I would like to create an automation for the winter that tells me “intelligently” when to close my windows.
This should take into account both temperature and humidity.
The idea is that I close the window when the temperature in the room has dropped more than 2°C or the humidity outside is higher than in the room. I have already calculated the absolute humidity needed for this.
For the implementation I have temperature and humidity sensor and a window sensors.
I use the current version HA 2022.10.3.
I created the automation this morning. Unfortunately I have the problem that it shows me the following error message during the template test: “In ‘template’ condition: UndefinedError: ‘trigger’ is undefined”.
I have already tried around a bit, but can’t find the error.
The automation looks like this for me.
alias: 99-99 Test Automation
description: ""
trigger:
- platform: state
entity_id:
- sensor.temperatursensor_buro
to: "null"
id: buro
- platform: state
entity_id:
- sensor.humidity_draussen
to: "null"
id: humidity
condition:
- condition: state
entity_id: binary_sensor.fenstersensor_buero
state: "on"
- condition: template
value_template: |-
{% if trigger.id == buro %}
{{ diff > 2 }}
{% else %}
{{ out > in }}
{% endif %}
action:
- service: notify.mobile_app_pixel_6_pro
data:
message: |-
Please close the window.
{% if trigger.id == 'buro' %}
The temperature has dropped by {{ diff }}°
{% else %}
The humidity has risen by {{ out - in }}%
{% endif %}
enabled: true
variables:
diff: >-
{{ trigger.from_state.state |float(0) - trigger.to_state.state |float(0)
}}
out: "{{ states('binary.sensor.absolute_humidity_draussen') |float(0) }}"
in: "{{ states('binary.sensor.absolute_humidity_buro') |float(0) }}"
mode: parallel
Independent from the needed automation, I think it might be worth looking into the additional calculation of the dew point. Just comparing humidity without taking the temperature of the air that humidity is measured in does not create a fully reliable picture of the situation.
Just in case you are German or can understand it: the German version of make magazine had a nice article about it, including the needed formulas etc:
Do you have a similar automation? If so, how do you do it?
I was going to look at the Heise article, but would need to sign up for it. Unfortunately, I don’t have an account for that.
Thank you for your example.
I have some questions.
Isn’t it better to use the window contact to call the service to start an automation and run that startet automation in a loop, until the window contact state change to close?
If i understand it correct, the {{ diff > 2 }} calculation means, the temp must drop by 2 celsius on each temperature change.
But my temp sensor triggers the automation on smaller temp changes.
The temp diff should be calculated from the start of window opening.
So the initial temp must be save.
Hope it’s understandable.