Im trying to create script that I can reuse in different automations.
I want to use Fields to provide variables to script and have managed to do functioning conditions for IFs.
I have field where calling automation would provide one or more lights that would be turned off or to some specific brightness based on script logic.
Light.turn_on service how ever gives me following error:
You defined a dictionary with a single item consisting of a key named entity_id with an associated value of light.wiz_rgbww_tunable_e8c724. A dictionary is not what the script’s light.turn_on service call expects. It expects to receive a list so that’s why you got an error message.
By wrapping condition_light in quotes, you converted it from the being the name of a variable to a string. So whatever value was passed by condition_light was never received by the Template Condition.
Script
alias: Lights Control With 2 Off States
sequence:
- if:
- condition: or
conditions:
- condition: template
value_template: "{{ is_state(condition_light, 'off') }}"
- condition: template
value_template: >
{{ state_attr('light.keittio_katto_ikkuna_light', 'brightness') < 80 }}
then:
- service: light.turn_on
data:
kelvin: 3800
brightness_pct: 75
target:
entity_id: "{{ lights_to_control }}"
else:
- if:
- condition: template
value_template: "{{ is_state(off_state_condition, 'on') }}"
then:
- service: light.turn_on
data:
kelvin: 3800
brightness_pct: 25
target:
entity_id: "{{ lights_to_control }}"
else:
- service: light.turn_off
data: {}
target:
entity_id: "{{ lights_to_control }}"
fields:
condition_light:
selector:
target:
entity:
domain: light
name: Condition Light
description: Light thats state/brightness is used as condition
required: true
lights_to_control:
selector:
target:
entity:
domain: light
name: Lights to Control
required: true
description: Lights to control
off_state_condition:
selector:
target: null
name: Off state condition
description: Determines what is off state of lights
mode: queued
max: 10