marothe
(MR)
June 30, 2022, 8:50pm
1
hey,
quick question: I want an easy automation that turns off my bedroom lights automation when I turn one of my bedroom lights to red. I tried this with the UI configurator:
alias: Schlafzimmer Lights (Fix)
description: ''
trigger:
- platform: template
value_template: >-
"{{ is_state_attr('light.nachttisch_name' , 'rgb_color' , (255, 66, 8))
}}"
id: red
condition: []
action:
- condition: trigger
id: red
- service: automation.turn_off
data: {}
target:
entity_id: automation.schlafzimmer_lights_ui
mode: single
If I turn on “light.nachttisch_name” to the correct RGB values, nothing happens (i.e. the automation does not turn off…)
Any ideas what I am doing wrong?
Attributes of the light:
Try changing (255, 66, 8)
to [255, 66, 8]
. (I.e., change from a tuple to a list.)
marothe
(MR)
July 1, 2022, 10:40am
3
Hi @pnbruckner , thank you for taking a look here. I tried that and changed it to the following:
alias: Schlafzimmer Lights (Fix)
description: ''
trigger:
- platform: template
value_template: >-
"{{ is_state_attr('light.nachttisch_name' , 'rgb_color' , [255, 66,
8])}}"
id: red
condition: []
action:
- condition: trigger
id: red
- service: automation.turn_off
data: {}
target:
entity_id: automation.schlafzimmer_lights_ui
mode: single
But still no change, the automation does not trigger if I set the lights to the RGB values.
Here is the state of the light and the automation trace.
Hellis81
(Hellis81)
July 1, 2022, 10:51am
4
marothe:
value_template: >-
"{{ is_state_attr('light.nachttisch_name' , 'rgb_color' , [255, 66,
8])}}"
You use both >-
and "
.
either:
value_template: >-
{{ is_state_attr('light.nachttisch_name' , 'rgb_color' , [255, 66,
8])}}
or
value_template: "{{ is_state_attr('light.nachttisch_name' , 'rgb_color' , [255, 66,
8])}}"
2 Likes
marothe
(MR)
July 2, 2022, 6:54pm
5
Thank you @Hellis81 for that! I fixed that, but still no avail nothing happens:
- id: '1656514096118'
alias: 'Schlafzimmer Lights (Fix)'
description: ''
trigger:
- platform: template
value_template: "{{ is_state_attr('light.nachttisch_name' , 'rgb_color' , [255, 66, 8])}}"
id: red
condition: []
action:
- condition: trigger
id: red
- service: automation.turn_off
data: {}
target:
entity_id: automation.schlafzimmer_lights_ui
mode: single
This seems like an easy automation, I do not know why this is not working
Hellis81
(Hellis81)
July 2, 2022, 7:22pm
6
In developer tools → templates, what does this return:
{{ is_state_attr('light.nachttisch_name' , 'rgb_color' , [255, 66, 8]) }}
{{ state_attr('light.nachttisch_name' , 'rgb_color') }}
{{ states('light.nachttisch_name') }}
?
marothe
(MR)
July 2, 2022, 7:41pm
7
hey @Hellis81 ; this is the results:
{{ is_state_attr('light.nachttisch_name' , 'rgb_color' , [255, 66, 8]) }}
{{ state_attr('light.nachttisch_name' , 'rgb_color') }}
{{ states('light.nachttisch_name') }}
sooo…false, the current values and on for the light…this seems strange to me
Hellis81
(Hellis81)
July 2, 2022, 7:48pm
8
Ok…
What about:
{{ state_attr('light.nachttisch_name' , 'rgb_color') | join(",") == "255,66,8" }}
I just noticed there was spaces Infront of 66 and 8. Try and remove them from the previous template also. It shouldn’t matter but let’s see.
123
(Taras)
July 2, 2022, 9:37pm
9
Express the RGB value as a tuple instead of a list. Notice how the template reports true
when the value is compared with a tuple.
- id: '1656514096118'
alias: 'Schlafzimmer Lights (Fix)'
description: ''
trigger:
- platform: template
value_template: "{{ is_state_attr('light.nachttisch_name', 'rgb_color', (255, 66, 8)) }}"
condition: []
action:
- service: automation.turn_off
target:
entity_id: automation.schlafzimmer_lights_ui
mode: single
NOTE
Instead of creating an automation to turn off another automation, just add a Template Condition to the other automation.
With the following template, the automation executes its action
only if the light’s RGB value is not 255, 66, 8.
condition:
- platform: template
value_template: "{{ not is_state_attr('light.nachttisch_name', 'rgb_color', (255, 66, 8)) }}"
1 Like
marothe
(MR)
July 3, 2022, 7:56am
10
hey @123 , thank you so much! this did the trick. Funny, I changed it from a tuple to a list because of the first comment, the change from @Hellis81 then did the trick I guess but I did not change it back.
Also, thank you so much for your additional help. I am new to templating and also only did very basic automations for my lights as of so far, so I really appreciate it. I will try to add it as a condition!
Thank you everyone for the help!
Hellis81
(Hellis81)
July 3, 2022, 8:01am
11
The issue in the first post was the >-
and "
at the same time.
So the thread made a complete circle
1 Like