I’m working on an automation to handle a four-button Hue remote (RWL020) triggering on/off and brightness control of some dimmable lights, similar to how it can be made to work with the Hue bridge. I’m using a Nortek Zigbee+Z-Wave dongle and direct ZHA integration, so there’s no Hue bridge involved. I’ve actually got it working with two separate automations, but it seems like I should be able to do it with just one.
Here’s what works with two automations, one to handle the ON+BRIGHTNESS update and another to handle the OFF update:
- id: '1551928271993'
alias: Office Light Remote On
trigger:
- entity_id: binary_sensor.office_light_remote
platform: state
condition:
- condition: state
entity_id: binary_sensor.office_light_remote
state: 'on'
action:
- data_template:
brightness: '{{ state_attr("binary_sensor.office_light_remote", "level") }}'
entity_id: light.office_desk_lamp
service: light.turn_on
- id: '1551934815541'
alias: Office Light Remote Off
trigger:
- entity_id: binary_sensor.office_light_remote
platform: state
condition:
- condition: state
entity_id: binary_sensor.office_light_remote
state: 'off'
action:
- entity_id: light.office_desk_lamp
service: light.turn_off
I tried combining them and putting the brightness
update in a conditional block like this, so that brightness is only set if the switch is on:
- id: '1551928271572'
alias: Office Light Remote Handler
trigger:
- entity_id: binary_sensor.office_light_remote
platform: state
condition:
action:
- entity_id: light.office_desk_lamp
data_template: >
{% if is_state("binary_sensor.office_light_remote", "on") %}
brightness: '{{ state_attr("binary_sensor.office_light_remote", "level") }}'
{% endif %}
service_template: >
{% if is_state("binary_sensor.office_light_remote", "on") %}
light.turn_on
{% else %}
light.turn_off
{% endif %}
The idea is that brightness should NOT be passed in the data if the light is turning off, since the light.turn_off
service doesn’t accept it as an argument. (I found this out the hard way when my initial attempt at integrating brightness worked to turn the light on, but not off, because the off service was failing due to the invalid argument.)
However, with the above combined format, the config validation fails with this error:
Invalid config for [automation]: expected a dictionary for dictionary value @ data[‘action’][0][‘data_template’]. Got None. (See /home/homeassistant/.homeassistant/configuration.yaml, line 35). Please check the docs at Automation - Home Assistant
I’ve looked through the docs as well as other topics, but I haven’t been able to figure out just why this doesn’t work, or if there is a way to fix it without resorting to two separate automations (which just feels like a kludge to me). Is this an impossible goal?