Page 1 of 2
Philips HUE Motion Sensor
Posted: Monday 17 October 2016 14:30
by Eisenhauer
Hi,
i have the new Philips HUE Motion Sensor. With the native Philips app it works fine, but the sensor is not shown under devices in Domoticz.
I created two scipts to read the temperature and ambient light values with the HUE API and put them to a virtual sensor. Thats works fine and is no time critical. I can read the Motion detection state in this way, too. But for a real working solution is this to slow and takes to much CPU time from the PI. There should be an solution to use the native way from Philips.
Is there a implementation on the new HUE Hardware planned? I can help with API outputs an so on.
Re: Philips HUE Motion Sensor
Posted: Monday 17 October 2016 15:18
by Derik
perhaps sent a mail to:
[email protected]
Ask... Gizmocuz
Re: Philips HUE Motion Sensor
Posted: Monday 17 October 2016 17:33
by Eisenhauer
I Wirte the mail. Maybe he have a solution. For now the Temperature Script.
Code: Select all
--Hue Bridge
local hueBridgeIP = 'Enter IP'
local hueBridgeAPI = 'Enter API'
i = SensorNumber from Temp Sensor
function getHueLight(id)
local http = require('socket.http')
local ltn12 = require('ltn12')
local json = require('dkjson')
t = {}
local url = string.format("http://%s/api/%s/sensors/%s", hueBridgeIP, hueBridgeAPI, id)
b, c, h = http.request{url=url, sink = ltn12.sink.table(t), method='GET'}
huestring = tostring(table.concat(t))
local hue, pos, err = json.decode(huestring, 1, nil)
if (hue.name) then
hue_name = (hue.name)
hue_temp = (hue.state.temperature)
hue_temp = hue_temp /100
else
stop = true
end
return hue_name, hue_temp, stop
end
commandArray = {}
--Sensor nummer
local hue = getHueLight(i)
--First Number, idx number virtual device
commandArray['UpdateDevice'] = '159|0|'..tostring(hue_temp)
return commandArray
Re: Philips HUE Motion Sensor
Posted: Friday 28 October 2016 4:37
by lbouriez
There is no way to see the sensor in the device list to be able to use it with the blocky events ?
Re: Philips HUE Motion Sensor
Posted: Friday 28 October 2016 7:59
by Sneezydevil
At the moment you could add a dummy switch and update that with the script. There is no support yet for the motion sensor in Domoticz itself.
Re: Philips HUE Motion Sensor
Posted: Friday 28 October 2016 20:05
by Eisenhauer
Yes, there is no native support for now. I hope it will be change.
A Script solution for using the motion sensor is to slow in reaction. The motion sensor with hue bridge have a reaction time of 500ms.
Re: Philips HUE Motion Sensor
Posted: Wednesday 04 January 2017 16:26
by robhuls
As far as I can see there is no native support yet. I switch a light with the motion sensor and defined that in the Hue app. If I want to do more, I can write a lua script in Domoticz that is triggered when that light goes on/off (e.g. turn on/off the TV). The response should be nearly instant if the switching of the light in Domoticz does not rely on a polling mechanism.
Re: Philips HUE Motion Sensor
Posted: Sunday 22 January 2017 20:46
by PeetX
Hi,
I try to run the script above, but with no succes. I get te following errors:
[string "--Hue Bridge..."]:7: module 'socket.http' not found:
no field package.preload['socket.http']
no file '/usr/local/share/lua/5.2/socket/http.lua'
no file '/usr/local/share/lua/5.2/socket/http/init.lua'
no file '/usr/local/lib/lua/5.2/socket/http.lua'
no file '/usr/local/lib/lua/5.2/socket/http/init.lua'
no file './socket/http.lua'
no file '/usr/local/lib/lua/5.2/socket/http.so'
no file '/usr/local/lib/lua/5.2/loadall.so'
no file './socket/http.so'
no file '/usr/local/lib/lua/5.2/socket.so'
no file '/usr/local/lib/lua/5.2/loadall.so'
no file './socket.so'
--------
after:
luarocks install luasocket
got the error:
error loading module 'socket.core' from file '/usr/local/lib/lua/5.2/socket/core.so':
dynamic libraries not enabled; check your Lua installation
LuaSockets seems not to be installed correctly.
Can somebody help me to point out how to install luasockets on macOS.
Re: Philips HUE Motion Sensor
Posted: Sunday 29 January 2017 17:23
by SSiRR
Hi there,
I've got myself a hue sensor too, would be great to get it to work without slow scripting. If there is anything i can do to help testing just let me know. I will put some time in ASAP to see how the scripting part is done.
kind regards,
Re: Philips HUE Motion Sensor
Posted: Sunday 19 February 2017 15:42
by Dropshot
If you have a Hue Motion Sensor, you can use this LUA script to update a virtual temperature and lux sensor every 5 min. It's not useful to update these sensors more frequently, since the Hue Motion Sensor refreshes its temp and lux data only every 5 minutes.
There is no virtual motion detection sensor in this script, since time-based scripts are triggered only every minute, and thereby not useful for motion detection (although I can add this to the script if you have any use-case for it).
So, if someone does know a way to use the motion sensor to trigger events in domoticz, please post your solution here!
Code: Select all
--
-- A: create a virtual temperature sensor (Hardware - Dummy - Create virtual sensors)
-- B: create a virtual lux sensor
-- C: If you haven't already, install the socket library: http://www.domoticz.com/wiki/Upload_energy_data_to_PVoutput#Install_socket_library
-- D: Change the variables in the code and trigger the script time-based
--
-- variables to customiz below --
local idTempSen = "xx" -- ID of 'Temperature Sensor'- get it at: http://<<yourHueBridgeIP>>/debug/clip.html, fill in: url: http://<<yourHueBridgeIP>>/api/<<your UserName>>/sensors/ and hit GET
local idLuxSen = "xx" -- ID of 'Ambient Light Sensor' - get it at: http://<<yourHueBridgeIP>>/debug/clip.html, fill in: url: http://<<yourHueBridgeIP>>/api/<<your UserName>>/sensors/ and hit GET
local idxTempSen = "xx" -- idx of dummy Hue temperature sensor (search for the sensor in 'Devices')
local idxLuxSen = "xx" -- idx of dummy Hue lux sensor
local localhost = 'xxx.xxx.xxx.xxx:8080' -- IP Address of domoticz
local hueBridgeIP = "xxx.xxx.xxx.xxx" -- IP Address of your Hue Bridge
local hueAPIID = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -- your Bridge User Name
-- variabes to customize above --
function getDeviceInfo(ID1, ID2) -- function to gather temperature and lux data
local http = require('socket.http')
local base_url = 'http://'..hueBridgeIP..'/api/'..hueAPIID..'/'
local deviceTemp = 'sensors/'..ID1..'/'
local deviceLux = 'sensors/'..ID2..'/'
local urlTemp = base_url..deviceTemp
local urlLux = base_url..deviceLux
local tempData = getHueData(urlTemp)
local temperature = tempData.state.temperature
local luxData = getHueData(urlLux)
local lux = luxData.state.lightlevel
return temperature, lux
end
function getHueData(url) -- function to get current data from Hue Motion Sensor
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()
local config = assert(io.popen('curl '..url))
local hueSensor = config:read('*all')
config:close()
local jsonHueSensor = json:decode(hueSensor)
return jsonHueSensor
end
function updateSensor(idx,data) -- function to update dummy sensors
commandArray[#commandArray + 1]={['UpdateDevice'] = idx .. '|0|' .. tostring(data)}
end
commandArray = {} -- actual script that is triggered every minute (time based)
time = os.date("*t")
if ((time.min % 5)==0) then -- only update sensors every 5 min
local temperature, lux = getDeviceInfo(idTempSen, idLuxSen)
temperature = temperature/100
updateSensor(idxTempSen,temperature)
updateSensor(idxLuxSen,lux)
end
return commandArray
Re: Philips HUE Motion Sensor
Posted: Tuesday 21 February 2017 10:23
by Jordy
I've been working on getting motion sensor support in Domoticz. It seems to be working, but it's still work in progress. You can check out my github fork @
https://github.com/JordyGitHub/domoticz ... ue_Sensors.
I've tested the windows build:

- domoticz_sensor.jpg (83.98 KiB) Viewed 10650 times
Re: Philips HUE Motion Sensor
Posted: Wednesday 22 February 2017 21:47
by gingercat
Cool - will have to give this a go at some point. Really want to be able to have more control over what happens when motion is detected/times out. The Phillips app doesn't let you do much.
Re: Philips HUE Motion Sensor
Posted: Thursday 23 February 2017 19:07
by Jordy
The latest Domoticz
beta supports my Philips hue motion sensor extension (V3.6775). Try it out

Re: RE: Re: Philips HUE Motion Sensor
Posted: Thursday 23 February 2017 20:26
by jjnj
Jordy wrote:The latest Domoticz
beta supports my Philips hue motion sensor extension (V3.6775). Try it out

Wow great news! Is also the light reading supported?
Re: Philips HUE Motion Sensor
Posted: Thursday 23 February 2017 22:51
by Jordy
I have only added the motion (presence) part. But I plan on looking into the others as well: lightlevel and also temperature
Re: Philips HUE Motion Sensor
Posted: Friday 24 February 2017 19:15
by Jordy
I've updated my implementation (request pending @ domoticz github)
The Philips Hue motion sensor contains 3 sensors: presence, temperature and lightlevel. My previous implemention was for the presence sensor.
My latest addition is for the temperature sensor and light level (displayed as dusk switch).
Also Battery is correctly logged/displayed.
Re: Philips HUE Motion Sensor
Posted: Sunday 26 February 2017 0:51
by constapel
Working Great. Thanks very much for implementation. Now the time consuming Lua sript can be removed.
Thanks!
Re: Philips HUE Motion Sensor
Posted: Sunday 26 February 2017 8:26
by constapel
The HUE Senor can also detect LuX. Are you going to implement that aswell?
Hue Lux Sensor Showing how much light. Via Lua Script and Virtual LUX sensor

- Knipsel.PNG (21.5 KiB) Viewed 10413 times
Re: Philips HUE Motion Sensor
Posted: Sunday 26 February 2017 13:05
by Jordy
I've implemented it as a dusk sensor. You can set the threshold via the Philips Hue application and then the sensor state will indicate if it's Dark or Daylight.
Since it can't be both dark and daylight at the same time, I've let the dusk sensor check on the Dark state.
Would you like to have an additional sensor for the Lux (which will use the lightlevel value)?
Example of the lightlevel sensor state:
"state": {
"lightlevel": 14716,
"dark": true,
"daylight": false,
"lastupdated": "2017-02-25T13:50:45"
},
Re: Philips HUE Motion Sensor
Posted: Sunday 26 February 2017 13:33
by constapel
That would be very nice. If we have a Lux device we can make our own threshold actions via domoticz.
This would make the Philips Hue Sensor an excelent device for domoticz.
I think a will buy some more, because the possibilities will be endless ( not needing the the philips hue app for scene selections).
Thank you very much for the good work!