I’d like to make a new automation to control my hot water circulation valve. For this I have a temperature sensor in my hot water tank, and another one measuring the water’s temperature inside the circulation pipe.
I want to start the circulation valve if the difference between the pipe’s and the tank’s water temperature equals or bigger than -8 degrees celcius (meaning when I have 45 degrees water temp in the tank, and 37 degrees water temp in the pipe, the valve kicks in, and delivers 45 degrees hot water to the sink), and stop the valve if the difference equals or smaller than -1 degree celsius (and of course consider some conditions, like we’re at home, alarm system is on/off, etc.) to save energy as much as possible. Currently it is operated by a dumb daily schedule, which is inefficient and also inconvenient at the same time.
To trigger the two separate automations with different conditions to turn on and off the valve, I thought of creating a binary sensor which turns ON if the difference of the two temperature sensor falls into the required range, and turn OFF, if into the other. State change of this binary sensor would trigger my automations respectively.
For the love of God I could not fabricate the needed mathematical calculus within a value template, thus I’m asking for the help of the beloved HA community. Tried to make it happen in developer tools, failed, tried to look for similar solutions in the forums, also failed, my bad, but not my ignorance
Logic I’d like to achieve:
binary sensor state is ON, while:
sensor.shelly1_8caab57452f2_temperature (pipe temp) MINUS sensor.daikin_altherma_dhwtanktemp (water tank temp) EQUALS OR LESS than -8 degrees
binary sensor state is OFF, while:
sensor.shelly1_8caab57452f2_temperature (pipe temp) MINUS sensor.daikin_altherma_dhwtanktemp (water tank temp) EQUALS OR GREAT than -1 degrees
Many thanks in advance, if you have advice on the whole automation setup as well, would be also greatly appreciated.
wow, thank you very much for your very very fast and effective help @Troon !!!
yes, and I see the mistake I made between the first paragraph and the “logic” part, and the logic part is the correct, hence the aimed negative temp difference, thank you very much!!!
Thanks again for your help, it almost works flawlessly, but your formula is perfect! I bumped into a small obstacle on the automation part: since the trigger is the actual state change, I’m having a hard time to start the automation, where I have a condition to only run the automation in a certain time range (between 6:00 and 23:59), but the state of this binary sensor already changed to ON before this time range. If it is already on before the time condition passes, the automation will not start. It will, obviously, when the next time the sensor will turn on, but it’s not what I’d like to achieve. What I’d like to have in this case, is this: IF the time condition passes, so it’s 06:00:01, and at the same moment the sensor state IS already ON, then fire action.
Can anyone give me some advice how to handle situations like this, automation wise?
My automation as it is right now:
alias: Turn hot water circluation ON
description: ""
trigger:
- platform: state
entity_id:
- binary_sensor.cirkulacios_homerseklet_igeny
to: "on"
for:
hours: 0
minutes: 0
seconds: 5
condition:
- condition: time
after: "06:00:00"
before: "23:59:00"
weekday:
- mon
- tue
- wed
- thu
- fri
- sat
- sun
- condition: or
conditions:
- condition: device
device_id: XXXXX
domain: device_tracker
entity_id: device_tracker.1
type: is_home
- condition: device
device_id: XXXXX
domain: device_tracker
entity_id: device_tracker.2
type: is_home
- condition: state
entity_id: alarm_control_panel.area_1
state: disarmed
action:
- service: switch.turn_on
data: {}
target:
entity_id: switch.shellyplug_s_51d5f9
mode: single
ah, clever, so it’s a 3rd automation, trigger wil be time only (06:01:00), condition binary sensor state is on (and device trackers and alarm control panel state)
I’d like to bother you a little bit more, I hope you don’t mind.
I noticed, that sometimes the pipe’s temp seeks above the water tank temp. Since we are substracting tank water temp from pipe temp, the math gives positive number, and the circulation does not stop, thus draining the temp further from the tank…
could you help me to modify the binary sensor value template to also switch the state to OFF in case the pipe temp is HIGHER than the tank water temp?
It should already do that, as positive numbers are greater than -1. Can you paste a history chart for just the second arrow section, also showing the binary sensor as well as the valve position? I wonder if there are spurious measurements that are interfering with the “for 5 minutes” in the trigger…
That looks like the sensor is working as expected, but the valve is not following it.
Why did the valve not turn off at about 18:10, and why did it turn off at about 00:40 instead of 00:01? Is there anything in the log, or traces from the automation?
Is the “valve operation” line showing switch.shellyplug_s_51d5f9 or some other entity?
Is the “valve operation” line showing switch.shellyplug_s_51d5f9 or some other entity?
correct.
Why did the valve not turn off at about 18:10, and why did it turn off at about 00:40 instead of 00:01? Is there anything in the log, or traces from the automation?
hm, indeed, strange, I don’t see any error message in the log, automation traces only gives 5 recent trigger point to check, so I don’t know what happened at 18:14 yesterday, when the binary sensor changed to off, but the automation did not get triggered:
Logger: homeassistant.components.automation.melegviz_keringetes_kikapcsol
Source: components/automation/__init__.py:580
Integration: Automation (documentation, issues)
First occurred: 13 June 2023 at 14:29:09 (4 occurrences)
Last logged: 10:39:50
Error while executing automation automation.melegviz_keringetes_kikapcsol: must contain at least one of entity_id, device_id, area_id.
Error while executing automation automation.melegviz_keringetes_kikapcsol: Setting state for entity shellyplug-s-51D5F9 failed, state: {'turn': 'off'}, error: DeviceConnectionError()