Input_number slider MQTT, Stuck in a loop

I am using the template below

I am using it a progress bar (playing a video from 0-100%)

I have an MQTT updating progress of the video.

I want to use the slider to jump to a “percentage”

The problem is, when the MQTT message updates the number the, automation sends that number out via MQTT (on the same topic i want to control it with) so i get stuck in a loop.

i only want to send the MQTT message when I adjust the slider on UI, not on every update.

# Example configuration.yaml entry using 'input_number' in an action in an automation
input_number:
  target_temp:
    name: Target Heater Temperature Slider
    min: 1
    max: 30
    step: 1
    unit_of_measurement: step
    icon: mdi:target

# This automation script runs when a value is received via MQTT on retained topic: setTemperature
# It sets the value slider on the GUI. This slides also had its own automation when the value is changed.
automation:
  - alias: Set temp slider
    trigger:
      platform: mqtt
      topic: 'setTemperature'
    action:
      service: input_number.set_value
      data_template:
        entity_id: input_number.target_temp
        value: "{{ trigger.payload }}"

# This second automation script runs when the target temperature slider is moved.
# It publishes its value to the same MQTT topic it is also subscribed to.
  - alias: Temp slider moved
    trigger:
      platform: state
      entity_id: input_number.target_temp
    action:
      service: mqtt.publish
      data_template:
        topic: 'setTemperature'
        retain: true
        payload: "{{ states('input_number.target_temp') | int }}"

Try this version of ‘Set temp slider’.

  - alias: Set temp slider
    trigger:
      platform: mqtt
      topic: 'setTemperature'
    condition:
      condition: template
      value_template: "{{ trigger.payload | int != states('input_number.target_temp') | int }}"
    action:
      service: input_number.set_value
      data_template:
        entity_id: input_number.target_temp
        value: "{{ trigger.payload }}"

It contains a Template Condition that checks if the received payload’s value is different from the input_number’s current value. If the two values are identical, it won’t execute the action (i.e. it won’t call the input_number.set_value service).