Hi Guys
I am looking for a Blueprint that turns light on at Sunset and Off at Sun rise, Pls
Thanks
Vaughan
Hi Guys
I am looking for a Blueprint that turns light on at Sunset and Off at Sun rise, Pls
Thanks
Vaughan
You don’t need a blueprint for that because this automation is straightforward.
Example:
alias: Christmas lights auto on/off
mode: single
trigger:
- platform: sun
event: sunrise
- platform: sun
event: sunset
condition: []
action:
- if:
- condition: template
value_template: "{{ trigger.event == \"sunrise\" }}"
then:
- type: turn_off
entity_id: switch.switch_movil_1
domain: switch
else:
- type: turn_on
entity_id: switch.switch_movil_1
domain: switch
Daniel
I tried using some of your coding here in a new automation - my knowledge of programming is pretty awful. I get an error when I try and test the template action. I just copied and pasted your value_template. I have put in a screen shot of the error. Is it a simple fix?
Daniel
A bit of fiddling and the below code worked?
- if:
- condition: template
value_template: trigger.event == \sunrise\
I see the problem. The content of value_template
should be a string. Its value should be quoted:
...
action:
- if:
- condition: template
value_template: "{{ trigger.event == \"sunrise\" }}"
...
Make sure to write the condition between double parentesis {{ }}
as well.
Daniel,
try as I might I can’t seem to see any difference to your latest string example and what I had attempted but threw errors?
The other code without parenthesis and quote marks appeared to run through the test without issue?
Pat
Daniel
just worked out my error. I copied and pasted your example into the gui window. When I switched to YAML then then process worked. thanks
Pat
I don’t know what the GUI expects to receive as value template. Maybe trigger.event == "sunrise"
or {{ trigger.event == "sunrise"}}
and it will put everything between quotes and escape the existing quotes with \"
.
Maybe when you copy&paste the already ready-to-use-in-YAML value template, it gets confused and breaks the valid template when correcting it.
I usually start my automation using the GUI, and then I switch to YAML to verify it generates the correct YAML. I do the same each time I update an automation as well. To make sure the GUI didn’t break something.