Turn on switch after x amount of time with option to delay

Hi, I have a circulation pump connected to a switch which now is on between 9am to 9pm. Once a day I need to turn it off for 15 minutes and clean a filter. I often forget to turn it back on. It would be convenient if I in the Home assistant frontend would have a card with on/off switch and a slider where I can decide the amount of time for the switch to be turned off.

The senario would be

  1. Decide amount of time to be turned off with a slider
  2. Click switch to turn off
  3. Switch turns on automatically after the decided time in the slider.

Also there needs to be an automation for the pump to continue to turn off at 9pm and then back on at 9pm

I have looked at these links but I can´t get it to work:

Not trying to be the safety police but do you think it’s a good idea to have the pump turn on automatically if you’ve turned it off in order to open the system to do maintenance on it?

Let’s say you set the timer for 30 minutes and turn the switch off, open the filter to change it and something comes up that draws your attention from the time. Then after 30 minutes the system is still open and the pump suddenly turns back on. Especially bad if you are working on it when it does not to mention possible property damage at a minimum.

Wouldn’t it be better to set up a persistent notification to keep telling you that you forgot to turn the pump back on? That way it will keep annoying you if you forget but you won’t suddenly get sprayed by whatever liquid the pump is supposed to be circulating! :scream:

I understand your point but if the pump would turn on with the filter removed it would not do any harm. The water would just pass the filter since the pump is operating on a low pressure.

I would prefer home assistant to turn tje pump back on automatically.

I have thought about putting in a delay, but what´s the fun in that. It would also look nicer with a card in the frontend of homeassistant with a slider :slight_smile:

What is the code you have tried so far?

I have copied the text from the above link and then renamed everything. It might be that I missed
In configuration.yaml

input_slider:
   pump_time:
    name: Pump Timer
    initial: 10
    min: 1
    max: 60
    step: 5

in script.yaml

  pump_timer:
    alias: "Pump timer"
    sequence:
      - delay: '00:{{ states.input_slider.pump_time.state | int }}:00'
      - service: homeassistant.turn_on
        data:
          entity_id: switch.pump_low

in automation.yaml

  - alias: "Pumo: Automatically turn on"
    trigger:
      - platform: state
        entity_id: switch.pump_low
        to: 'off'
    action:
      - service: script.turn_on
        entity_id: script.pump_timer

  - alias: "Pump reset timer"
    trigger:
      - platform: state
        entity_id: switch.pump_low
        to: 'on'
    action:
      - service: script.turn_off
        entity_id: script.pump_timer

In groups.yaml

  Timers:
    entities:
      - input_slider.pump_time

There are a couple of things -

The “input_slider” has been renamed to “input_number”. Change that.

And I’m not really sure if it’s a problem but I think you can’t have the colon in your alias. remove that also (“Pumo Automatically turn on”).

Give it a try then.

1 Like

Alright, I´ll give it a try tnight :slight_smile:

I saw this post from you (@finity) Light auto off timer

Can I use a similar code and include the automation for shutting off the pump at 9pm and then coming back at 9am? Possible with a conditon?

You can use that automation for your turn back on delay but you said you wanted to use a variable selectable delay. :wink:

I don’t think you can combine the two automations since they are fundamentally performing two opposing actions (turning back on after a delay, turning off at a certain time). you might be able to do it but it would take a bunch of templating that gets hairy.

Easiest to just handle those different situations with two automations. But you can put a condition in so that if it’s after 9pm when the dekllay runs out and should be turning the pump back it won’t fire.

I think the following will work for that:

pump_timer:
    alias: "Pump timer"
    sequence:
      - delay: '00:{{ states.input_slider.pump_time.state | int }}:00'
      - condition: time
        before: '21:00:00'
      - service: homeassistant.turn_on
        data:
          entity_id: switch.pump_low

Alright, seems to be working at least in the frontend. Now to trigger the event, I am unsure what to use.

I have two on/off switches in automations:

  • pump automatically turn on
  • pump reset timer

I have on script

  • pump timer

And I have one slider

Should i enter the number of minutes and then hit the script?

If you want to test whether just the automations or script conditions and actions work then just either execute the script or select the automation in the frontend and then click ‘trigger’

to fully test the automation and make sure it works in a normal production environment just turn off your switch (switch.pump_low) then wait to see if the switch gets turned back on at the time set by the input number.

Then change the input number and try it again to make sure the time delay changes.

The automations doesn´t seem to work.

Regarding ‘00:{{ states.input_slider.pump_time.state | int }}:00’

Shouldn´t it be ‘00:{{ states.input_number.pump_time.state | int }}:00’ ?

yes it should.

It works! Thanks you @finity. Now I am going to try to make an automation for my car heater depending on the temperature outside :slight_smile:

Good Luck! :grinning: