Another issue with sync between input_select and MQTT

Hi. I’ve managed to partially fix my sync between input_select and MQTT.

  - alias: Set Central Heating Temporary Mode
    initial_state: on
    trigger:
      - platform: state
        entity_id: input_select.central_heating_temporary_mode
    action:
      - service: mqtt.publish
        data_template:
          topic: "ebusd/f47/Hc1SFMode/set"
          payload: >
            {% set tpmode = {
              'None': 'none',
              'Day away': 'onedayholiday',
              'Day in': 'onedaybankholiday',
              'Party': 'party' } %}
            {{ tpmode.get(trigger.to_state.state,'none') }}

  - alias: Get Central Heating Temporary Mode
    initial_state: on
    trigger:
      - platform: mqtt
        topic: "ebusd/f47/Hc1SFMode"
    action:
      service: input_select.select_option
      data_template:
        entity_id: input_select.central_heating_temporary_mode
        option: >
          {% set tpmode = {
            'none': 'None',
            'onedayholiday': 'Day away',
            'onedaybankholiday': 'Day in',
            'party': 'Party' } %}
          {{ tpmode.get('trigger.payload','None') }}

Technically this is working fine, but when I change the input_select in HA, as soon as ithe message is sent to ebusd/f47/Hc1SFMode/set, “Get Central Heating Temporary Mode” automation is triggered with the old value (why? ebusd/f47/Hc1SFMode/ has not changed yet), input_select is changed back to the original value, and “Set Central Heating Temporary Mode” is triggered again sending the original value to ebusd/f47/Hc1SFMode/set. So while i can see the topics changing on MQTT side, its almost instantly changed back.

If i disable “Get Central Heating Temporary Mode” automation, then “Set Central Heating Temporary Mode” works fine and changes ebusd/f47/Hc1SFMode correctly.

Im using similar automations with input_numbers and they work perfectly fine and im not sure why input_select behaves differently:

  - alias: Set Central Heating Heat Curve
    initial_state: on
    trigger:
      - platform: state
        entity_id: input_number.central_heating_heat_curve
    action:
      service: mqtt.publish
      data_template:
        topic: "ebusd/f47/Hc1HeatCurve/set"
        payload: "{{ states.input_number.central_heating_heat_curve.state | float }}"

  - alias: Get Central Heating Heat Curve
    initial_state: on
    trigger:
      - platform: mqtt
        topic: "ebusd/f47/Hc1HeatCurve"
    action:
      service: input_number.set_value
      data_template:
        entity_id: input_number.central_heating_heat_curve
        value: "{{ trigger.payload | float }}"

Try :


  - alias: Set Central Heating Heat Curve
    initial_state: on
    trigger:
      - platform: state
        entity_id: input_number.central_heating_heat_curve
    action:
    - service: automation.turn_off
      entity_id: automation.get_central_heating_heat_curve
    - service: mqtt.publish
      data_template:
        topic: "ebusd/f47/Hc1HeatCurve/set"
        payload: "{{ states.input_number.central_heating_heat_curve.state | float }}"
    - delay: 00:00:10
    - service: automation.turn_on
      entity_id: automation.get_central_heating_heat_curve


1 Like

Many thanks. That looks like a good workaround.
I still dont understand why same thing works with input_numbers and but behaves differently with input_select. Can it be a bug in HA?

Using input_select with mqtt, you need to make sure you don’t get a loop. I don’t think it is a bug.