Switch that automaticly turns of after 1 hour

I would like som help with my watering system. when i turn on the switch “water 1” then i would like it to automaticly switch off after 1 hour. And i would also like to be able to turn it off if i somehow don´t want it to go the full time.

I now have 4 magnetic valves that i control via a Sonoff 4 pro that is included in my Home Assistant.

(in the best of worlds i would also like a slider so i could choose the length of time the sprinklers are on. but i know that it might be “overkill”)

Create an automation in the UI that triggers when the switch has been on for an hour — and set the action to turn it off.

If you turn it off manually within the hour, the trigger won’t fire.

If you restart HA while the light is on, though, the automation will be reset and you’ll have to switch it off manually.

That can be worked around if needed, and you can set a slider like you want, but that’s YAML territory. Get the first bit working to start with.

Hi, look at this:

alias: water_system_off_1h
description: Turn off switch water system after one hour
mode: single
trigger:
  - platform: state
    entity_id: switch.water_system
    to: 'on'
    for: '1:00:00'
condition: []
action:
  - service: switch.turn_off
    target:
      entity_id: switch.water_system

1 Like

this is in yaml, right?

yes

Go to automations, create new empty. Select edit in yaml mode and paste it

Worked super!! Than you!! is there also a way to se how much time there is left?

(in an easy way) :smiley:

If possible, I don’t know how to do it.

About the slider, you can do it with a helper entity. First edit the script to take the value from the helper entity and assign it to the “for” entry in the script.
Once achieved, you only need to tunne it in the UI to be shown as a slider. See this topic

Glad to help.

Hi,

Is it possible to set to monitor multiple entities and tun off after 1 hour? I have created an automation as below. I have 12 zones and want to make sure that when the script is fired by automation that whatever happens no single zone will run for longer than 1 hour. Will this work?

Thanks in advance

alias: Sprinklers Off After 1 Hour
  description: Turns off the Sprinklers if they have been left on for more than 1
    hour
  trigger:
  - platform: state
    entity_id:
    - switch.irrigation_zone_1
    - switch.irrigation_zone_2
    - switch.irrigation_zone_3
    - switch.irrigation_zone_4
    - switch.irrigation_zone_5
    - switch.irrigation_zone_6
    - switch.irrigation_zone_7
    - switch.irrigation_zone_8
    - switch.irrigation_zone_9
    - switch.irrigation_zone_10
    - switch.irrigation_zone_11
    - switch.irrigation_zone_12
    attribute: 'on'
    for:
      hours: 1
      minutes: 0
      seconds: 0
  condition: []
  action:
  - service: switch.turn_off
    data: {}
    target:
      entity_id:
      - switch.irrigation_zone_1
      - switch.irrigation_zone_2
      - switch.irrigation_zone_3
      - switch.irrigation_zone_4
      - switch.irrigation_zone_5
      - switch.irrigation_zone_6
      - switch.irrigation_zone_7
      - switch.irrigation_zone_8
      - switch.irrigation_zone_9
      - switch.irrigation_zone_10
      - switch.irrigation_zone_11
      - switch.irrigation_zone_12
  mode: single