Help with MQTT, sonoff with tasmota and PowerOnState command

I there, I have a similar issue with Tasmota and Sonoff Pro 4Ch. When it loses the connection and reconnect, the mqtt server send a payload with on and immidiatly off causing my garage to open randomly :confused: PowerOnState ignore setup to 0. A small work around, but I hope to find a real solution, was to setup an Automation that every 30 seconds reset the stored status on relay4

There si somethink wrong with mqtt on HassIO or on Sonoff?! I can’t figure out :frowning:

This is strange. Having the retain flag set for a the topic would explain one message when it connects, but not two with different payloads. Do you have some automation in HA that would send the second message?

Right, well… I have not tried disconnecting the PIR but that is the case when I disable it from the tasmota settints.

@krash : when you disable the PIR, the sonoff acts normally?
Meaning: Sonoff power up, light ON, Light remain ON.
Please confirm?

Also, please specify which PIR sensor you are using ?

@Tommmii This is the PIR i use: HC-SR501.
As for your other question:
When i disable the PIR, (see image), It works as you said: Sonoff power up, light ON, Light remain ON.

okay, well… could it be that the PIR is in fact ordering the Sonoff to switch off, because once the PIR has started up (+/- 3 seconds) it detects no movement ?

Or…perhaps you’re running into smt similar as Ben :

Are you referring to the conflict within wifi and the PIR sensor going crazy?
I think i am ok with that, i have placed the PIRs (kind of) far away from the module, they seem to be reporting movement pretty accurately.

My problem is only on startup.

(i do have a couple of sensors like the ones that Ben is recommending, will try them out at some point to see if it’s been a pir sensor issue)

Even if the pir detects no movement, there is no automation ordering such function.
Why would it turn off?

ok, i figured your PIR might have been right onto the Sonoff.

Your tasmota logs don’t seem to show maximum detail, have you put the Sonoff into “more debug” mode, it should display the origin of every action in the device ?
Find this in Configuration / Configure Logging / Web log level / 4 More debug

Hey, thanks for looking into it.
Im not at home right now but I have posted plenty of detailed logs, according to the the settings you propose on the tasmota issues tracker on github.
Here: How to corretly set up PowerOnState, SwitchTopic and SwitchMode with a PIR sensor ¡ Issue #1675 ¡ arendst/Tasmota ¡ GitHub

ok, went through that thread…
I would connect the PIR to another sonoff, just the pir and nothing else, to try and find out what the pir sensor is publishing.

Am also expecting a mailbag with some PIR sensors, so i will try to replicate this.

I have the same effect on two sonoffs with the same pirs connected, so I don’t think something is mulfunctioning.
(upper and lower end of a staircase)

yes, i understood that.
I 'm just trying to simplify things, to make debugging easier.
1 device with PIR, publishing a topic to mqtt broker
1 (other) device without PIR, subscribing to this topic

Then we should clearly be able to see if PIR is sending poweroff, or if mqtt is retaining poweroff, or if the lamp/sonoff is getting the poweroff from own memory.
or none of the above :confounded:

Pls here: MQTT and Tasmota problems when Disconnect/Crash

I had the same issue. After hours of “playing” with the sonoff and HA config and more googleing, this solved my problem:

https://github.com/arendst/Sonoff-Tasmota/issues/937#issuecomment-338289181

And to Save you some time on how to delete the retained messages in mqtt, go here:

Thanks a ton! I would love to try it, any idea how i can run those in the hassio docker?
I can stop and start the service from within the hassio.
When i run rm /var/lib/mosquitto/mosquitto.db from putty i get No such file or directory
Any clues?

sounds like perhaps you’re not connected to the Hass.IO console ?

When you open putty, and you connect, do you get this ascii welcome text :


  _    _                 _____ ____
 | |  | |               |_   _/ __ \
 | |__| | __ _ ___ ___    | || |  | |
 |  __  |/ _` / __/ __|   | || |  | |
 | |  | | (_| \__ \__ \_ _| || |__| |
 |_|  |_|\__,_|___/___(_)_____\____/


Our Cli:
$ hassio help

➜  ~ 

If not, then you’re not connected to the Hassio container.

Yeap, that’s the case. I need this right?

I’m not sure, I think you might need to connect to the Mosquitto container.
This is way above my paygrade…hopefully some one more knowledgeable will help.

edit :
I’ve asked on the discord app… got the usual “no reply” from the ppl present over there.
@krash you might have luck with this :