Skip to content

Instantly share code, notes, and snippets.

@renepenner
Last active August 23, 2021 10:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renepenner/3c673e87efc75e54c52b82b01b98de28 to your computer and use it in GitHub Desktop.
Save renepenner/3c673e87efc75e54c52b82b01b98de28 to your computer and use it in GitHub Desktop.
HUE Motion Sensor Script
<?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);
}
@oiskenny
Copy link

oiskenny commented Jul 9, 2017

sieht toll aus, danke
wie wird der script ausgeführt? mit cron jede 500ms, oder gibts eine bessere Lösung?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment