Situation:
I put together a tasmotized Wemos D1 Mini and a relay in order to control some lights.
The system is working: from the web page of the wemos I can turn it on and off.
I put the following code the configuration.yaml:
The issue:
The entry reacts well to all the changes (if I turn it off, icon goes off - if I turn it on, it goes on), BUT I can`t command it from the dashboard: as soon as I try change the status, it turns back to the previous one. What is wrong in the MQTT command?
Many thanks
The command POWER gives me the same as “power on”, while “power Toggle” turns the relay on/off according to the state of the relay. However it works only from the Tasmota web page, not from homeassistant.
Where is the mistake? In the code? In the Tasmota setup?
Hi Bluey!
Thanks…
But it doesn’t work. In this way I don’t have depicted in HA the right state of the relay and I cannot turn the moduli on/off from HA
Just a question: how do you setup the moduli in tasmota?
Here is what I did …
Ah my bad here, apologies I just realised this is on wemos D1 mini, my yaml was for a sonoff basic so will be slightly different on the config page in Tasmota due to the differing GPIO pins etc.
If you don’t specify the payload values, default values will be used (see documentation). That means the default “ON” and “OFF” messages are published to the command_topic.
I recommend you try @nickrout’s suggestion and change the command_topic to "cmnd/sonoff5/POWER"
That doesn’t surprise me. You set retain: true. The MQTT broker now stores (retains) the command topic’s message. Whenever the Wemo D1 connects to the broker, it will receive the last message published to the command topic (independently of Home Assistant).
You should purge the message from the command topic and then set retain: false. Here’s an easy way to purge a retained message:
Whenever debugging MQTT issues, I always recommend using an MQTT client to observe topic messages. You want to confirm the message is what you expect. Don’t just blindly try a thousand and one things and hope one of them works.
Use an MQTT client, like MQTT.fx or MQTT-spy or even mosquitto_sub, subscribe it to a topic, like stat/sonoff5/POWER and tele/sonoff5/POWER, and observe what is received when you turn the device on/off (using its web page).
Sorry but changing the topic’s structure isn’t a “solution”. Many people successfully use the default topic structure.
In addition, %topic% is a tasmota token (variable) and is used to customize the topic (see documentation). It’s not normally meant to be used literally.
The fact you needlessly changed the topic structure and included a tasmota variable (without actually using it as a variable) suggests you don’t have an adequate grasp of MQTT or tasmota. All you achieved was to ensure the state_topic was identical in Home Assistant and the device (don’t have to change its structure to achieve that).
I strongly caution others not to assume the reported “solution” is in fact any kind of solution at all.