Kane610/deconz

Feature Request: Expose the config.on attribute of a sensor to Home Assistant

Closed this issue · 10 comments

Possible implementations:

  • As an attribute of a sensor
  • As a switch:
    Map config.on true to state 'on' and config.on false to state 'off'
    turn_on service to PUT /sensors/#/config {"on": true}
    turn_off service to PUT /sensors/#/config {"on": false}

Use case: I'm using the rule engine of deCONZ and sometimes I disable a motion sensor the prevent triggering all rules related to the sensor.
I would prefer the second implementation.

It is already supported by the sensor so I will add it as an attribute. Will look into this next week. No need to rush since the new beta period has already started. There would just be too many entities created if a switch would be generated for each sensor.

For turning on and off there already is a service for that. It's generic but you can just specify entity and send that payload.

PR is submitted to HASS, you can expect it to show up with release 0.74

Did some testing for this one also. Initial on attribute state works. Changes are not reported.
I think it is related to the on attribute missing here? https://github.com/Kane610/home-assistant/blob/c5d89ece993d02bc888e99bdbbf089d233b4c300/homeassistant/components/binary_sensor/deconz.py#L63

Here is the log after triggering the change of config.on using the deconz.configure service:

2018-07-02 21:23:11 DEBUG (MainThread) [pydeconz.utils] Sending {'data': '{"on": false}'} to http://192.x.x.x:80/api/<redacted-api-key>/sensors/62/config
2018-07-02 21:23:11 DEBUG (MainThread) [pydeconz.utils] HTTP request response: [{'success': {'/sensors/62/config/on': False}}]
2018-07-02 21:23:11 DEBUG (MainThread) [pydeconz.deconzdevice] Motion Sensor: update alert with none
2018-07-02 21:23:11 DEBUG (MainThread) [pydeconz.deconzdevice] Motion Sensor: update battery with 100
2018-07-02 21:23:11 DEBUG (MainThread) [pydeconz.deconzdevice] Motion Sensor: update delay with 0
2018-07-02 21:23:11 DEBUG (MainThread) [pydeconz.deconzdevice] Motion Sensor: update ledindication with False
2018-07-02 21:23:11 DEBUG (MainThread) [pydeconz.deconzdevice] Motion Sensor: update on with False
2018-07-02 21:23:11 DEBUG (MainThread) [pydeconz.deconzdevice] Motion Sensor: update reachable with True
2018-07-02 21:23:11 DEBUG (MainThread) [pydeconz.deconzdevice] Motion Sensor: update sensitivity with 2
2018-07-02 21:23:11 DEBUG (MainThread) [pydeconz.deconzdevice] Motion Sensor: update sensitivitymax with 2
2018-07-02 21:23:11 DEBUG (MainThread) [pydeconz.deconzdevice] Motion Sensor: update usertest with False
2018-07-02 21:23:11 DEBUG (MainThread) [pydeconz.websocket] Websocket data: {"config":{"alert":"none","battery":100,"delay":0,"ledindication":false,"on":false,"reachable":true,"sensitivity":2,"sensitivitymax":2,"usertest":false},"e":"changed","id":"62","r":"sensors","t":"event"}

Call is succesful. Websocket shows the new state of the config attribute (false). However, there is no update of the attribute in the Home Assistant entity

Thanks for testing it so rigorously! I apologise for all these misses

Pushed an update, try it out now

Thanks. I can confirm that all changes work as expected now.

Just for your information, I'm using this template switch to view and toggle the config.on state of a motion sensor:

switch:
  - platform: template
    switches:
      motion_kitchen:
        value_template: "{{ states.binary_sensor.motion_kitchen.attributes.on }}"
        turn_on:
          service: deconz.configure
          data:
            field: /sensors/62/config
            data:
              "on": true
        turn_off:
          service: deconz.configure
          data:
            field: /sensors/62/config
            data:
              "on": false

Great! PR is approved so it is ready to be merged, perfect timing. Thanks for your support!

I might put this in as an example on how to use the "on" attribute. Nice idea!

It is now available on HASS dev branch