Duplicate MQTT messages

Hi All, I run a unipi (PLC based device) and wrote a script on that to accept MQTT messages. That used to work fine, but since 0.92.2 I get duplicate messages on a specific topic.

When use the config below and set the brightness that specific topic is send twice to the MQTT broker. Somehow paho mqtt crashes when I handle those messages so fast after each other.

Changing the switch to send a MQTT message with “ON” or with a delay in brightness does not send the message twice.

This might be an issues with my config in HASSIO, as templates are not my expertise, but please advise.

Config in HASSIO:

      schema: template
      name: "Bijkeuken light"
      state_topic: "homeassistant/bgg/bijkeuken/licht"
      command_topic: "homeassistant/bgg/bijkeuken/licht/set"
      availability_topic: "homeassistant/bgg/bijkeuken/licht/available"
      payload_available: "online"
      payload_not_available: "offline"
      brightness_state_topic: "homeassistant/bgg/bijkeuken/licht/brightness"
      command_on_template: >
        {"state": "on"
        , "circuit": "2_03"
        , "dev": "analogoutput"
        {%- if brightness is defined -%}
        , "brightness": {{ brightness }}
        {%- elif brightness is undefined -%}
        , "brightness": 100
        {%- endif -%}
        {%- if transition is defined -%}
        , "transition": {{ transition }}
        {%- endif -%}
        }
      command_off_template: '{"state": "off", "circuit": "2_03", "dev": "analogoutput"}'
      state_template: '{{ value_json.state }}'
      #brightness_template: '{{ value_json.brightness }}'
      brightness_template: '{{ brightness }}'
      qos: 0

The topics I see passing by on the MQTT server are;

topic; homeassistant/bgg/bijkeuken/licht/set
message; {"state": "on" , "circuit": "2_03" , "dev": "analogoutput", "brightness": 163}

This is the expected message, just twice. If I remove the brightness_template line I can no longer set brightness from the GUI, just on and off.

It’s probably something in the above config, can someone help me out here?

1 Like