Restore previous clima preset_mode

Hello there,
I would like to store the current clima preset_mode when a window is opened, to come back to the stored state, when it is closed again.
Can anybody help me with this code? I couldn’t find a helping post for that till now.
Errormessage: “None is not a valid HVACOperationMode”
Thanks in advance.

        alias: HeatBrake_On_EG_Wz
        description: Heizung aus mit Fensterkontakt
        trigger:
          - platform: state
            entity_id:
              - binary_sensor.00171be9a55fe0_1_state
            to: "on"
        condition:
          - condition: numeric_state
            entity_id: sensor.00181a49904536_actual_temperature
            below: 18
        action:
          - variables:
              last_heat_mode_wz = state_attr('climate.eg_wohnzimmer','preset_mode'): null
          - service: climate.set_preset_mode
            data:
              preset_mode: eco
            target:
              entity_id: climate.eg_wohnzimmer
          - wait_for_trigger:
              - platform: state
                entity_id:
                  - binary_sensor.00171be9a55fe0_1_state
                to: "off"
            continue_on_timeout: false
          - service: climate.set_preset_mode
            data:
              preset_mode: states('last_heat_mode_wz')
            target:
              entity_id: climate.eg_wohnzimmer
        mode: single
          - variables:
              last_heat_mode_wz: "{{ state_attr('climate.eg_wohnzimmer', 'preset_mode') }}"
          - service: climate.set_preset_mode
            data:
              preset_mode: "{{ last_heat_mode_wz }}"
            target:
              entity_id: climate.eg_wohnzimmer

Hello Taras,
thanks a lot. That works fine! :slight_smile:

1 Like