Hi I have the below automation rules set for my main door light to turn on & off:
# Front Light On 15min after sunset
- id: front_lights_on_at_sunset
alias: front lights on at sunset
trigger:
platform: sun
event: sunset
offset: "00:15:00"
action:
service: homeassistant.turn_on
entity_id: switch.maindoor
# Front Lights Off at 11PM
- id: front_lights_off_at_11_night
alias: front lights off at 11 night
trigger:
platform: time
at: "23:00:00"
action:
service: homeassistant.turn_off
entity_id: switch.maindoor
I need help to implement data_ template to dynamically compute light off time based on season value. I have sensor.season configured and it provides values {‘Spring’, ‘Summer’, ‘Autumn’, ‘Winter’} and for each of these season I want light to turn off at {“22:30:00”, “23:30:00”, “23:00:00”, “22:00:00”}. Any help along this or any other suggestion appreciated.
# Front Lights Off at time defined by season
- id: front_lights_off_by_season
alias: front lights off by season
trigger:
platform: time
at: "21:59:00"
action:
- delay: >
TEMPLATE HERE - if winter, 1 minute, if spring 31 minutes etc
- service: homeassistant.turn_off
entity_id: switch.maindoor
I’m on my phone so you’ll have to figure out the template
Well lets see, we want to turn off a light dependent on seasons, which is dependent on where the SUN is in the sky, without being too sarcastic, i would just delay the light turn off by 3min 48s per day, so use the variable custom component to do the work, or just delay the turn off by 6hrs from sunset, however since the OP only wants an 1:30hrs diff between summer and winter maybe @anon43302295 ‘s idea is better than mine (can’t see any code there tho’ )
Thanks to both of you for your prompt response and sharing different ways of achieving it. I was trying to achieve through data_template but quickest one is to use the Keith’s idea the same sun set event with a standard delay to switch off the light and it will automatically adjust 3min 48 seconds per day. I also like the idea of delay calculation based on template as it opens the door for me to think of other automations. Can you please help with the exact syntax of template to use delay in below statement with {%if ( ) %} {%else ( ) %} …{endif%}? It is very confusing to me.
action:
- delay: >
TEMPLATE HERE - if winter, 1 minute, if spring 31 minutes etc
I think there may be some confusion on what you really want to do.
do you want to always turn the lights off a certain number of hours or minutes after sunset (ie 4 hours)?
Do you want to turn the lights off at a certain time depending on the season for no regard to how long they are on?
the first is fairly easy. use an offset past sunset (offset: “04:00:00”)
the second is harder. I don’t know of a sensor for “season”. there might be one but i just don’t know it. or you could possibly create one based on date.
if it’s the second you just need to use if/else statements determined by your season sensor.
if it’s some other third thing then clarify, please.
Yes I want to use Homeassistant’s inbuilt component Season that has a sensor which returns the value of season prevailing and take decision to switch off light specially because I am in EST zone that has big variation of time from summer to winter during the year. This is how I want light to turn off light:
Summer: 11:30PM
Autumn: 11:00PM
Winter: 10:00PM
Spring: 10:30PM
Thank you.
I was not able to place delay inside trigger action as it kept giving error instead tried the time directly inside trigger as below:
# Front Lights Off at Night
- id: front_lights_off_at_night
alias: front lights off at night
trigger:
platform: time
at: '{% if states("sensor.season") == "Winter" %}21:30:00{% elif states("sensor.season") == "Spring" %}22:30:00{% elif states("sensor.season") == "Summer" %}23:59:59{% elif states("sensor.season") == "Autumn" %}23:00:00{% endif %}'
action:
service: homeassistant.turn_off
entity_id: switch.maindoor
But config log giving error and can not figure out syntax error: Invalid time specified: {% if states("sensor.season") == "Winter" %}21:30:00{% elif states("sensor.season") == "Spring" %}22:30:00{% elif states("sensor.season") == "Summer" %}23:59:59{% elif states("sensor.season") == "Autumn" %}23:00:00{% endif %} for dictionary value @ data['trigger'][0]['at']. Got None. (See /config/configuration.yaml, line 299). Please check the docs at https://home-assistant.io/components/automation/_