Automation - Run every hour for 14 minutes (Not working)

Apologies if this has been answered elsewhere, I’m relatively new to home assistant and its forums. I’ve been trying to write an automation where a fogging device turns on every hour for 14 minutes but despite my efforts it doesn’t seem to work and I don’t quite understand why.

The fogger is connected via raspberry pi gpio to a relay and the relay is controlled via home assistant. I can trigger the relay manually in home assistant and it works, so everything is wired correctly.

My automation.yaml code is as follows:

- alias: Fogger turns on for 14 minutes every 1 hour
  trigger:
    - platform: time
      hours: '/1'
      minutes: '00'
      seconds: '00'
  action:
    - service: switch.turn_on
      entity_id: switch.Fogger
    - delay:
        minutes: '14'
    - service: switch.turn_off
      entity_id: switch.Fogger

Think you need to use Time Pattern Trigger instead:

Please also check switch.Fogger. I’m almost certain that HA internally converts device names to lowercase for entity names.

Oh yes, and platform: time_pattern of course.

1 Like

Thanks, corrected my post

Yes: valid entity names reference

Thank you! Will change to time-pattern trigger and adjust switch.Fogger to switch.fogger and let you know how it goes :slight_smile:

I use this to run 25 mins every hour (3 mins after each hour to be precise as it was somehow clashing with another oddly) between certain times:

- id: '1592323457308'
  alias: Small Bathroom Heating
  description: ''
  trigger:
  - minutes: '03'
    platform: time_pattern
  condition:
  - after: 08:30
    before: '16:00'
    condition: time
  action:
  - data: {}
    entity_id: switch.sonoff_1000744b0c
    service: switch.turn_on
  - delay: 00:25
  - data: {}
    entity_id: switch.sonoff_1000744b0c
    service: switch.turn_off

Have made both changes but the automations till doesn’t work. The code is now:

- alias: Fogger turns on for 14 minutes every 1 hour
  trigger:
    - platform: time_pattern
      hours: '/1'
      minutes: '00'
      seconds: '00'
  action:
    - service: switch.turn_on
      entity_id: switch.fogger
    - delay: 00:14:00
    - service: switch.turn_off
      entity_id: switch.fogger

Please read the big warning box at the end of the Time Pattern trigger documentation:

The Delay docs also suggest the time might need to be in quotes, or you could use:

    - delay:
        minutes: 14

I actually tried your automation here, the

delay: 00:14:00

didn’t give a config check error but lead to odd results (early switch off).

So I’d suggest you use @Troon’s suggestion or put quotes around the delay value:

delay: '00:14:00'

Keep in mind when you use the delay function like that it does not work if you reboot HA.

Say you are one minute in the delay and reboot, that means the fogger Will not turn of until 1 hour and 13 minutes later.

That also. Timers and delays currently don’t survive HA restarts.
Also keep in mind that re-triggering an automation while it’s currently in a delay will abort the delay and continue with the next action in the sequence.

HA is full of quirks and little oddities. :wink:

So you might want to try something like this:

- alias: 'Fogger turns on for 14 minutes every 1 hour'
  trigger:
    - platform: time_pattern
      hours: '/1'
      minutes: 0
      seconds: 0
  action:
    - service: switch.turn_on
      entity_id: switch.fogger
    - delay: '00:14:00'
    - service: switch.turn_off
      entity_id: switch.fogger

Having read the thread, I would like to add:

Using version 2021.2.2 of Home Assistant, this is the YAML code that was automatically created to ‘Turn a fan on GrowFan for 5 minutes, every hour.’

Steps:
Go to ‘Configuration->Automations’
Click ‘+ Add Automation’ (Lower right corner)
Click ‘Start with an empty automation’

New Automation:
Name: Give it a name.

Triggers: (I added one trigger)
Trigger Type: Time Pattern
Hours: /1
Minutes: 0
Seconds: 0

Conditions: (I did not add any conditions.)

Actions: (I added three Actions.)
Action Type: Device (Turn Fan on)
Action Type: Delay (5 minutes)
Action Type: Device (Turn Fan off)

This has been verified to execute. (At least once :slight_smile:

Info found in ‘automations.yaml’:
(Created Automatically = created by HA when adding the automation.)


- id: '**Created Automatically**'
  alias: Control GrowFan
  description: ''
  trigger:
  - platform: time_pattern
    hours: /1
    minutes: '0'
    seconds: '0'
  condition: []
  action:
  - type: turn_on
    device_id: **Created Automatically**
    entity_id: switch.tasmota_4switch_01
    domain: switch
  - delay:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
  - type: turn_off
    device_id: **Created Automatically**
    entity_id: switch.tasmota_4switch_01
    domain: switch
  mode: single

1 Like

Awesome. Elfman, this guided me to setup a similar automation for me. Thanks for sharing.

Recent enhancements to Home Assistant allow for a simpler way to achieve the goal and without the use of delay.

- alias: Example 1
  trigger:
  - id: 'on'
    platform: time_pattern
    hours: /1
    minutes: '0'
    seconds: '0'
  - id: 'off'
    platform: time_pattern
    hours: /1
    minutes: '5'
    seconds: '0'
  action:
  - service: "switch.turn_{{ trigger.id }}"
    target:
      entity_id: switch.your_switch
1 Like

I am afraid that for some reason I know I should see how this works, but I am not.
If I am reading this right then the newest iteration here would trigger every hour (/1) and every 5 minutes after the hour (5), and based upon when the trigger was triggered the action would either run the if of ON or OFF.

Is this correct?

If so, does this mean that to create a simple automation that turns an entity on for a specified amount of time you can simply copy and paste this into a new automation YAML and replace the entity_id with your preferred entity and the time pattern with your required one and it would be one and done?

No more time deltas, no more multiple automation, one to turn on, one to turn off, etc?

Is there more documentation on this?

Hi,
I’m using your code :

- alias: Pompe piscine
  trigger:
  - id: 'on'
    platform: time_pattern
    hours: /1
    minutes: '0'
    seconds: '0'
  - id: 'off'
    platform: time_pattern
    hours: /1
    minutes: '15'
    seconds: '0'
  action:
  - service: "switch.turn_{{ trigger.id }}"
    target:
      entity_id: switch.relay_switch_1x2_5kw

It work well. But i would like to add a temperature condition to “ON” id only. For example, every hour i check if outdoor temperature is below 5 if yes i turn the switch on. And set to off the switch without condition after 15 minutes.

Here is what i tried to do :

- alias: Pompe piscine
  trigger:
  - id: 'on'
    platform: time_pattern
    hours: /1
    minutes: '0'
    seconds: '0'
    condition:
      alias: "Temperature < 5°"
      condition: numeric_state
      entity_id: sensor.universal_binary_sensor_air_temperature_4
      below: 5
  - id: 'off'
    platform: time_pattern
    hours: /1
    minutes: '15'
    seconds: '0'
  action:
  - service: "switch.turn_{{ trigger.id }}"
    target:
      entity_id: switch.relay_switch_1x2_5kw

Here is what i came through :

alias: Pompe piscine
trigger:
  - id: "on"
    platform: time_pattern
    hours: /1
    minutes: "17"
    seconds: "0"
  - id: "off"
    platform: time_pattern
    hours: /1
    minutes: "18"
    seconds: "0"
condition:
  - condition: or
    conditions:
      - condition: and
        conditions:
          - condition: trigger
            id: "on"
          - condition: numeric_state
            entity_id: sensor.universal_binary_sensor_air_temperature_4
            below: 10
      - condition: trigger
        id: "off"
action:
  - service: switch.turn_{{ trigger.id }}
    target:
      entity_id: switch.relay_switch_1x2_5kw