Last active
August 23, 2021 10:50
-
-
Save renepenner/3c673e87efc75e54c52b82b01b98de28 to your computer and use it in GitHub Desktop.
HUE Motion Sensor Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$hue_bridge = "http://192.168.178.100"; | |
$hue_secret = "?????????????"; | |
$loxone_address = 'miniserver-ip:34435'; | |
$config = [ | |
'ZLLTemperature' => [ | |
'key' => 'temperature' | |
], | |
'ZLLPresence' => [ | |
'key' => 'presence' | |
], | |
'ZLLLightLevel' => [ | |
'key' => 'lightlevel' | |
] | |
]; | |
while(1){ | |
$json_value = file_get_contents( $hue_bridge . '/api/'.$hue_secret.'/sensors'); | |
$data = json_decode($json_value, true); | |
foreach($data as $sensor){ | |
$sensorType = $sensor['type']; | |
if(in_array($sensorType, array_keys($config))){ | |
$key = $config[$sensor['type']]['key']; | |
$value = $sensor['state'][$key]; | |
if(is_bool($value)){ | |
$value = $value ? 1 : 0 ; | |
} | |
echo $msg = $key . ':' . $value; | |
echo PHP_EOL; | |
$socket = fsockopen('udp://'.$loxone_address); | |
fwrite($socket, $msg); | |
} | |
} | |
flush(); | |
sleep(2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sieht toll aus, danke
wie wird der script ausgeführt? mit cron jede 500ms, oder gibts eine bessere Lösung?