Emulated Hue: Switch Climate between heat/cool

My heater is integrated in HA via BSB-Lan and a climate-template.
So I have 4 states for it: off - cool - heat - auto
(cool is for the reduced temperature at night)

I want to switch it between cool and heat via Alexa.
So my Idea was to make a input_boolean helper which is mapped via emulated hue to Alexa.
This mapping works fine.
The next Idea was to create an automation to switch the climate-mode according to this helper:

alias: Alexa_Heizung
description: ""
trigger:
  - platform: state
    entity_id:
      - input_boolean.alexa_heizung
    from: "off"
    to: "on"
  - platform: state
    entity_id:
      - input_boolean.alexa_heizung
    from: "on"
    to: "off"
condition:
  - condition: and
    conditions:
      - condition: template
        value_template: >-
          {{ as_timestamp(now()) -
          as_timestamp(states.sensor.uptime.last_changed) |
                int > 30 }}
        alias: Vermeide Auslösen bei Neustart
      - condition: not
        conditions:
          - condition: state
            entity_id: climate.heizung_bsb_lan_heizungstherme
            state: "off"
        alias: Heizung ist nicht AUS (Sommerbetrieb)
action:
  - if:
      - condition: state
        entity_id: input_boolean.alexa_heizung
        state: "on"
    then:
      - service: climate.set_hvac_mode
        metadata: {}
        data:
          hvac_mode: heat
        target:
          entity_id: climate.heizung_bsb_lan_heizungstherme
    else:
      - if:
          - condition: state
            entity_id: input_boolean.alexa_heizung
            state: "off"
        then:
          - service: climate.set_hvac_mode
            metadata: {}
            data:
              hvac_mode: cool
            target:
              entity_id: climate.heizung_bsb_lan_heizungstherme
mode: single

This also does it’s job.

Now I’m thinking about “how to track the helper when the climate-mode is changed via HA-frontend or thermostat?”
My first idea was to make a second automation which is triggered by the change of climate-state-mode and will switch the helper to “on” if “climate.heizung_bsb_lan_heizungstherme” is “heat” and will switch it off, if the state is “cool”.

I’m sure this will work, even it will trigger the first automation and send the corresponding command a second time
e.g.:

  1. switch the heater to “heat” by thermostat
  2. heater will change it’s state to “heat”
  3. helper “input_boolean.alexa_heizung” will be switched to “on”
  4. the first automation will recognize the change of the helper and will send a second command “heat” to the heater.

not very nice but it will work.

Does anyone have a more elegant idea of how to avoid the second triggering or how to build the whole thing differently?

I solved it with a template-switch:

switch:
  - platform: template
    switches:
      alexa_heizung:
        friendly_name: Alexa Heizung
        unique_id: "alexa_heizung"
        value_template: "{{ is_state('select.heizung_bsb_lan_betriebsart',['Komfort','Automatik']) }}"
        turn_on:
          service: select.select_option
          target:
            entity_id: select.heizung_bsb_lan_betriebsart
          data:
            option: Komfort
        turn_off:
          - condition: not
            conditions:
              - condition: state
                entity_id: select.heizung_bsb_lan_betriebsart
                state: "Schutzbetrieb"
          - service: select.select_option
            target:
              entity_id: select.heizung_bsb_lan_betriebsart
            data:
              option: Reduziert