There is a delay between publishing to an MQTT topic and the topic being updated... Help?

Hello,

I am trying to create an automation that will allow me to increase the animation speed of an LED strip I have. The LED strip is controlled by MQTT, and the animation speed is controlled by sending the payload { “transition”: [int from 0 to 150] } to the topic the LED strip subscribes to (led/desk/set).

The LED strip does not store the transition variable in it’s topic. It just stores information about state, brightness, and effect. So, I created a new MQTT topic (led/one_animation_speed) to store a transition value that is persistent. When I press a button on my Lutron Pico Remote an automation increments/decreases the value in led/one_animation_speed. It then publishes the value of the MQTT topic, which is setup as a sensor (sensor.led_strip_1_anm_speed) to the MQTT topic the LED strip subscribes to (led/desk/set).

However, the MQTT publish to the LED strip topic is always one update behind the automation. It’s as if there’s a delay between the animation speed MQTT topic update and the LED strip topic update. Any ideas?

# Increase animation speed
- alias: Increase LED strip animation speed
  trigger:
    platform: state
    entity_id: sensor.main_lights_remote_1
    to: '8'
  condition:
    condition: template
    value_template: "{{ is_state('sensor.pico_mid_button_pressed', '1') }}"
  action:
    - service: mqtt.publish
      data_template:
        topic: 'led/one_animation_speed'
        payload: "{{ [150, states('sensor.led_strip_1_anm_spd')|int(0) + 25]|min }}"
    - service: mqtt.publish
      data_template:
        topic: 'led/desk/set'
        payload: "{\"transition\":{{ states('sensor.led_strip_1_anm_spd')|int(0) }}}"

I can only tell you that everything in HA and MQTT works as expected, and im looking on milliseconds. :wink:
https://github.com/home-assistant/home-assistant/issues/12716

Please post the configuration for sensor.led_strip_1_anm_spd. Is it subscribed to led/one_animation_speed?