Tutorial adding HUE Motion sensor (Lux,Temp and Motion)

Good shout! :+1:

I use the motion sensors in HA. I use the rest-component in HA to set it up.

I donā€™t know if this has been mentioned but the Hue API also exposes the presence as a sensor, appearing in mine as:

{
  "state": {
    "presence": true,
    "lastupdated": "2017-07-22T11:52:42"
  },
  "config": {
    "on": true,
    "reachable": true
  },
  "name": "Robins iPhone",
  "type": "Geofence",
  "modelid": "HA_GEOFENCE",
  "manufacturername": "Philips",
  "swversion": "A_1",
  "uniqueid": "L_02_IYwHM",
  "recycle": false
}

Thanks for sharing.
I personally donā€™t want Philips to know where I am so I donā€™t have an account linked and thus no presence detection.

Anyone have an issue with these virtual sensors disappearing upon a power cycle/loss with the HUE hub? Power went out a few days ago and I lost all of my virtual sensors. It was only two so it wasnā€™t a big deal to recreat, but stillā€¦

Is there a way to back up the configuration? Should it store these changes?

Thanks,

Yes that happens. Also when you change the sensitivity for instance through the Hue app I noticed I lost some rules and entries.
So what I did is keep a copy of what I entered in a document and once it happens I copy paste is quickly again.

Iā€™m using the motion sensors without using the ā€˜virtual sensorsā€™ and work great!

binary_sensor:
  - platform: rest 
    resource: http://<bridge ip address>/api/<username>/sensors/15 
    name: living_room_motion_sensor 
    value_template: '{{value_json.state.presence}}' 
    scan_interval: 1

Iā€™m having some problems setting this up.

I guess this is my motion sensor:

ā€œ5ā€:{ā€œstateā€:{ā€œstatusā€:0,ā€œlastupdatedā€:ā€œ2017-08-10T05:30:39ā€},ā€œconfigā€:{ā€œonā€:true,ā€œreachableā€:true},ā€œnameā€:ā€œMotionSensor 3.Companionā€,ā€œtypeā€:ā€œCLIPGenericStatusā€,ā€œmodelidā€:ā€œPHA_STATEā€,ā€œmanufacturernameā€:ā€œPhilipsā€,ā€œswversionā€:ā€œ1.0ā€,ā€œuniqueidā€:ā€œMotionSensor 3.Companionā€,ā€œrecycleā€:true},

And this is my config:

My sensor will show up in homeassistant but it doesnt report any state. It is just empty

Doesnā€™t look correct return from the API. See https://www.hackster.io/robin-cole/boil-my-kettle-when-i-get-out-of-bed-in-the-morning-10e7de

You are right, thank you for the link.

This is how the sensor should look like:

"3": {
	"state": {
		"presence": false,
		"lastupdated": "2017-04-15T19:32:23"
	},
	"config": {
		"on": true,
		"battery": 100,
		"reachable": true,
		"alert": "none",
		"ledindication": false,
		"usertest": false,
		"sensitivity": 2,
		"sensitivitymax": 2,
		"pending": []
	},
	"name": "Unten Sensor",
	"type": "ZLLPresence",
	"modelid": "SML001",
1 Like

Great tutorial. Have followed and worked out greatā€¦ twice. Seems if you change IP address the key needs to be reset. Am I right in saying that as I moved from one hardwired access point to another (with different IP) I just setup again after no motion sensor detection? Had no issues in doing so but just wanted to double check

Glad I did as I setup the lux and temp sensors now. :slight_smile: Pal I owe you a few internet pints

One thing iā€™ve noted with my dealings though is that instead of motion sensor detection ā€œTrueā€ is that it shows as ā€œ1ā€ or ā€œ0ā€ā€¦ which is no biggie but just wondering why it aint matching with ā€œtrueā€ or ā€œfalseā€

Always grateful for an internet pint :grin:
To avoid the changing IP I recommend setting a DHCP reservation on your router.
Iā€™ve also noticed that if you remove and then re-add a sensor in the Hue app, it is assigned a different index.
Re 1, 0, I havenā€™t encountered that, be interested to hear if you get to the bottom of it. Cheers

Is it possible to set the scan_interval to less than a sec (e.g. 500 ms) ?

I set scan_interval = 0.5 and appears to make no difference. I also removed scan_interval and that made no difference. Therefore I conclude that scan_interval is not required (it is not in https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/sensor/rest.py)

I took the steps above without any problems. However when I restarted HA I get this error

2017-08-13 15:37:52 ERROR (Thread-5) [homeassistant.components.sensor.rest] Error fetching data: <PreparedRequest [GET]>
2017-08-13 15:37:52 ERROR (Thread-5) [homeassistant.components.sensor.rest] Unable to fetch REST data

Does anyone know why Iā€™m getting that error?

Ip of the bridge hasnā€™t changed and Hue component is otherwise functioning without errors?

Yes the IP is still the same and the Hue component is functioning correctly.

Iā€™d check what is being returned by the rest call. Have noticed that adding new devices can change the ordering of sensors etc

EDIT: Now using Deconzā€¦ even better !

I moved my Hue Motion sensors from rest to MQTT using hue-mqtt-bridge and the delay is much better !

binary_sensor:
- platform: mqtt
device_class: motion
state_topic: hue/my_sensor/presence
name: ā€˜Sensor Motionā€™
payload_on: ā€œtrueā€
payload_off: ā€œfalseā€

4 Likes

I followed the tutorial to add the light sensor (not the others) in REST. My configuration file looks like this:

  • platform: rest
    resource: http://ā€œIP Adressā€/api/ā€œUserā€/sensors/6
    value_template: ā€˜{{ (10 ** (float(value_json.state.lightlevel) / 10000) -1) | round (1)}}ā€™

    unit_of_measurement: Lux
    name: ā€˜Living Room Luxā€™

It works fine and home assistant receives data. However when I try to use the lux in an automation, the automation does not trigger. My automations file looks like this:

  • action:
    • data:
      entity_id: light.iris
      service: light.turn_on
      alias: Turn on Iris
      condition:
    • condition: state
      entity_id: light.iris
      state: ā€˜offā€™
      id:
      trigger:
    • below: ā€˜200ā€™
      entity_id: sensor.living_room_lux
      platform: numeric_state

If I change the automation to start at for instance 20:00 it works fine, so it is only the trigger that is failling.

Any ideas?