You’re missing an is_state in the second part of the if statement there.
Same here. And, I believe that is_state looks for an exact match, not a formula. So, you may want to try states('sensor.pool_pump_running_today') | float < 8.0 (assuming that this stores a float, not an int).
And, I think for the service_template to work across multiple lines you can’t use double-quotes, but the syntax is service_template: > followed by the template code on the next line.
Thanks for your advice. It seems that in my quest I may be trying to over simplify it as I’ve ended up with a problem. Of course, now the pool pump (fake) will try and turn on (or off) every 2 minutes! Trying to think of an easy way to solve that.
automation:
- alias: Simple pool control
trigger:
- platform: time_pattern
minutes: '/2'
condition:
- condition: time
after: "08:59:00"
action:
- service_template: >
{% if is_state('sensor.power_rate' , 'offpeak') and states('sensor.pool_pump_running_today') | float >8%}
input_boolean.turn_on
{% else %}
input_boolean.turn_off
{% endif %}
entity_id: input_boolean.fake_pool_pump
- service: notify.mobile_app_nokia_7_1
data:
message: "Fake Pool Pump is {{states('input_boolean.fake_pool_pump')}}"
input_boolean:
fake_pool_pump:
name: Fake Pool Pump
I’m wondering if 2 minutes is a bit too aggressive. Would checking every 5, 10 or 15 minutes work as well? I mean, it’s probably not going to ruin you if you run the pool pump for 8 hours and 5 minutes, or if you run it for 5 minutes on your peak tariff?
If you are concerned with the pump’s power switch being triggered all the time, you could think about starting the action list with a condition that checks if the pump is already in the correct state, and only continue if it isn’t.
Agreed but I’m wondering of the implication of using a pool pump ‘on’ condition as that would prevent the service_template from functioning properly?
In my code, 0900 comes around, so we move on. Pool pump is ‘off’ so we move one. Service template starts and determines that it’s peak time so it turns the pool pump off, no big deal.
1100 rolls around (offpeak start) and the 2/5/15 min check determines it’s after 08:59 and the pool pump is ‘off’ so the service template starts. As it’s now offpeak and the pump has run for <8hrs, it turns the pump on. All good.
Now here’s the problem. It gets to 1700 when peak rate has initiated and the automation runs. It’s after 08:59 so we move on. Uh oh, pool pump is not ‘off’ so the automation stops and the pool pump is not switched off. Not quite sure how to solve that.
I’ve decided just to leave my automations as-is but to replace all of my time constraint conditions with my state('sensor.power_rate' , 'offpeak') condition and that should tidy things up a lot.