Wemos D1 mini switching on by itself

So I have a wemos d1 mini with tasmota 6.4.1 and WS2812B leds. It sometimes turns on by itself, usually once every hour or so, which is unacceptable at night. It seems to happen when it reconnects to mqtt. My guess is that it has something to do with retain messages, but I really don’t know the correct configuration. Here is the log of wemos when it turns on by itself:

> 12:48:28 MQT: Attempting connection...
> 12:48:28 MQT: Connect failed to ip.of.my.mqtt:1883, rc -2. Retry in 10 sec
> 12:48:28 WIF: Connecting to AP1 my-wifi-name in mode 11N as Led Controller...
> 12:48:35 WIF: Connected
> 12:48:35 DNS: Initialized
> 12:48:46 MQT: Attempting connection...
> 12:48:46 MQT: Connected
> 12:48:46 MQT: tele/Couch_light/LWT = Online (retained)
> 12:48:46 MQT: cmnd/Couch_light/POWER = 
> 12:48:46 MQT: stat/Couch_light/RESULT = {"Command":"Unknown"}
> 12:48:46 MQT: stat/Couch_light/RESULT = {"Dimmer":13}
> 12:48:46 MQT: stat/Couch_light/RESULT = {"POWER":"OFF"}
> 12:48:46 MQT: stat/Couch_light/POWER = OFF (retained)
> 12:48:46 MQT: stat/Couch_light/RESULT = {"POWER":"ON","Dimmer":13,"Color":"33,33,33","HSBColor":"0,0,13","Channel":[12,12,12]}
> 12:48:46 MQT: stat/Couch_light/RESULT = {"Command":"Unknown"}

The retain config in tasmota is :
buttonretain -off
switchretain -off
powerretain -on

This is how i configured it in config.yaml

light:
  - platform: mqtt
    name: "Couch light"
    command_topic: "cmnd/Couch_light/power"
    state_topic: "stat/Couch_light/POWER"
    rgb_state_topic: "stat/Couch_light/color"
    rgb_command_topic: "cmnd/Couch_light/color"
    brightness_pct_state_topic: "stat/Couch_light/dimmer"
    brightness_pct_command_topic: "cmnd/Couch_light/dimmer"
    retain: true

The led strip is just a single device connected to that wemos, it’s connected to D4(GPIO2).
Thanks for any help!

It’s the retain:true in your config. It should be false.

Thank you, I’ve changed it to see, whether it makes a difference

Make sure the last values that were retained were off.

I believe why this is happening is that the wemos is rebooting. I’ve been playing with the Wemos and both Tasmota and esphomeyaml and I have noticed that the tasmota (6.4.0 in my case) will spontaneously reboot several times a day.

I think your issue is the pin you’re using. D4 on the Wemos boards is also connected to the built-in LED. When Tasmota boots, it flashes that LED to show WiFi connection status. That can send unintended “on” to some/all of the LEDs in your strips. I bet that LED is on constantly when your strip is on too…

Switch to another pin (I use D2 for one of my LED strips).

Thanks for your reply.
The built-in LED is on all the time when wemos is powered, but this seems an interesting observation, i’ll propably resolder it tommorow, if the suggestion by PeteCondliffe won’t help.

It’s definitely the pin, trust me, I’ve had the same issue. The reason the LED is on all the time is the wemos is using that pin to communicate with the strip.

This will also solve the LED being on all the time (it shouldn’t be - it’s supposed to turn off once connected to WiFi).

Separate question is why your wemos constantly lose the wifi connection (it’s not rebooting of wemos - check uptime…) Tasmota 6.4.x OTA firmare is on Core 2.4.2 when Tasmota 6.3.0 and before is on 2.3.0. When you do upgrade OTA to core 2.4.2 sometimes something is going wrong. You have to back to core version 2.3.0 or flash it again by serial console. It’s known issue. Check Tasmota forum.

Yeah, it restarted again, i’ll have to resolder it.

yeah, it’s losing connection. But to be fair i have it pretty far from the router. it was flashed with esptool and via a usb cable to this current (6.4.x) firmware. I am not really a fan of ota methods.

Sorry i was in a rush before so didn’t explain to well. It could be rebooting due to wifi connectivity i’ve got a couple of Sonoff Basics that do that due to wifi range but they don’t cause me any real issue. Not sure about the LED thing but either way the retain: true in HA config will certainly be having a negative impact on the issue.

With retain: true in HA config when the D1 is turned on/off from HA the MQTT message will be saved on the MQTT broker so when the D1 reboots and reports back in it sees the MQTT message that says it should be on or off so it turns on or off.

On the other hand you want HA to know the state of the device when it is rebooted so you set tasmota PowerRetain On so when the D1’s power state is changed it publishes a message to the MQTT broker that’s saved. This allows 1) when HA restarts it knows the device state. 2) If the D1 restarts the MQTT message will always be the state it is currently in so it wont turn on/off.

But wouldn’t it be pointless to set powerretain to on when retain is off at the broker side(hassio)?

Rule of thumb is:

  • Use retain=false for command topics.
  • Use retain=true for state topics.

Home Assistant commands the device (Wemos D1 Mini) so its (command topic) message should not be retained by the MQTT Broker (i.e. set retain: false).

The device reports its state to its (state topic) message should be retained by the MQTT Broker (i.e. PowerRetain on). Tasmota MQTT features.

1 Like

I really recommend you try with Core 2.5. For me and many others it’s much more stable in wifi and mqtt connection. http://thehackbox.org/tasmota/020500/

Hey guys, thanks for all your replies. So i resoldered the whole led strip to another pin and the ghost switching stopped, BUT, now the wemos dims and brightens the light by itself…i have no idea why.

No because when HA restarts and connects to the MQTT broker it has no state for the given switch therefore it will default to off

Ok , so i’ve figured it out. I followed this video tutorial : https://www.youtube.com/watch?v=31IyfM1gygo. Then i reinstalled mosquitto mqtt completely, to make sure no retain messages were stuck somewhere and it worked! thank you all for your help!