Issues with heater window sensor blueprint

Hi community:

I want to create a blueprint for heating control for my Tado X heaters based on the state of the window sensors.
It should wait x seconds (default 5 seconds) after opening the window to turn off the heater. After closing the window it should also wait (default 5 min) until the room temperature has equalized itself.
In addition it should be possible to select in one automation e.g. 3 binary sensors and 2 heaters (one room) and the heaters should be turned off in case of one of the binary sensors is “on”.

This is my currently implemented code:

blueprint:
  name: Fenster offen - Heizung aus
  description: "Automatisierung, um Heizungen bei geöffneten Fenstern auszuschalten."
  domain: automation
  input:
    fenster_sensoren:
      name: Fenstersensoren
      description: "Wähle die Fenstersensoren aus."
      selector:
        entity:
          domain: binary_sensor
          multiple: true
    heizungen:
      name: Heizung(en)
      description: "Wähle die Heizungen aus."
      selector:
         entity:
           domain: climate
           multiple: true
    heizung_modus_speicher:
      name: Heizung-Modus-Speicher
      description: "Wähle eine Input Text Entität, um den Heizungsmodus zu speichern."
      selector:
         entity:
           domain: input_text
    wartezeit:
      name: Wartezeit (Fenster geöffnet)
      description: "Zeit, die gewartet wird, bevor die Heizung ausgeschaltet wird."
      default: "00:00:05"
      selector:
        text:
          type: time

mode: single

trigger:
  - platform: state
    entity_id: !input fenster_sensoren
    to: "on"

condition: []

action:
  - variables:
      fenster_sensoren: !input fenster_sensoren
      heizungen_raw: !input heizungen
      heizung_modus_speicher_raw: !input heizung_modus_speicher
      wartezeit: !input wartezeit
      heizungen_list: "{{ heizungen_raw if heizungen_raw is iterable else [heizungen_raw] }}"
      heizung_modus_speicher_list: "{{ heizung_modus_speicher_raw if heizung_modus_speicher_raw is iterable else [heizung_modus_speicher_raw] }}"

  - choose:
      - conditions:
          - condition: state
            entity_id: !input fenster_sensoren
            state: "on"
        sequence:
          - delay: "{{ wartezeit }}"
          - repeat:
              count: "{{ heizungen_list | length }}"
              sequence:
                - service: logbook.log
                  data:
                    name: "Debugging - Schleifenstart"
                    message: >
                      Aktueller Index: {{ repeat.index0 | default('undefined') }},
                      Heizungen: {{ heizungen_list | join(', ') }},
                      Modus-Speicher: {{ heizung_modus_speicher_list | join(', ') }},
                      Anzahl Heizungen: {{ heizungen_list | length }},
                      Anzahl Speicherplätze: {{ heizung_modus_speicher_list | length }}

                - choose:
                    - conditions:
                        - condition: template
                          value_template: "{{ repeat.index0 < (heizungen_list | length) }}"
                        - condition: template
                          value_template: "{{ repeat.index0 < (heizung_modus_speicher_list | length) }}"
                      sequence:
                        - service: logbook.log
                          data:
                            name: "Debugging - Vor Modus speichern"
                            message: >
                              Heizung: {{ heizungen_list[repeat.index0] | default('undefined') }},
                              Speicher: {{ heizung_modus_speicher_list[repeat.index0] | default('undefined') }},
                              Aktueller Modus der Heizung: {{ state_attr(heizungen_list[repeat.index0], 'hvac_mode') | default('off') }}

                        - service: input_text.set_value
                          target:
                            entity_id: >
                              {% if repeat.index0 < heizung_modus_speicher_list | length %}
                                {{ heizung_modus_speicher_list[repeat.index0] }}
                              {% else %}
                                input_text.invalid
                              {% endif %}
                          data:
                            value: >
                              {% if repeat.index0 < heizungen_list | length %}
                                {{ state_attr(heizungen_list[repeat.index0], 'hvac_mode') | default('off') }}
                              {% else %}
                                off
                              {% endif %}

                        - service: climate.set_hvac_mode
                          target:
                            entity_id: "{{ heizungen_list[repeat.index0] | default('climate.invalid') }}"
                          data:
                            hvac_mode: "off"

  - choose:
      - conditions:
          - condition: state
            entity_id: !input fenster_sensoren
            state: "off"
        sequence:
          - repeat:
              count: "{{ heizungen_list | length }}"
              sequence:
                - choose:
                    - conditions:
                        - condition: template
                          value_template: "{{ repeat.index0 < (heizungen_list | length) }}"
                        - condition: template
                          value_template: "{{ repeat.index0 < (heizung_modus_speicher_list | length) }}"
                      sequence:
                        - service: logbook.log
                          data:
                            name: "Debugging - Modus wiederherstellen"
                            message: >
                              Modus wird wiederhergestellt:
                              Heizung: {{ heizungen_list[repeat.index0] | default('undefined') }},
                              Speicher: {{ heizung_modus_speicher_list[repeat.index0] | default('undefined') }},
                              Gespeicherter Modus: {{ states(heizung_modus_speicher_list[repeat.index0]) | default('off') }}

                        - service: climate.set_hvac_mode
                          target:
                            entity_id: "{{ heizungen_list[repeat.index0] | default('climate.invalid') }}"
                          data:
                            hvac_mode: "{{ states(heizung_modus_speicher_list[repeat.index0]) | default('off') }}"

Could anyone help me to get this code running?

Thanks in advance and best regards!

Greetings HomeAssT1,

So the right way to write a Blueprint, (well let’s call it best practice and the method suggested in the docs), is to write an automation or script that does a simplified version of that you want first, then add the blueprint magic sauce. Getting the logic working is not always easy, and becomes obfuscated in all that variable substitution stuff, making everything frustrating.

Get what you want working with sample entities instead of inputs, then make the blueprint out of that by adding the !inputs and variables and such. Try to avoid device triggers and selectors. You can make them work, but people tend to struggle with those when dealing with them outside of the GUI editor context.

1 Like