@popboxgun wrote:
I am having an issue where the script works fine for one automation, but fails on another with:
expected float for dictionary value @ data['brightness_pct']
I tried adding float to the below lights_on_brightness script, which just turned the lights to 0 pct, but I don’t know why it would work fine for one but fail for another when I’m passing the same values in the data_template.
Here’s the lights script
lights_on_brightness: alias: Lights on brightness script sequence: - service: light.turn_on data_template: entity_id: "{{ entity_id }}" brightness_pct: > {% if brightness_pct is defined %} {{ brightness_pct }} {% else %} 100 {% endif %} transition: > {% if transition is defined %} {{ transition }} {% else %} 3 {% endif %}
Here’s a working automation using it.
- alias: Extra Button Light initial_state: on trigger: - platform: event event_data: command: button_single device_ieee: '28:6d:97:00:01:05:b6:2c' event_type: zha_event - platform: event event_data: command: button_double device_ieee: '28:6d:97:00:01:05:b6:2c' event_type: zha_event - platform: event event_data: command: button_hold device_ieee: '28:6d:97:00:01:05:b6:2c' event_type: zha_event action: data_template: entity_id: light.extra_light brightness_pct: >- {% if (trigger.event.data.command) == "button_single" %} 70 {% elif (trigger.event.data.command) == "button_double" %} 10 {% endif %} service_template: >- {% if (trigger.event.data.command) == "button_single" %} script.lights_on_brightness {% elif (trigger.event.data.command) == "button_double" %} script.lights_on_brightness {% else %} script.lights_off {% endif %}
But here’s the automation I’m getting the error on and need help with
alias: Plex Media Lights initial_state: on trigger: - platform: state entity_id: media_player.roku_ultra_2 - platform: state entity_id: media_player.roku_ultra_3 action: - service: script.lights_on_brightness data_template: entity_id: group.house_lights transition: 3 brightness_pct: >- {% if trigger.state == "playing" %} 10 {% elif trigger.state == "paused" %} 30 {% elif trigger.state == "idle" and trigger.entity_id != "media_player.roku_ultra_3" %} 50 {% endif %}
Posts: 1
Participants: 1