Mqtt_template light state not updating consistently

Hi folks,

I’m trying to set up an mqtt_template light, and having some difficulty. I managed to get basic control of the light working - on/off works, for example. However I’ve run into some unexpected behaviour that I was hoping someone here might have some insight into.

After my custom template failed, I changed the config to almost exactly match the example one in the mqtt_template light documentation (my exact config below). I have experimented publishing state updates to the state topic using mosquitto_pub (I’m running the Mosquitto add-on for Hassio).

When I publish an on state, the HA interface updates correctly. But then if I re-publish the state with a different colour, nothing happens. In the developer tools state viewer, it still says the initial colour that the light was set to.

Publishing ‘off’ and then ‘on’ with a different colour will update the state to the correct colour.

All this means that though I can control my light fine from within HA, the state (except for on/off) gets out of sync easily).


  - platform: mqtt_template
    name: Colour lights
    command_topic: home/light/livingroom/ledarraytest/set
    state_topic: home/light/livingroom/ledarraytest/state
    state_template: "{{ value.split(',')[0] }}"
    red_template: "{{ value.split(',')[2].split('-')[0] }}"
    green_template: "{{ value.split(',')[2].split('-')[1] }}"
    blue_template: "{{ value.split(',')[2].split('-')[2] }}"
    command_on_template: "on,{{ brightness|d }},{{ red|d }}-{{ green|d }}-{{ blue|d }}"
    command_off_template: "off"

Initially I publish to the state topic:


In HA the light appears on, and blue, correctly. The logs in HA show the MQTT message received, and a state change event for the light.

If I then publish to the state topic:


The light should appear red, but stays blue. The only thing in the HA log (for which I am logging all levels from all components) is:

2017-07-19 11:00:21 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on home/light/livingroom/ledarraytest/state: on,255,255-0-0

No other log lines are printed, and the HA interface does not update.

Publishing ‘off’ correctly updates the state again.

In a previous configuration attempt, I actually did get the state to update if the brightness changed, but not if the colour changed.

Can anyone explain this behaviour? Am I doing something wrong? Is it expected? Is it a bug? Any enlightenment welcomed… thanks!

Actually, could this be a frontend issue, or something in-between? I just discovered that hitting reload to reload the frontend in the browser will make it show the correct state.

Feels like a bug to me.