Hi there folks,
I have recently migrated my Smart Home from smarthomeNG to Home Assistant. And I really love HA for what it is. Easy and maintainable. All can be done from the UI, which is really nice.
There is just one feature I cannot wrap my head around on how to solve that in HA.
In smarthomeNG you can use a python script to run a logic and trigger events.
For example I did this:
from datetime import datetime, time
now = datetime.now()
now_time = now.time()
TWO = sh.Zentral.Kesseltemperaturen.TrinkwasserOben() # Read one temperature
HWO = sh.Zentral.Kesseltemperaturen.HeizungswasserOben() # Read another temperature
Pumpe = sh.Zentral.Heizung.Pumpe() # Read the pump status
Automatik = sh.Zentral.Heizung.Automatik() # Check if the variable automatik is True
if now_time >= time(9,00) and now_time <= time(20,00):
Nacht = False;
else:
Nacht = True;
if Automatik == True and Nacht == False:
if (TWO < 40 or TWO > 60) and (TWO > HWO+5 or TWO > 70):
if Pumpe == False:
sh.Zentral.Heizung.Pumpe(True) # activate pump
elif (HWO > 50 and TWO > 45) and (TWO < 55 or TWO+5 > HWO):
if Pumpe == True:
sh.Zentral.Heizung.Pumpe(False) # deactivate pump
else:
if Pumpe == True:
sh.Zentral.Heizung.Pumpe(False) # deactivate pump
else:
if Nacht == True and Automatik == True:
if Pumpe == True:
sh.Zentral.Heizung.Pumpe(False) # deactivate pump
It does compare two temperature readings and a status of a pump and in addition a time frame and then decide whether the pump should be activated or not.
I desperately tried to do that in HA but did not succeed. I tried using the basic python implementation and I tried using templates.
This is my last template approach to try and see if it works:
template:
- binary_sensor:
- name: "Heizungsautomatik Entscheidung"
unique_id: heizungsautomatik_entscheidung
state: >
{% set two = states('sensor.28_ffd7b0821603_temperatur') | float(0) %}
{% set hwo = states('sensor.28_ffbd5b831603_temperatur') | float(0) %}
{% set pump = is_state('switch.heizung_pumpe', 'on') %}
{% if (two < 40 or two > 60) and (two > hwo + 5 or two > 70) %}
{{ pump }}
{% elif (hwo > 50 and two > 45) and (two < 55 or two + 5 > hwo) %}
{{ not pump }}
{% else %}
{{ not pump }}
{% endif %}
This will either return “on” or “off” if I look at this in a Dashboard for example. But as soon as I turn the pump on ( let’s say it wants me to turn it on) then it says to turn it off. If I would let that binary sensor decide to trigger the pump (this is what I want) then the pump would loop on and off.
Is there any chance I can do such things in HA?
For a better understanding I want to explain why I am doing this.
I have two water tanks, one is meant to be for heating the house and one is meant to be for heating the water for the faucets and shower.
There are 2 primary sources of energy, one is a wood heating and one is solar thermal energy. In summer the solar energy will overheat my one tank. This is why I start the pump to get the hot water into the other tank. And what I want to achieve is to automate this process. Otherwise I would need to manually pump the water every 30 minutes or so.
The logic was meant to monitor the faucet tank and if it gets to hot and is hotter than the other tank it should start the pump. As soon as the temperatures even out it should stop pumping to get the faucet tank hot again. And this in a loop until it is 8pm. From 8pm to 9am (at night) the solar energy will not get the water hot anyways. And the next morning, as soon as the faucet tank will get too hot again the logic is supposed to again pump.
I hope you guys can understand and might be able to help me.
Thanks in advance,
Patrick