MQTT State problem with HA - the switch wont toggle! <solved>

Hello,
I’ve been playig around on this for a couple of days, and read many posts, I have rewritten the code in espeasy many times and now using MQTT.fx for testing without any luck.

I have an issue with configuring the state topic in HA - Ha seems to subscribe to the state_topic, but dosnt do anything when i send values to it.

I am running version 61.1 (updated 21/01/2017) the issue i have has existed since 60.0.
I’m running mosquito on the same HA machine.

I have in created debug logging in HA and added the logging below.
I can turn on the switch using HA, then after a couple of seconds the switch returns to its original position ( I think this is an indication that the “state” is not working)

my birth and LWT messages do work.
However when i set “optimistic” to “false” i expect the state_topic to control the switch position when receiving updates?

I can see the messages do reach HA, but HA does not toggle the switch?

2018-01-21 14:24:58 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on /esp11/status: Connected
2018-01-21 14:25:04 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on /esp11/relay/Switch: on
2018-01-21 14:25:04 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on /esp11/relay/Switch: 0
2018-01-21 14:25:10 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on /esp11/relay/Switch: 1
2018-01-21 14:25:22 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on /esp11/relay/Switch: 1.0
2018-01-21 14:25:35 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on /esp11/relay/Switch: "1.0"
2018-01-21 14:25:44 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on /esp11/relay/Switch: "1"
2018-01-21 14:25:54 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on /esp11/relay/Switch: 1
2018-01-21 14:26:50 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on /esp11/relay/Switch: 0
2018-01-21 14:26:59 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on /esp11/relay/Switch: 1

Here is my switch configuration:

  • platform: mqtt
    name: “Recycle Fountain”
    state_topic: “/esp11/relay/Switch”
    command_topic: “/esp11/gpio/12”
    payload_on: “1”
    payload_off: “0”
    availability_topic: “/esp11/status”
    payload_available: “Connected”
    payload_not_available: “Connection Lost”
    optimistic: false
    qos: 0
    retain: false
    value_template: ‘{{ value.x }}’

How is it possible that HA receives the MQTT message, the message matches the state_topic and yet the switch doesn’t toggle? - im pretty new to HA so maybe I misunderstand what the state topic does?

any help much appreciated.
NZcam

To simplify things while fault finding, comment out the payload_available / not_available and value_template lines, and can you post a screenshot of your ESPEasy Devices page and also rules page if your using that

Hi @jivesinger
Thanks for the help. I have removed anything to do with Birth and LWT in HA config as well as the value template. The problem persists.
i can confirm that HA receives the MQTT message.

If I send an MQTT message with the payload 1 or “1” to the state topic using MQTT.fx, would you expect the button to toggle in HA?

Here are the rules

on button#Switch do
if [button#Switch]=0
  gpio,12,0
else
  gpio,12,1
endif
endon

Here is the device setup



Thanks in advance.

NZcam

I would.

I have a very similar setup at home and will confirm later this evening.

Im having similar issues after finally getting round to a clean install from 0.38 (which i had no problems with)

I have 3 ESPEasy devices 2 8 way relay boards and a sonoff with ESPeasy.

The sonoff sits there happily with expected uptime in the ESP logs.
The 2 ESP Relay baords keep getting connection to broker lost/connected to broker. The switch behaviour in HA is identical i think to what you are seeing. However they worked flawlessly on 0.38

When i tried hassbian-config install mosquitto, i get an error with the sources list, this is also the same using apt-get update. Coould it be an underlying problem with the mosquitto install??

Thanks

Hmm.

So I saw what I expected. HA toggled when I sent a state change from MQTTLens.

Can you please repost your config for ‘Recycle Fountain’ using the code tags above ‘</>’ to keep the formatting :slight_smile:

Here it is …

- platform: mqtt
  name: "Recycle Fountain"
  state_topic: "/esp11/relay/Switch"
  command_topic: "/esp11/gpio/12"
  payload_on: "1"
  payload_off: "0"
  #  availability_topic: "/esp11/status"
  #  payload_available: "Connected"
  #  payload_not_available: "Connection Lost"
  #  optimistic: true
  qos: 0
  retain: false

i can confirm that it is now working. I’ll leave the value_template commented out as it seems to be the problem, re-enabled the avalability_topic and related payloads and its all working fine.

Thank you very much.

NZcam