Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@oiskenny 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