I have a suggestion, but make an assumption - at times where the temperatures are oscillating around each other you don’t want the valve to go on-off-on-off-etc. within seconds. So, my suggestion is to run an automation for example every 5 minutes, and compare temperatures.
Personally, I dislike time period automations. What I would do is create a template sensor and make an automation based off that. This is only required because you can’t use the for: attribute for template triggers. There’s a PR for that currently and the functionality should be in the software soon… but until then:
Then your automation would use the for x minutes for turning on/off the pool switch
- alias: Pool Switch
trigger:
- platform: state
entity_id: binary_sensor.pool_temperature
to: 'off'
from: 'on'
for: '00:05:00'
- platform: state
entity_id: binary_sensor.pool_temperature
from: 'off'
to: 'on'
for: '00:05:00'
action:
- service_template: >
switch.turn_{{ trigger.to_state.state }}
entity_id: switch.switch1
So this setup creates an on/off sensor to let you know when the temperature of sensor.temp1 is greater than sensor.temp2. It will update whenever temp1 or temp2 updates. So you don’t need to ‘check it every 5 minutes’. Next, the automation watches the state changes of the on/off sensor. If the state changes and it stays the same for 5 minutes, then the automation will trigger. If it turns on, it will turn on the switch. If it turns off, it will turn off the switch.
Thank you,
This works perfectly and exactly as i wanted.
But one question,
When I open the automation in frontend it says that the “action” is invalid!?
I actually don’t care that much because it works as it supposed to. I’m just curious why it says that and works anyway.
Scripts are equivalent to buttons. Treat a scripts sequence like the action section of an automation. You can also use a switch template and have the turn on and turn off sections turn on/off the automation and switch.