@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:
It’s not a work around, it’s the current way unfortunately. Maybe in the future they will add a attribute to trigger that filters even and odd. I doubt it’s even on the dev’s radar. Might want to add a feature request.
Condition would be best way to do the odd hour thing. I don’t think any automation system, commercial or DIY, are granular enough on the triggers to split odd/even hours like that without using a condition.