Toggle keep switching off

I’ve just flashed a Ankuoo NEO that control a light with hfeasy that provide an MQTT Client that successfully connects to my MQTT Server. Here you can find the setup of the plug:

Server IP: 192.168.XX.XX /
Server Port: 1883
usr: username
psw: ****
sub_topic: cmnd/abatjour/POWER
pub_topic: stat/abatjour/POWER
QOS: 2
ON value: 1
OFF value: 0

Furthermore I’ve been able import that switch through MQTT to Home Assistant and even to control it. Here’s my HA setup:

  -platform: mqtt
   name: "light"
   command_topic: "cmnd/abatjour/POWER"
   state_topic: "stat/abatjour/POWER"
   qos: 2
   payload_on: "1"
   payload_off: "0"
   retain: true

The issue is that if the light it’s OFF and I toggle it ON actually it does but the switch, on HA, after few seconds switch back to OFF position whereas the light stay ON.
To switch it OFF I need to press twice the toggle, the first touch is needed to make the toggle matching the plug state and the second to send the MQTT command to turn it OFF.

Someone already came across this issue? Or can someone help me figure out the issue?

First of all, remove the “retain: true” and delete the retained message from your mqtt broker database.

Okay, I remove the line in the configuration, how can I remove it from the database?

Easiest way is to install mqtt explorer and delete the line with that.

Hi, like this?

Do you know if it’s possible to install on Raspbian and not hassio?

It is a windows program.


nice to know…

There are versions of MQTT Explorer available for Windows, Mac, Ubuntu, and Linux.

You can also purge a retained message using Developer Tools > Services > mqtt.publish

Screenshot from 2020-03-19 16-21-59

Paste the following into Service Data and click Call Service.

topic: cmnd/abatjour/POWER
payload: ''
retain: true

The payload consists of two consecutive single quotes (not one double quote). It represents an ‘empty string’.

That’s the standard behavior when the state_topic fails to receive the expected value. You turned the switch on, Home Assistant published 1 to the command_topic and then expected to receive 1 via the state_topic. It didn’t so it put the switch (in the UI) back to off.

Try this version without the lone double-quote at the start of each topic.

  -platform: mqtt
   name: light
   command_topic: cmnd/abatjour/POWER
   state_topic: stat/abatjour/POWER
   qos: 2
   payload_on: "1"
   payload_off: "0"
1 Like

I’m not sure to having properly understood how to delete the retained message…

Even with the new configuration the switch doesn’t seem to work properly.

Then you need to confirm that the state_topic is receiving a 1 when you turn the switch on.

  • Ensure the switch and the physical light are off.
  • Go to Developer Tools > MQTT > Listen to a topic
  • Enter stat/abatjour/POWER then click Start Listening
  • Go the the UI and turn on the switch.
  • Go back to Developer Tools > MQTT and see what was reported. It should indicate it received a 1. If it didn’t, or reported something else, then that’s information we need to know in order to continue debugging this problem.

it’s simple - you need to publish an empty message to that topic.

1 Like

As you imagined the MQTT do not listen anything

You have two choices now.

  1. Try to determine why the device fails to publish its state to stat/abatjour/POWER.
  2. If the device is unable to report its state, remove state_topic and use the optimistic option.
optimistic: true

the second option seems to work but now the toggle is no more a switch it is instead a double button, like:

Ideas for the first option?

You will have to ask the author of hfeasy why no status is reported.

1 Like

I have had this problem trying to test the MQTT in python. I had to set the state from the client with:

# callback for received messages
def on_message(client, userdata, msg):
    if msg.topic == "homeassistant/switch/myswitch/set" :
        print("SWITCH is being set to " + str(msg.payload))
        data = msg.payload
        client.publish(switchstatetopic, data)

Also, I had to delete as already mentioned the old states using MQTT EXplorer as mentioned.