Input_number changed state automation only on manual change

Is there a possibility to change the automation for input_number on a changed state to only trigger if input_number has been changed manually, not by an automation?

My problem is this:
I use an input_number component to set a temperature. I have an automation that publishes this value to e.g. “temp/set” in the event that input_number has been changed. My device then receives this value and publishes the temp to the topic “temp”. My other automation changes the state of input_number to the value received on the topic “temp”.
Works perfectly and shows the current value even if it is changed by another device etc.
But if an other devices changes the temp published to “temp”, my automation correctly changes the state of input_number. This however triggers the other automation which publishes the changed state to “temp/set”.
This results in always getting duplicate temp change requests on MQTT.
Is there a way to prevent the automation from being triggered, if the state change was made by another automation and by me using the frontend?

Here’s my configuration and automation:

    name: Heater Target Temperature
    min: 16
    max: 30
    step: 0.25
    unit_of_measurement: °C  


- alias: Temp slider moved
    platform: state
    entity_id: input_number.heater_target_temp
    service: mqtt.publish
      topic: home/9cc5b900/heater/temp/set
      retain: false
      payload: '{{ states.input_number.heater_target_temp.state | float }}'
- alias: Temp slider mqtt
    platform: mqtt
    topic: home/9cc5b900/heater/temp
    service: input_number.set_value
      entity_id: input_number.heater_target_temp
      value: "{{ trigger.payload }}"

Thanks a lot for any help.

Is it possible for your other devices to change the input_number (using service: input_number.set_value ) rather than publishing to the mqtt topic?

I guess not as they are devices connected by mqtt just publishing to their topics, completely independent to homeassistant.

You could create another mqqt topic and sensor called automatic_change. Your other devices would publish a set/active value to this topic before publishing to the temp topic.
Your slider moved automation could use the state of the automatic_change sensor as a condition. You would also have to publish a reset value to automatic_change topic in this automation.

yeah that would work but to be honest, I’d like to make homeassistant work as I expect it to work, not make a huge workaround on all my devices to achieve expected behaviour.

Do it the other way round then. Use the extra topic for the manual change.

Not for nothing, but @tom_l’s solution isn’t really a work around. This is how home assistant has always worked. People without MQTT usually have to make an input_boolean and flag it when the automation is executing. Coding is however you can make it work, it’s never really a work around. And in every feedback loop case, this is always a problem with every code->device, and device->code platform. I run into this at work daily.

@kevinkk52 does have a point though. Much easier to add an extra flag for the home assistant side automation rather than having to re-flash all his remote devices.

The extra topic configuration seems like quite a big workaround…
In the 0.76 announcement I don’t really see how that helps me.

So obviously there is no real possibility yet. Would it be possible to disable the 2nd automation in the execution of the 1st and with a delay reactivate the 2nd automation so that it would not be triggered?

I think you could get rid of the feedback loop if you just add an if statement to check the value of heater before setting it.

So just modify both your automations have this condition (after you add the mqtt topic as a sensor):

  - condition: template
    value_template: "{{ states('sensor.heater') != states('input_number.heater_target_temp') }}"

first pass, they won’t be equal, it will execute.

Second pass, they will be equal and won’t execute.


That’s perfect! Thanks a lot, did not think about that. Now it does not retrigger itself if another device changes the number. I had the sensor to that topic added already but did not think about that condition.
Adding that condition works perfectly:

    condition: template
    value_template: "{{ states('sensor.heater_target_temp') | float != states('input_number.heater_target_temp') | float }}"
1 Like