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

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:.

I broke out my hue_sensors functionality into a separate .py file, could be useful for debugging.
Hopefully I get the component published soon.

Can anyone assist getting the temperature working, I keep getting the following error in the log and its the only sensor not currently working.

When I do a GET with the following command “http://IP.ADDRESS.HERE/api/API-KEY-HERE/sensors/13” in the API debug tool I get the following output

{
“state”: {
“temperature”: 2365,
“lastupdated”: “2017-10-08T15:55:16”
},
“swupdate”: {
“state”: “noupdates”,
“lastinstall”: null
},
“config”: {
“on”: true,
“battery”: 100,
“reachable”: true,
“alert”: “none”,
“ledindication”: false,
“usertest”: false,
“pending”:
},
“name”: “Hue temperature sensor 1”,
“type”: “ZLLTemperature”,
“modelid”: “SML001”,
“manufacturername”: “Philips”,
“swversion”: “6.1.0.18912”,
“uniqueid”: “blah-blah-blah-02-0402”
}

Below is my sensor config

- platform: rest
  resource: !secret temp_sensor_api
  value_template: '{{ value_json.state.temperature | round(-1) | float / 100 }}'
  unit_of_measurement: °C
  scan_interval: 10
  name: 'Room Temperature'

Error in Hassio log

Error parsing value: ‘list object’ has no attribute ‘state’ (value: [{“error”:{“type”:4,“address”:“/13”,“description”:“method, GET, not available for resource, /13”}}], template: {{ value_json.state.temperature | round(-1) | float / 100 }})

Try without the rounding:
value_template: ‘{{ value_json.state.temperature | float / 100 }}’

Can I safely try this next to what I currently have?
I don’t want to be in an irreversible situation (apart from restoring a backup image).

Thanks for the quick response.

I just realised having read my own post and then checking my config, that I had a typo in my secrets.yaml file!!!

What a doughnut!! :frowning:

1 Like