Als Arzt kann ich nur sagen, dass es am besten wäre, wenn man Statine ins Trinkwasser geben würde (ist nicht ganz ernst gemeint) denn ich vergesse gelegentlich mein Statin einzunehmen. Also habe ich ein Zigbee-Vibrationssensor auf der Box geklebt, und hier ist ein Skript welches mich man mahnt, falls ich das vergessen habe. Der Skript funktioniert auch mit anderen Medikamente, jedoch nicht mit homeopathischen Mitteln
<?php
/**
* Pill Reminder Script
*
* This script is designed to help ensure that a statin pill is taken daily. It relies on a vibration sensor
* (attached to the pill bottle) to detect activity. If the sensor does not detect any vibration by a specified
* threshold time (6:30 AM), the script will send a reminder email. The script should be scheduled to run
* at a specific time (e.g., 5 PM) to perform this check.
*
* How it works:
* 1. The script retrieves the last update timestamp of the vibration sensor.
* 2. Compares this timestamp to the threshold time for the day (6:30 AM).
* 3. If no vibration is detected after the threshold, a reminder email is sent.
* 4. If the 5 PM trigger does not exist, the script creates it automatically.
* 5. All activities are logged for debugging and monitoring purposes.
*
* Configuration:
* - Update the variable IDs and email details below to match your IP-Symcon setup.
*/
// Configuration
$vibrationSensorID = 55487; // ID of the vibration sensor
$sendmailInstanceID = 41006; // ID of the sendmail instance
$emailAddress = "empfaenger@mail.edu"; // Recipient email address
$eventName = "PillReminderTrigger"; // Name of the scheduled event
$checkTime = strtotime("17:00"); // 5:00 PM
// Debugging output to log script start
IPS_LogMessage("Pill Reminder Script", "Script execution started.");
// Check if a scheduled event exists, and create one if not
$scriptID = $_IPS['SELF']; // Current script ID
$eventID = @IPS_GetObjectIDByName($eventName, $scriptID);
if ($eventID === false) {
// Event does not exist, create it
$eventID = IPS_CreateEvent(1); // 1 = Cyclic Event
IPS_SetParent($eventID, $scriptID);
IPS_SetName($eventID, $eventName);
IPS_SetEventCyclicTimeFrom($eventID, date("H", $checkTime), date("i", $checkTime), 0);
IPS_SetEventCyclic($eventID, 0, 0, 0, 0, 1, 0); // Daily trigger at a specific time
IPS_SetEventActive($eventID, true);
IPS_LogMessage("Pill Reminder Script", "Scheduled event created for 5 PM.");
} else {
IPS_LogMessage("Pill Reminder Script", "Scheduled event already exists.");
}
// Get the last update time of the vibration sensor
$lastUpdate = IPS_GetVariable($vibrationSensorID)['VariableUpdated'];
IPS_LogMessage("Pill Reminder Script", "Last vibration update time: " . date("Y-m-d H:i:s", $lastUpdate));
// Define the threshold time (6:30 AM today)
$threshold = strtotime("06:30");
IPS_LogMessage("Pill Reminder Script", "Threshold time for vibration: " . date("Y-m-d H:i:s", $threshold));
// Check if the vibration sensor has not been updated since 6:30 AM
if ($lastUpdate < $threshold) {
IPS_LogMessage("Pill Reminder Script", "No vibration detected since threshold. Preparing to send reminder email.");
// Email content
$subject = "Pill Reminder: Statin not taken yet";
$message = "Hello Adriano,\n\n" .
"This is a reminder that you have not taken your statin pill today. " .
"Please make sure to take it as soon as possible.\n\n" .
"Best regards,\nYour IP-Symcon System";
// Debugging output for email details
IPS_LogMessage("Pill Reminder Script", "Sending email to: $emailAddress with subject: $subject");
// Send email using the sendmail instance
$emailSent = SMTP_SendMailEx($sendmailInstanceID, $emailAddress, $subject, $message);
// Check if email was sent successfully
if ($emailSent) {
IPS_LogMessage("Pill Reminder Script", "Reminder email successfully sent to $emailAddress.");
echo "Reminder email sent to $emailAddress.";
} else {
IPS_LogMessage("Pill Reminder Script", "Failed to send reminder email.");
echo "Failed to send reminder email.";
}
} else {
IPS_LogMessage("Pill Reminder Script", "Pill has already been taken today.");
echo "Pill has already been taken today.";
}
// Debugging output to log script end
IPS_LogMessage("Pill Reminder Script", "Script execution completed.");
?>