Der Titel sagt alles. Lichter abschalten etc., wenn man aus dem Haus geht und die Haustür mit der Nuki-Rücktaste abschliesst.
<?php
// Enable error reporting for debugging
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Instance ID
$instanceID = 24242;
// Script ID to trigger
$scriptID = 33853;
echo "Starting script...\n";
// Get the HTML content from the instance
$htmlContent = GetValue($instanceID);
echo "HTML Content: " . htmlentities($htmlContent) . "\n";
// Convert HTML entities back to characters
$htmlContent = html_entity_decode($htmlContent, ENT_QUOTES, 'UTF-8');
// Create a new DOMDocument and load the HTML content
$dom = new DOMDocument;
@$dom->loadHTML('<?xml encoding="UTF-8">' . $htmlContent, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
echo "Loaded HTML into DOMDocument with UTF-8 encoding.\n";
// Find the table - assuming it's the first table in the HTML
$tables = $dom->getElementsByTagName('table');
if ($tables->length > 0) {
echo "Found a table.\n";
$firstTable = $tables->item(0);
// Assuming the first row is the header and the second row contains the data
$rows = $firstTable->getElementsByTagName('tr');
if ($rows->length > 1) {
echo "Found header and data rows.\n";
$dataRow = $rows->item(1); // Second row (index 1)
$cells = $dataRow->getElementsByTagName('td');
// Find the index of "Automatisch entriegeln" column
$headerRow = $rows->item(0);
$headers = $headerRow->getElementsByTagName('td');
$unlockColumnIndex = null;
foreach ($headers as $index => $header) {
if (trim($header->textContent) == "Automatisch entriegeln") {
$unlockColumnIndex = $index;
echo "Found 'Automatisch entriegeln' column at index: $unlockColumnIndex\n";
break;
}
}
if ($unlockColumnIndex !== null) {
// Check if the specific cell contains "Zurück-Taste"
$cellContent = trim($cells->item($unlockColumnIndex)->textContent);
echo "Content of the cell in 'Automatisch entriegeln' column: $cellContent\n";
if ($cellContent == "Zurück-Taste") {
// Trigger the script
IPS_RunScript($scriptID);
echo "Script with ID $scriptID triggered due to 'Zurück-Taste'.\n";
// Send an email notification
SMTP_SendMail(41006, "Lehnstrasse door locked with back key", "Lehnstrasse door locked with back key");
} else {
echo "The 'Automatisch entriegeln' column does not contain 'Zurück-Taste'. No action taken.\n";
// Send a different email notification
SMTP_SendMail(41006, "Lehnstrasse door", "The 'Automatisch entriegeln' column does not contain 'Zurück-Taste'. No action taken.");
}
} else {
echo "Column 'Automatisch entriegeln' not found.\n";
// Send an email notification for column not found
SMTP_SendMail(41006, "Lehnstrasse door", "Column 'Automatisch entriegeln' not found.");
}
} else {
echo "Data row not found in the table.\n";
// Send an email notification for data row not found
SMTP_SendMail(41006, "Lehnstrasse door", "Data row not found in the table.");
}
} else {
echo "No table found in the HTML content.\n";
// Send an email notification for no table found
SMTP_SendMail(41006, "Lehnstrasse door", "No table found in the HTML content.");
}
?>