wocko1
(Thomas Watkins)
October 26, 2018, 10:22am
1
Hi, I am trying to write a christmas lights script, which will check input booleans to check what lights to include.
I am trying this code
lights_chrissie_on:
alias: Lights chrissie on
sequence:
- service: light.turn_on
data_template:
entity_id: light.{{['games_room_front']|random}}
#entity_id: light.{{['games_room_front'{% if is_state(input_boolean.effect_gr_rear, 'on') %},'games_room_rear'{% endif %}]|random}}
brightness: '{{ (range(50, 250)|random) }}'
color_name: '{% if (range(0,11) | random) <= 5 %}red{% else %}green{% endif %}'
transition: '{{ (range(1, 3)|random) }}'
but the config check fails everytime. How do I fix this?
Thanks in advance
tom_l
October 26, 2018, 10:36am
2
What is the error message?
wocko1
(Thomas Watkins)
October 26, 2018, 11:15am
3
Invalid config for [script]: invalid template (TemplateSyntaxError: expected token ‘,’, got ‘{’) for dictionary value @ data[‘script’][‘lights_chrissie_on’][‘sequence’][0][‘data_template’][‘entity_id’]. Got “light.{{[‘games_room_front’{% if is_state(input_boolean.effect_gr_rear, ‘on’) %},‘games_room_rear’{% endif %}]|random}}”. (See /config/configuration.yaml, line 134). Please check the docs at https://home-assistant.io/components/script/
petro
(Petro)
October 26, 2018, 11:28am
4
Your template should work if you put your entity_id template in quotes.
lights_chrissie_on:
alias: Lights chrissie on
sequence:
- service: light.turn_on
data_template:
entity_id: "light.{{['games_room_front']|random}}"
#entity_id: light.{{['games_room_front'{% if is_state(input_boolean.effect_gr_rear, 'on') %},'games_room_rear'{% endif %}]|random}}
brightness: '{{ (range(50, 250)|random) }}'
color_name: '{% if (range(0,11) | random) <= 5 %}red{% else %}green{% endif %}'
transition: '{{ (range(1, 3)|random) }}'
Anyways, it looks like you are trying to check to see if lights are on and only change the ones that are on. So…
Try this, it will error though if all of your lights are off so I added a condition in the front.
lights_chrissie_on:
alias: Lights chrissie on
sequence:
- condition: template
value_template: >
{% light_list = ['light.games_room_front','light.games_room_rear'] %}
{{ states.light | selectattr('entity_id','in',light_list) | selectattr('state','eq','on') | list | length >= 1 }}
- service: light.turn_on
data_template:
entity_id: >
{% light_list = ['light.games_room_front','light.games_room_rear'] %}
{{ states.light | selectattr('entity_id','in', light_list) | selectattr('state','eq','on') | map(attribute='entity_id') | list | random }}
brightness: "{{ range(50, 250) | random }}"
color_name: "{{ ['red','green'] | random) }}"
transition: "{{ range(1, 3) | random }}"
dusing
(Dusing)
December 2, 2020, 1:42am
5
OLD thread I know. but I’m trying to use this script to rotate red/green colors with my lights and I’m getting an error. Here is the whole automation:
- alias: 'Turn Outside lights on when the sun gets dim'
trigger:
platform: numeric_state
entity_id: sun.sun
value_template: '{{ state.attributes.elevation }}'
below: 0
action:
- service: scene.turn_on
entity_id: scene.outside_night
- delay: '00:01:00'
- condition: template
value_template: >
{% light_list = ['light.porch_1','light.porch_2','light.porch_3','light.porch_4'] %}
{{ states.light | selectattr('entity_id','in',light_list) | selectattr('state','eq','on') | list | length >= 1 }}
- service: light.turn_on
data_template:
entity_id: >
{% light_list = ['light.porch_1','light.porch_2','light.porch_3','light.porch_4'] %}
{{ states.light | selectattr('entity_id','in', light_list) | selectattr('state','eq','on') | map(attribute='entity_id') | list | random }}
brightness: "{{ range(50, 250) | random }}"
color_name: "{{ ['red','green'] | random) }}"
transition: "{{ range(1, 3) | random }}"
I get this error: Invalid config for [automation]: invalid template (TemplateSyntaxError: Encountered unknown tag 'light_list'.) for dictionary value @ data['action'][2]['data_template']. Got None. (See /config/configuration.yaml, line 501).
dusing
(Dusing)
December 2, 2020, 2:44am
7
Thanks, after that change it is giving me this error
Invalid config for [automation]: invalid template (TemplateSyntaxError: unexpected ')') for dictionary value @ data['action'][3]['data_template']. Got None. (See /config/configuration.yaml, line 501).
petro
(Petro)
December 2, 2020, 3:30am
8
Color name has an extra ) that it shouldnt