I have been trying to get this automation to run correctly, however it seems to turn on every hour instead of every 2 hours.
Am I missing something here? Please help
Thanks
- id: FT Bed Heater Auto On for 30 Minutes Every 2 Hour From 11pm to 6am
alias: FT Bed Heater Auto On for 30 Minutes Every 2 Hour From 11pm to 6am
trigger:
platform: time
minutes: '/120'
seconds: 00
condition:
- after: '23:00:00'
before: 06:00:00
condition: time
action:
- entity_id: switch.ftheater
service: homeassistant.turn_on
- delay: 00:30:00
- entity_id: switch.ftheater
service: homeassistant.turn_off
I tried with the HOURS, automation didnt fire at all. as of right now I just created 4 separate automation based on AT specific time, until i can figure out why.
@mateola, the way I read the code, even though the docs donāt say it, the time trigger does support seconds, minutes and hours. So you should be able to do (although I havenāt tried myself):
trigger:
platform: time
hours: '/2'
minutes: 0
seconds: 0
The reason this:
trigger:
platform: time
minutes: '/120'
seconds: 0
doesnāt work (i.e., triggers every hour instead of every two hours) is because it does a modulo operation of the current minute with the value provided and triggers if the result is zero. But minute only goes from 0 to 59. So, every time the minute is 0 it will trigger (i.e., 0 % 120 == 0), which happens once every hour.
Pretty sure the issue is with your condition not your trigger. First, in your condition, you donāt have quotes around your before time. All times need quotes.
I also got rid of your ID. Usually thatās an integer. Not sure what a huge ass string will do in that. Itās also auto populated so you donāt need to add it yourself.
- alias: FT Bed Heater Auto On for 30 Minutes Every 2 Hour From 11pm to 6am
trigger:
platform: time
minutes: '/120'
seconds: 0
condition:
- condition: time
after: '23:00:00'
before: '06:00:00'
action:
- entity_id: switch.ftheater
service: homeassistant.turn_on
- delay: 00:30:00
- entity_id: switch.ftheater
service: homeassistant.turn_off
Also, all the talk about the trigger may be correct. Iāve never made this trigger beyond 60 minutes.
EDIT: After reading @pnbrucknerās response, I tend to agree with him about the trigger occuring once an hour due to seconds going from 0 to 59.
So, I followed the code too and you are 100% correct, /120 wonāt work because they are using mod (%) against time. So @mateola final automation should be:
- alias: FT Bed Heater Auto On for 30 Minutes Every 2 Hour From 11pm to 6am
id: FT Bed Heater Auto On for 30 Minutes Every 2 Hour From 11pm to 6am
trigger:
platform: time
hour: '/2'
minutes: 0
seconds: 0
condition:
- condition: time
after: '23:00:00'
before: '06:00:00'
action:
- entity_id: switch.ftheater
service: homeassistant.turn_on
- delay: 00:30:00
- entity_id: switch.ftheater
service: homeassistant.turn_off
In case anyone is following this now, in later versions of Home Assistant the time platform has been split into time and time_pattern. See https://www.home-assistant.io/docs/automation/trigger/ .
In this case it would now be: