Interesting one. It's actually a pretty complex little process since it requires variables for the on/off time and has to loop. I can do this faster without node red since I'm not that comfortable with NR yet...
Here's how I was able to get this to work:
- Under configuration --> helpers, add a toggle and name it "Cycle Pump". The entity ID should become input_boolean.cycle_pump when you create it.
- Again, under helpers, add 2 input numbers. One will be named "Pump On Time" and the other will be "Pump Off Time". Set the min/max values for each and give them a unit of measurement. You can use seconds for the on time and minutes for the off time or whatever you'd like. This is just a label for you to read and doesn't actually change how the input works.
- Add an "Entities" card to your dashboard and add these 3 helpers to it.
- Go to your automations.yaml file and paste this in:
Code: Select all
- id: '1595019292093'
alias: Cycle Pump GO
description: ''
trigger:
- entity_id: input_boolean.cycle_pump
platform: state
to: 'on'
condition: []
action:
- data: {}
entity_id: script.1595017680358
service: script.turn_on
- id: '1595019345732'
alias: Cycle Pump STOP
description: ''
trigger:
- entity_id: input_boolean.cycle_pump
platform: state
to: 'off'
condition: []
action:
- data: {}
entity_id: switch. #PASTE IN THE ENTITY ID OF YOUR SWITCH HERE
service: switch.turn_off
- data: {}
entity_id: script.1595017680358
service: script.turn_off
- data: {}
entity_id: script.1595017404845
service: script.turn_off
This is going to call a script when you turn your toggle on (which will actually be looping another script), and it's going to stop these scripts and force your pump off when you turn the toggle off.
- Now go to your scripts.yaml and paste this in:
Code: Select all
'1595017404845':
alias: Cycle Pump On and Off
sequence:
- data: {}
entity_id: switch. #PASTE IN THE ENTITY ID OF YOUR SWITCH HERE
service: switch.turn_on
- delay:
seconds: "{{ states('input_number.pump_on_time') | int }}" #change the "seconds" at the beginning of this line to minutes or hours or whatever unit you want your on time input to be... this one matters!
- data: {}
entity_id: switch. #PASTE IN THE ENTITY ID OF YOUR SWITCH HERE
service: switch.turn_off
- delay:
seconds: "{{ states('input_number.pump_off_time') | int }}" #change the "seconds" at the beginning of this line if you want your off time input to be in minutes, hours, or whatever
- data: {}
service: script.1595017680358
'1595017680358':
alias: Call Pump Script
sequence:
- wait_template: "{{ is_state('script.1595017404845', 'off') }}" #The wait ensures the other script is ready to be called
- data: {}
entity_id: script.1595017404845
service: script.turn_on
The smaller script's only purpose is to call the other script which turns the switches on and off... the big script then calls the little one, which calls the big one... and this repeats until you turn your pump toggle off.
Do a config check and restart if you're all good.