Entity state not changed by MQTT message?

Hi folks,

I’m just started with a docker image of home assistant to check if a change from OpenHab2 to HA would made the things easier :wink:

As a MQTT broker, I use mosquitto version 1.3.4 (build date 2018-09-28 22:21:32+0000) on a different host.

In the configuration.yaml, I have added the following:

mqtt:
  broker: 192.168.192.235
  port: 1883
  client_id: home-assistant
  discovery: false

switch:
  - platform: mqtt
    name: "buero licht"
    state_topic: "homenet/touch01/stat/POWER"
    command_topic: "homenet/touch01/cmnd/POWER"
    retain: true
    payload_on: "ON"
    payload_off: "OFF"
    state_on: "ON"
    state_off: "OFF"
    optimistic: false
    qos: 0
  - platform: mqtt
    name: "buero led"
    state_topic: "homenet/led01/stat/POWER"
    command_topic: "homenet/led01/cmnd/POWER"
    retain: true
    payload_on: "ON"
    payload_off: "OFF"
    state_on: "ON"
    state_off: "OFF"
    optimistic: false
    qos: 0

group:
  Buero:
    view: true
    entities:
      - switch.buero_licht
      - switch.buero_led


logger:
  default: debug
  logs:
    homeassistant.components.mqtt: debug
    homeassistant.components.websocket_api: info

With this configuration, I’m able to switch the lights on. But it seems, that the state send back from the mqtt broker will not used by HA?

In my log, I could read the following:

  1. I trigger the switch manually on:
    2019-03-25 09:20:52 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on /homenet/led01/stat/POWER: b'ON'
    The message is received by HA, but the state of the switch in the UI of HA is not changed?

  2. I trigger the switch manually off:
    2019-03-25 09:20:55 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on /homenet/led01/stat/POWER: b'OFF'

  3. I use the UI of HA to switch the light on:
    2019-03-25 09:21:01 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=switch, service=turn_on, service_data=entity_id=switch.buero_led>
    2019-03-25 09:21:01 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=mqtt, service=publish, service_data=topic=homenet/led01/cmnd/POWER, qos=0, retain=True, payload=ON>
    2019-03-25 09:21:01 DEBUG (MainThread) [homeassistant.components.mqtt] Transmitting message on homenet/led01/cmnd/POWER: ON
    2019-03-25 09:21:01 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on /homenet/led01/stat/POWER: b’ON’
    The light is going on, but after a second the switch in th UI of HA changes from ON to off but he light keeps on???

Any idea whats going wrong in my installation?

Thanks in advance
Joerg

Is it still connected to OpenHAB as well? Could it be sending a retained message or something like that?

Both lights are connected to the mosquitto mqtt broker. HA and openHAB are connected to this broker also.

In the logs you could see that the right status message is received by HA - only the internal state change of the entity is missing?

I’ve never seen a payload reported this way:
b'ON'

I searched for an answer and learned that the leading b is python’s way of indicating it’s a “bytes” object.

See these posts for more details:

I believe that’s why the payload fails to match this:
payload_on: "ON"

What kind of light is publishing to homenet/led01/stat/POWER? Do you have control over how it reports its state?