Philips HUE Motion Sensor

Others (MiLight, Hue, Toon etc...)

Moderator: leecollings

Eisenhauer
Posts: 6
Joined: Monday 17 October 2016 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Philips HUE Motion Sensor

Post 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.
Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Philips HUE Motion Sensor

Post by Derik »

perhaps sent a mail to: [email protected]
Ask... Gizmocuz
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
Eisenhauer
Posts: 6
Joined: Monday 17 October 2016 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Philips HUE Motion Sensor

Post 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
lbouriez
Posts: 4
Joined: Thursday 20 November 2014 22:16
Target OS: Linux
Domoticz version:
Contact:

Re: Philips HUE Motion Sensor

Post by lbouriez »

There is no way to see the sensor in the device list to be able to use it with the blocky events ?
Sneezydevil
Posts: 111
Joined: Monday 18 January 2016 9:56
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Philips HUE Motion Sensor

Post 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.
Eisenhauer
Posts: 6
Joined: Monday 17 October 2016 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Philips HUE Motion Sensor

Post 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.
robhuls
Posts: 29
Joined: Monday 23 March 2015 19:20
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Zwolle
Contact:

Re: Philips HUE Motion Sensor

Post 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.
PeetX
Posts: 1
Joined: Saturday 21 January 2017 19:35
Target OS: -
Domoticz version:
Contact:

Re: Philips HUE Motion Sensor

Post 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.
SSiRR
Posts: 1
Joined: Sunday 29 January 2017 16:48
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Philips HUE Motion Sensor

Post 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,
Dropshot
Posts: 44
Joined: Tuesday 20 December 2016 22:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Philips HUE Motion Sensor

Post 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
Last edited by Dropshot on Friday 10 March 2017 16:08, edited 2 times in total.
Jordy
Posts: 11
Joined: Tuesday 21 February 2017 10:00
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: NL
Contact:

Re: Philips HUE Motion Sensor

Post 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
domoticz_sensor.jpg (83.98 KiB) Viewed 10641 times
gingercat
Posts: 4
Joined: Friday 21 October 2016 18:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Philips HUE Motion Sensor

Post 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.
Jordy
Posts: 11
Joined: Tuesday 21 February 2017 10:00
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: NL
Contact:

Re: Philips HUE Motion Sensor

Post by Jordy »

The latest Domoticz beta supports my Philips hue motion sensor extension (V3.6775). Try it out :)
jjnj

Re: RE: Re: Philips HUE Motion Sensor

Post 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?
Jordy
Posts: 11
Joined: Tuesday 21 February 2017 10:00
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: NL
Contact:

Re: Philips HUE Motion Sensor

Post by Jordy »

I have only added the motion (presence) part. But I plan on looking into the others as well: lightlevel and also temperature
Jordy
Posts: 11
Joined: Tuesday 21 February 2017 10:00
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: NL
Contact:

Re: Philips HUE Motion Sensor

Post 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.
User avatar
constapel
Posts: 15
Joined: Friday 30 December 2016 21:43
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Philips HUE Motion Sensor

Post by constapel »

Working Great. Thanks very much for implementation. Now the time consuming Lua sript can be removed.
Thanks!
User avatar
constapel
Posts: 15
Joined: Friday 30 December 2016 21:43
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Philips HUE Motion Sensor

Post 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
Knipsel.PNG (21.5 KiB) Viewed 10404 times
Jordy
Posts: 11
Joined: Tuesday 21 February 2017 10:00
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: NL
Contact:

Re: Philips HUE Motion Sensor

Post 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"
},
User avatar
constapel
Posts: 15
Joined: Friday 30 December 2016 21:43
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Philips HUE Motion Sensor

Post 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!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest