Im trying to setup an easy timer to turn a light on at 6pm and then turn it off at 9pm. I just cant figure out how to do it.
I’d use a couple of automations to do this:
alias: 'Light on at night'
trigger:
platform: time
at: '18:00:00'
action:
service: light.turn_on
entity_id: light.lounge_5_0
Then:
alias: 'Light off at night'
trigger:
platform: time
at: '21:00:00'
action:
service: light.turn_off
entity_id: light.lounge_5_0
In my case, I use sunset as the trigger, since in the summer I’m unlikely to want the light turned on so early. The documentation has more, including details on the supported triggers etc.
Thanks.
I tried your example but I get duplicate alias error in the log.
Have you tried hass --script check_config
?
A copy of your config would help considerably here. I suspect though that simply changing the aliases will help, since it sounds like you’ve already got a “Light on at night” or “Light off at night” automation.
Ok I got this to work. Thanks for the help.
automation:
alias: Turn on rock light for two hours
trigger:
- platform: time
after: '18:01:00'
action:
service: homeassistant.turn_on
entity_id: script.timed_lamp
script:
timed_lamp:
alias: "Turn on lamp and set timer"
sequence:
# Cancel ev. old timers
- service: script.turn_off
data:
entity_id: script.timer_off
- service: switch.turn_on
data:
entity_id: switch.great_room_rec_switch_3_0
# Set new timer
- service: script.turn_on
data:
entity_id: script.timer_off
timer_off:
alias: "Turn off lamp after 120 minutes"
sequence:
- delay:
minutes: 120
- service: switch.turn_off
data:
entity_id: switch.great_room_rec_switch_3_0
This method is more suitable for motion activated automation. What you need can be setup simply using @Tinkerer suggestion. It is simple and easy.
I was using @Tinkerer’s way up to some time ago. Now I installed hass.io (v5) and it not seem to like it.
Would anybody know why?
What does it not like?
What do your automations look like? Are the entity IDs correct?
The trigger time statements need to change from
after:
to
at
:
This is a breaking change
Good point, thanks. I’ll edit my original post to point that out for future searchers.
Well, I would if too much time hasn’t passed
Not sure how old this post is (seems over 2 years old).
I am trying to turn a switch (gpio pin) on at a certain time, and off at a certain time. I am having problems finding answers to my questions, mainly cause I think I am missing the key words I need for my search.
I can follow instructions on how to set up the automation to turn on and off at specific times, but this post came closer to helping me narrow my question.
Seems at one point the automation used “after” x time, but now “at” has to be used. I am assuming that “at” would only turn on the switch at the specified time. Let say we turn switch on at 7am, but at 7:05am we reboot the pi. At reboot all pins used would have a pull down, so pin would boot off and staff until the next day.
I am trying to set up an automation that would turn on a switch a x time and turn it off at y time, regardless if system reboots in between or is off during one of the trigger times
Hmmm, resurrecting an ancient thread…
A time trigger is mostly what you’re after.
However, if Home Assistant was shut down, then the trigger won’t fire. You’d need to also have a startup trigger and some time conditions so that it covered your other use case.