Home Assistant Automation vereinfachen? (YAML)



  • Moin, ich finde die Syntax von HA teils extrem schwer überprüfbar, aber vielleicht ist das auch nur Gewöhnungssache.

    Was möchte ich?

    Es ist Winter und neben einer Tür steht ein Temperatursensor. Wenn ich die Tür öffne, wird es innen kälter (da Winter ist, und die Außentemperatur kleiner ist als die Innentemperatur). Daraufhin soll eine LED automatisch eingeschaltet werden. Danach und wenn ich die Tür wieder schließe, wird es innen nicht mehr kälter und die LED soll wieder ausgeschaltet werden.

    Vice versa, wenn es Sommer ist (die Innentemperatur ist dann kleiner und es wird wärmer, wenn die Tür geöffnet wird).

    Was ist das Problem?

    Die Automation startet bei jeder Temperaturänderung des Türsensors. Das ist so weit in Ordnung. Aber ich möchte einen Early-Stop erreichen: Wenn der Threshold gar nicht erreicht wird und die LED nicht eingeschaltet ist, dann soll auch gar nichts passieren. Und ich weiß nicht, ob es auch so etwas wie globale Automation-States gibt.

    Die LED soll eben nicht unnötig oft ein- und ausgeschaltet werden oder "angefunkt" werden, obwohl nix ist.

    alias: Dyn Temp Shift Door
    description: Automatically adjusts the sensitivity based on the temperature difference.
    triggers:
      - trigger: state
        entity_id: sensor.temp_shift_door
    actions:
      - variables:
          temp_innen_1: '{{ states(''sensor.temp_combi'') | float(24) }}'
          temp_innen_2: '{{ states(''sensor.wohnzimmer_tp357_klein_temperature'') | float(24) }}'
          temp_aussen: '{{ states(''sensor.aktuelle_wetter_temperatur'') | float(15) }}'
          temp_shift_door: '{{ states(''sensor.temp_shift_door'') | float(0) }}'
          delta: '{{ max((temp_innen_2 - temp_aussen) | abs, 4) }}'
          threshold: '{{ 0.01 + (delta * 0.005) }}'
      - choose:
          - conditions:
              - condition: template
                value_template: '{{ temp_innen_1 >= temp_aussen }}'
            sequence:
              - choose:
                  - conditions:
                      - condition: template
                        value_template: '{{ temp_shift_door < (threshold * -1) }}'
                    sequence:
                      - action: light.turn_on
                        target:
                          entity_id: light.tapo_l530_balkon
                  - conditions:
                      - condition: template
                        value_template: '{{ temp_shift_door > 0.01 }}'
                      - condition: state
                        entity_id: light.tapo_l530_balkon
                        state: 'on'
                    sequence:
                      - action: light.turn_off
                        target:
                          entity_id: light.tapo_l530_balkon
          - conditions:
              - condition: template
                value_template: '{{ temp_innen_1 < temp_aussen }}'
            sequence:
              - choose:
                  - conditions:
                      - condition: template
                        value_template: '{{ temp_shift_door > threshold }}'
                    sequence:
                      - action: light.turn_on
                        target:
                          entity_id: light.tapo_l530_balkon
                  - conditions:
                      - condition: template
                        value_template: '{{ temp_shift_door < -0.01 }}'
                      - condition: state
                        entity_id: light.tapo_l530_balkon
                        state: 'on'
                    sequence:
                      - action: light.turn_off
                        target:
                          entity_id: light.tapo_l530_balkon
    
    

    temp_combi ist ein Kombinationssensor aus allen Temperatursensoren im Raum (arithmetisches Mittel, ändert sich kaum, wenn die Tür geöffnet wird), tp357 ist der Türsensor und temp_shift_door ist die Ableitung des Türsensors.



  • Hab's übersichtlicher hinbekommen, und auch einen Fehler behoben, glaube ich:

    alias: Dyn Temp Shift Door
    description: Automatically adjusts the sensitivity based on the temperature difference.
    triggers:
      - trigger: state
        entity_id: sensor.temp_shift_door
    actions:
      - variables:
          temp_innen_1: '{{ states(''sensor.temp_combi'') | float(24) }}'
          temp_innen_2: '{{ states(''sensor.wohnzimmer_tp357_klein_temperature'') | float(24) }}'
          temp_aussen: '{{ states(''sensor.aktuelle_wetter_temperatur'') | float(15) }}'
          temp_shift_door: '{{ states(''sensor.temp_shift_door'') | float(0) }}'
          is_winter: '{{ temp_aussen < temp_innen_1 }}'
          delta: '{{ (temp_aussen - temp_innen_1) | abs }}'
          threshold: '{{ (-1.0 if is_winter else 1.0) * (0.03 + (delta * 0.005)) }}'
      - choose:
          - conditions:
              - condition: state
                entity_id: light.tapo_l530_balkon
                state: 'off'
              - condition: template
                value_template: >-
                  {{ (is_winter and temp_shift_door < threshold) or (not is_winter
                  and temp_shift_door > threshold) }}
            sequence:
              - action: light.turn_on
                target:
                  entity_id: light.tapo_l530_balkon
          - conditions:
              - condition: state
                entity_id: light.tapo_l530_balkon
                state: 'on'
              - condition: template
                value_template: >-
                  {{ (is_winter and temp_shift_door > 0.01) or (not is_winter and
                  temp_shift_door < -0.01) }}
            sequence:
              - action: light.turn_off
                target:
                  entity_id: light.tapo_l530_balkon
    
    

    temp_innen_2 braucht man, glaube ich, gar nicht, da dieser Wert ja schon in temp_shift_door ist.


Anmelden zum Antworten