Okay, although I wanted too very badly, I couldn’t really investigate / respond yesterday about the code as my brain was distracted with other pressing issues that I unexpectedly got hit with.
The issue I see with your code suggestion now (thanks again, btw!) is that the operational test perform don’t actually produce the desired effect.
You are right about the input_slider representing the value of Number of times per day the pump should run. Dividing this value against 24 hours in a day, I derive elsewhere that this should represent the interval in “n” hours. So if the user selects 24 times a day, I thought we can evaluate that quickly in a Template Trigger (if I am allowed to do such a thing) with:
trigger:
platform: time
hour: ‘/{{ ( 24 / float(states(“input_select.reefdoser2_pump1_daily_freq”))) | int }}’
seconds: 00
And we’d know what the result is without actually triggering the automation to run and test further conditions (and be more efficient). BTW & just FYI, I don’t define a hard limit to minutes: in the time trigger, because that’s another variable the user can choose to “offset” the pumps so they do not (or do) run at the same synchronised time.
“{{ now().hour % states(‘input_select.reefdoser2_pump1_daily_freq’)|int == 0 }}”
Only when I looked at it again with more focus (and coffee) this morning, did I realise your suggestion wouldn’t work “as is”. The value in the input_select.reefdoser2_pump1_daily_freq object isn’t the actual hour it should run, but the number of times it should run per day.
However, you were on the right track with your suggestion and which kicked me in the butt to realise my own solution which was to divide it into 24, which I’d done elsewhere in my code and BOOM it works.
{{ now().hour % ( 24 / float(states(‘input_select.reefdoser2_pump3_daily_freq’)))|int == 0 }}
So now I have the following automation - only ONCE for each pump. YAY!
- alias: Reefdoser1 Pump1 at the specified frequency
trigger:
- platform: time
hours: '/1'
seconds: '00'
condition:
condition: and
conditions:
- condition: template
value_template: "{{ now().hour % ( 24 / float(states('input_select.reefdoser1_pump1_daily_freq')))|int == 0 }}"
- condition: template
value_template: "{% if now().minute | int == states.input_number.reefdoser1_pump1_daily_mins.state | int %}true{% endif %}"
- condition: state
entity_id: sensor.reefdoser1
state: 'Online'
- condition: state
entity_id: input_boolean.r1d1
state: 'on'
action:
- service: switch.turn_on
entity_id: switch.reefdoser1_pump1
- delay: '00:00:{{ states.sensor.reefdoser1_pump1_time_split.state | int }}'
- service: switch.turn_off
entity_id: switch.reefdoser1_pump1
Thanks again @pnbruckner!
BTW, for anyone who’s curious to know more about my project with dosing pumps, I’ll be releasing the full YAML code on how I did this automatic dosing pump upgrade to Sonoff/MQTT setup very shortly on the Share Your Projects thread.