Automation - Turn Heater On Every 2 Hours

Hi all

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

Anyone? Please halpp…

Replace minutes: /120 by

hours: /2
minutes: 00
seconds: 00

Not 100% sure though

I didnt use HOURS because i thought it’s not supported for this automation, hence im sticking with MINUTES.

But I will try and see what happens.

Thanks!

Anyway, it should be working with minutes…

yes i found that and followed that guide, however mine still doesnt work for some reason.
it was turning every hour instead of every 2 hours.

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.

cheers

Hi,
Did you find how to fix it ?
I would like to use the same solution.

Thank you in advance

@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.

It’s only auto-populated if the automation editor was used, and it can be any unique value.

thanks for clearing that up.

The docs say that hour:, minute: and second: are supported, and that you can use / notation in any of them.

So,

  trigger: 
    platform: time
    hours: '/2'
    minutes: 0
    seconds: 0

Should work

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

Perfetc !! Thank you guys

Using hour throws a config check error for me:

  trigger: 
    platform: time
    hour: '/2'
    minutes: 0
    seconds: 0

Invalid config for [automation]: [hour] is an invalid option for [automation]. Check: automation->trigger->0->hour.

However using minutes doesn’t work either (runs every hour regardless of value). Here’s my automation:

- id: speed_tests
  alias: 'Run speed test every 6 hours'
  trigger:
    platform: time
    minutes: '/360'
    seconds: 0
  condition:
    condition: state
    entity_id: sensor.steam_123
    state: 'offline'
  action:
    service: sensor.update_speedtest

It’s hours:, not hour:.

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:

trigger:
  platform: time_pattern
  hours: xxxx
  minutes: xxxx
  seconds: xxxx
condition:
 ........

Thank you! It would have taken me forever to figure this out had I not seen this last comment.

the “/2” patern is clear - for every even hour.
what if I need every odd hour ?