Prevent an input number changed by MQTT publish to run its action

i’m using and input number as a timer set for my boiler:
input_number:
boiler_timer_set:
name: ‘Timer Set’
initial: 0
min: -240
max: 240
step: 15
unit_of_measurement: Minutes

using the following automation:
automation:

move status ui slider when an mqtt update received

-  id: boiler_timerstatus_change
   alias: Boiler Timer Status Setter
   initial_state: 'on'
   trigger:
     platform: mqtt
     topic: 'home/boiler/timer'
   action:
     service: input_number.set_value
     data_template:
       entity_id: input_number.boiler_timer_status
       value: "{{ trigger.payload }}"

publish message when timer setter slider is moved

-  id: boiler_timersetter_changed
   alias: Boiler Timer Set
   initial_state: 'on'
   trigger:
     platform: state
     entity_id: input_number.boiler_timer_set
   action:
     service: "mqtt.publish"
     data_template:
       topic: "home/boiler/settimer"
       retain: "false"
       payload: '{{states("input_number.boiler_timer_set") | round(0)}}' 

the mqtt device sends updates of the time left for the timer every minute and i want it to update the input number control to reflect it.

the problem is that the updates sent every minute by the device, updates the input number and this causes the input number to activate its action and publish a command to set the timer which is wrong.

is it possible to only update its value, but skip the mqtt.publish that it triggers in the case that the update did not happen from the user but from the subscription to “home/boiler/timer”?

yes, it is possible.

create an input_boolean:

input_boolean:
  boiler_status_from_mqtt_in_progress:
  initial: 'false'

and in your automations:

-  id: boiler_timerstatus_change
   alias: Boiler Timer Status Setter
   initial_state: 'on'
   trigger:
     platform: mqtt
     topic: 'home/boiler/timer'
   action:
    - service: input_boolean.turn_on
      data:
        entity_id: input_boolean.boiler_status_from_mqtt_in_progress
    - service: input_number.set_value
      data_template:
        entity_id: input_number.boiler_timer_status
        value: "{{ trigger.payload }}"
    - service: input_boolean.turn_off
      data:
        entity_id: input_boolean.boiler_status_from_mqtt_in_progress

-  id: boiler_timersetter_changed
   alias: Boiler Timer Set
   initial_state: 'on'
   trigger:
     platform: state
     entity_id: input_number.boiler_timer_set
  condition:
    condition: state
    entity_id: input_boolean.boiler_status_from_mqtt_in_progress
    state: 'false'
   action:
     service: mqtt.publish
     data_template:
       topic: "home/boiler/settimer"
       payload: '{{states("input_number.boiler_timer_set") | round(0)}}' 

I couldn’t check all that, but hope you get the idea of a simple flag.
Please let us know how it goes.

1 Like

Thanks - works like a charm :slight_smile: