I’m trying to make an automation which turns on (or adjusts) my office lights with a brightness based on the detected luminance. My automation is written as follows:
- alias: "Turn on lights when dark while working"
trigger:
- platform: state
entity_id: sensor.office_multi_luminance_3
- platform: numeric_state
entity_id: sensor.laptop_work_david
above: 500
condition:
condition: and
conditions:
- condition: state
entity_id: switch.turn_on_lights_when_dark_while_working
state: 'on'
- condition: numeric_state
entity_id: sensor.office_multi_luminance_3
below: 30
- condition: numeric_state
entity_id: sensor.laptop_work_david
above: 500
action:
- service: script.turn_on
entity_id: script.office_worklight
data_template:
variables: >-
{%- set lux = states.sensor.office_multi_luminance_3.state | int -%}
{%- set perc = 60 - lux -%}
{%- set bri = ((255 * perc) / 100) | int -%}
brightness: {{ bri }}
And the script being called looks like this:
office_worklight:
sequence:
- service: light.turn_on
data:
entity_id:
- light.lamp_desk_left
- light.lamp_desk_right
rgb_color: [211, 191, 157]
transition: 5
data_template:
brightness: '{{ brightness }}'
The script works perfectly. I’ve tested it manually through the HASS frontend, on the Services page, by calling it with the following data: { "brightness": "86" }
However, the automation keeps returning the following error:
16-09-06 13:28:53 homeassistant.core: Invalid service data for script.turn_on: expected dict for dictionary value @ data['variables']. Got 'brightness: 86'
I tried to rewrite the data_template
section a few different ways, but my variable seems to get parsed as a string no matter what I try. I fear I may have stumbled onto another (showstopping, for me) bug but I thought I’d check here first. There is very little information to be found anywhere when it comes to passing variables to scripts, especially when trying to template the variables.