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

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?

Try without the ’
So: below: 200
Also I have this for the lux, don’t know why you have all that floating and rounding.

- platform: rest
  resource: http://blablabla/sensors/11
  value_template: '{{ value_json.state.lightlevel }}'
  unit_of_measurement: Lux
  name: 'Living room'

Oh and when you post code, put on the line before you start the post ```
and also on the line below your code.
Then it’s easier to read.

Thanks for your reply:

The ‘200’ is done via the automation ui, but if I remove the ’ and just write 200 directly in the automations file and reload it then it unfortunately also doesn’t fire.

Original:

- action:
  - data:
      entity_id: light.iris
    service: light.turn_on
  alias: Turn on Iris
  condition:
  - condition: state
    entity_id: light.iris
    state: 'off'
  id: '<id replaced>'
  trigger:
  - below: '200'
    entity_id: sensor.living_room_lux
    platform: numeric_state

New

- action:
  - data:
      entity_id: light.iris
    service: light.turn_on
  alias: Turn on Iris
  condition:
  - condition: state
    entity_id: light.iris
    state: 'off'
  id: '<id replaced>'
  trigger:
  - below: 200
    entity_id: sensor.living_room_lux
    platform: numeric_state

Thanks for the tip regarding ```

I don’t know if the alignment is like that in your yaml file but it doesn’t look good.
Or does the automation ui fix the indent?
Can you align id: right under state?
And did you change the rest sensor thing like mine?

By the way it will only trigger when it goes from above 200 to below 200. Are you sure that’s happening when you want to test the automation?
Just put a light in front of it to it’s above 200 and then make it dark so it goes below.
You can see in the status list what the sensor’s actual status is.

The alignment is done completely by the ui.

You are spot on in regards to the lux has to be over 200 and then under 200 before home assistant switches the light on. Today it worked fine as daylight has been above 200 lux :slight_smile:

Is there any way that the automation will fire even if the lux is never above 200 - just for my understanding.

Maybe when Hass starts (after a restart) but otherwise no, only when it drops below 200, coming from above 200.
What is the reason you are asking?

Okay, it was primarily because I considered making an automation which would trigger the lights as 8:00 in the morning if the lux was below 200, but I have to test out if that works then, because during that time at winter the lux would always be below 200 when I would like it to trigger.

Also it is a difference to what I am used to in Domoticz where it always responds if the lux is under 200, but if the triggers work anyway it doesn’t really matter :slight_smile:

For the light level value, the template should be {{ float(10**((sensor.lightlevel-1)/10000)) | round(2) }} because according to Hue API: “Light level in 10000 log10 (lux) +1 measured by sensor”. (https://www.developers.meethue.com/documentation/supported-sensors)

1 Like

Interesting but still I didn’t set it up like that and it’s working fine :slight_smile:.