There is a high level of ground water so in my house I cannot have “normal” cellar. So there is well isolated room on the ground level with two air connections. One take the air just from outside (called OUT), the second (called GWC) goes from 20 meter pipe buried in the ground (less then 1m deep). Air going through this pipe is getting cooled and thus making my cellar chilled. Each connecting has its own fan in the cellar and temperature sensor on the “input” side. There is also CEL temp sensor in the cellar.
I have a challenge to write an elegant automation (instead of several independent automations) based on the following assumptions:
As long as temperature in CEL is beloe 12C do nothing
With CEL temp > 12
a) if the OUT temperature is lower then CEL by 2 degrees turn ON OUT fan. In case the OUT temperature rises above this 2 degrees limit turn the fan OFF.
b) if the GWC temperature is lower then CEL by 2 degrees turn ON GWC fan. In case the GWC temperature rises above this 2 degrees limit turn the fan OFF.
At any time if the temperature in CEL drops below 12C turn the fas OFF
In case both air ways temps are OK to be turned on, the preference is for OUT
At any give time only one fan should be ON
As my adventure with HA is just beginning I believe there is nice ans elegant way to write ideally one automation to cover my case. At this point I was thinking about several automations for each “simple” case but I am not sure if they will not interfere with each other.
Any help or suggestion will be appreciated.
Technically I have NodeMCU with 3 temp sensors and 2 relay board connected.
cool.
I’d advise you to take a look at the docs to make sure your config is following the requirements (just noticed that you quote values of above/below)
Looks like you’re using Automation editor… you can make your automations shorter and learn faster/more if you do it manually (but it’s absolutely fine if you like it)
Yes, I am using Automation editor to start with and then I am editing the file sometime checking with editor how it looks and if it is OK.
Also template editor in Developer tools is very helpful.
Qute values are coming from the editor. Is it wrong ?
My dream and target is to create ONE automation for this purpose.
it seems like you don’t need to quote values for above and below but if it works, don’t bother.
could you explain why is it your dream?
UPDATE: actually, looking at your automations I can see some reasons. Well, if the separate automations work as expected, we’ll look into it.
Could you tell me why #3 and #4 use different ways to change state of the switch, is it intentional?
I believe it will be easier to troubleshoot in case something is wrong. Also if one piece of “code” is controlling behaviour of one solution it is easier to change and adjust (as opposite I can make some change in one automation, like some treshold, and then not notice that the other one there is older treshold or it does not correspond to changes made in first one.
No, not intentional. When using Automation editor initially i have used “call service” for action and then I realised I can use “Device” as action type. Is there any suggestion which one would be better ?
Yes. 12C is the target temperature I would like to have in my cellar.
So, as long as it is below 12C (it may happen in the strong winter as the room does not have any heating) I do not need to cool it down - so do nothing.
The second quote you have made refers to the same target and I wanted to explain that while any of the fan is working and temperature drops below 12C then any fan (OUT and GWC( should be off as the target has been reached.
So here’s how I see it now:
Let’s talk temperature sensors and switches for clarity.
Is it correct to say that to decide what to do we need to observe the following rules:
0. if CEL <= 12, turn off both switch.out and switch.gwc
else:
turn_OUT_on = (OUT+2) < CEL < (OUT-2)
turn_GWC_on = (GWC+2) < CEL < (GWC-2)
if turn_OUT_on is True, turn on switch.out and turn off switch.gwc
else if turn_GWC_on is True, turn on switch.gwc and turn off switch.out
else turn off both switch.out and switch.gwc
Thanks.
rule 0 confirmed.
The rest I would write slightly different:
1. turn_OUT_on = (OUT+2) < CEL
2. turn_GWC_on = (GWC+2) < CEL
3. if turn_OUT_on is True,
turn on switch.out and turn off switch.gwc
else if turn_GWC_on is True
turn on switch.gwc and turn off switch.out
else
turn off both switch.out and switch.gwc
Sorry, it seems I was not clear enough. My assumption
was related to the same condition. If OUT temperature is lower then CEL by 2 degrees turn the OUT fan ON. In case it is not lower (in my words: OUT temperature rises above this 2 degree limit) then turn the OUT fan off.
The same goes for GWC temperature and fan.
The idea is that fan should not pomp the air inside the cellar if the temperature outside (or in ground system) is higher then CEL temp - 2 degrees, as in that case cellar is not chilled any more.
Ok, now we’re clear with the algo and can discuss a code.
Are you ready to produce it now or need some help/hints?
From what I see it won’t be the most elegant automation at least because Jinja’s variables are limited by boundaries of a template and you’ll need at least 2 (to control both switches).
And you’ll probably need 2 automations - one for rule 0 and another for the rest (but I’m not sure without the actual code).
I think I would like to get some help/hints.
I have used/copied this one for controlling light:
alias: AUTO - lights
trigger:
- entity_id: binary_sensor.pir1_gospodarczy
platform: state
to: 'on'
- entity_id: binary_sensor.pir1_gospodarczy
for: 0:00:12
platform: state
to: 'off'
action:
entity_id: switch.swiatlo_gospodarczy
service_template: |-
{% if trigger.to_state.state == "on" %}
homeassistant.turn_on
{% elif trigger.to_state.state == "off" %}
homeassistant.turn_off
{% endif %}
and I like it as it is one for turning the lights on and off and also have this nice feature that the light is ON for defined time after sensor has stopped detecting movement.
OK. Great ! Had a time now to put it into automations file. Will see now, how it works.
Thank your for your help - it is for me also great learning as I love to do it on practical, live examples. Let ask few questions as the learning concerns:
I “{%” string indicating that now we are entering a programming area (in python ?) ?
What is the difference between {% , {%- and {{ ? I have tried to find it in google with little success. Maybe you can point me to good reference ?
Can this be written the way that {% is at the beginning of first line and then at the end of last line, instead of the beginning and end of each line ?