@prankousky wrote:
Hi everybody,
I am using the automation below to control my
SPZB0001
zigbee thermostats via Home Assistant depending on window statuses; the code below includes three different rooms (office, kitchen, living room).As you can see, office (“Arbeitszimmer”) and kitchen (“Küche”) are identical except for the sensors they depend on (obviously, office depends on the office window while kitchen depends on the kitchen sensor, but the rest is the same code). Then, however, there is the living room, which has multiple windows as well as multiple thermostats to set. My code there works as well, but here are my questions:
- is there some code / template I can use for all rooms (or, if not, at least all rooms except the living room? All other rooms only have one single window and one single climate entity to control)
- how can I improve this code to constantly monitor the windows? Explanation below
I also have timers for my climate entities, for example, turn office to 18.5°C at 09:00. This works fine as long as the office window is shut. However, when the office window is open at 09:00, the climate entity will still be set to 18.5°C, because the
trigger.to_state
entity in this case is notbinary_sensor.arbeitszimmer_fenster_contact
(which would be the window sensor), but ratherclimate.arbeitszimmer_heizung_climate
, as my automation triggers that entity directly (example below as well).So currently, I can successfully open or close windows, and my climate entities will act accordingly; however, when a climate entity is controlled by another automation (or manually), it will not “double-check” whether or not the corresponding window is still shut and might turn on the heat while the window is not shut.
So, my initial idea was to create an automation with
time_pattern
to check, for example, every 30 seconds whether or not any windows are open, and, if so, turn off the corresponding climate entity. HOWEVER, this would require me to write (almost) identical code for each room. So I was hoping there might be a better way to do this without so much copy and paste.All my window sensors are titled
binary_sensor.<room>_fenster_contact
and all my climate entities are titledclimate.<room>_heizung_climate
. There are three exceptions: living room (three window sensors, two climate entities) as well as both bathrooms, which are heated by infrared radiators and are therefore controlled by different automations (if temperature in bathroom1 <= valuex, turn on switch.heat_bathroom1, else turn off switch.heat_bathroom1), so those two bathrooms are not effected by this. The living room, however, ought to be included, if possible; I havebinary_sensor.wohnzimmer_vorne_fenster_contact
,binary_sensor.wohnzimmer_mitte_fenster_contact
, andbinary_sensor.wohnzimmer_strasse_fenster_contact
here (vorne, mitte, and strasse being the locations of those windows, which makes the pattern a bit different than the pattern I use for all other rooms).How can I improve this?
Thank you for your ideas
Automation to control climate entities based on window sensor
Will be triggered when window sensor state changes and regulate climate entity accordingly; works fine, but has to be hand-written for each room.
automation: # Arbeitszimmer ##################################################### - id: "heizung_az" alias: "[Heizung] AZ" trigger: - platform: state entity_id: binary_sensor.arbeitszimmer_fenster_contact action: - service: climate.set_hvac_mode data_template: entity_id: climate.arbeitszimmer_heizung_climate hvac_mode: > {% if trigger.to_state.state == "on" %} off {% elif trigger.to_state.state == "off" %} heat {% endif %} # Küche ##################################################### - id: "heizung_ku" alias: "[Heizung] KU" trigger: - platform: state entity_id: binary_sensor.kueche_fenster_contact action: - service: climate.set_hvac_mode data_template: entity_id: climate.kueche_heizung_climate hvac_mode: > {% if trigger.to_state.state == "on" %} off {% elif trigger.to_state.state == "off" %} heat {% endif %} # Wohnzimmer ##################################################### - id: "heizung_wz" alias: "[Heizung] WZ" trigger: - platform: state entity_id: binary_sensor.wohnzimmer_vorne_fenster_contact, binary_sensor.wohnzimmer_mitte_fenster_contact, binary_sensor.wohnzimmer_strasse_fenster_contact action: - service: climate.set_hvac_mode data_template: entity_id: climate.wohnzimmer_strasse_heizung_climate hvac_mode: > {% if trigger.to_state.state == "on" %} off {% elif trigger.to_state.state == "off" %} heat {% endif %} - service: climate.set_hvac_mode data_template: entity_id: climate.wohnzimmer_vorne_heizung_climate hvac_mode: > {% if trigger.to_state.state == "on" %} off {% elif trigger.to_state.state == "off" %} heat {% endif %}
Automations to control climate entities based on time (currently still turning on climate entities even when windows are open, which needs to be fixed)
This gives me input sliders so that I can individually set the temperature for each room in the morning and at night (some rooms have multiple of those, for example, kitchen will be heated at 08:00, then turned down at 10:00, heated again at 17:30, turned down again at 18:30, and turned down more at 22:15, etc. etc.; but all rooms have at least one individually setable value for morning and evening)
# Zeitsteuerung für Heizungen input_number: az_morgens: name: "AZ 08:30" initial: 18.5 <<: &input_template min: 5 max: 30 step: 0.5 icon: mdi:radiator unit_of_measurement: "°C" az_abends: name: "AZ 20:15" initial: 16.5 <<: *input_template automation: # Arbeitszimmer {{{ - id: "heizung_az_morgens" alias: "[Heizung] AZ 08:30" trigger: - platform: time at: "08:30:00" action: - service: climate.set_temperature data_template: entity_id: climate.arbeitszimmer_heizung_climate temperature: "{{ states('input_number.az_morgens') | float }}" - id: "heizung_az_abends" alias: "[Heizung] AZ 20:15" trigger: - platform: time at: "20:15:00" action: - service: climate.set_temperature data_template: entity_id: climate.arbeitszimmer_heizung_climate temperature: "{{ states('input_number.az_abends') | float }}"
Posts: 2
Participants: 2