Help with MQTT, sonoff with tasmota and PowerOnState command

There is no evidence of retain flag being set in the messages in the dump.

Sorry I missed some of the things you wrote.
It doesn’t seem like the PowerRetain is the problem, as I said before.

I don’t quite know why it’s not working :frowning:

That sounds interesting, although last time i tried my HA couldnt detect the switches.
Will the sensors keep working if i emulate Hue or WeMo?

If possible would you be able to keep your sonoff powered on all the time or is there a reason to have the main power for the sonoff controlled by the switch?

This is the desired usage, but untill my (senior) parents get used to the motion detection, they automatically hit the switches. So i want this option available too: they hit the switch once, it wont switch on, they hit it twice, it turns and stays on :slight_smile:

Ok, I wasnt sure if this would work for you. Instead of the main power to the sonoff being controlled by the switch the switch is tied to a GPIO on the sonoff which can control the Relay on the sonoff to. I think you would get the same effect but with out your Sonoff loosing power which I believe will take care of the problem with the sonoff reading the last state from the MQTT Broker. I found that issue with my sonoffs that if the light was on and the sonoff lost power that it would turn off after a few seconds of regaining power and booting backup.

There is also this 3 way option too. I know you mentioned you had 2 lights and 2 switches. Im not sure if it is already wired in a 3 way or not but either way you could keep it that way with this or you could make your single wall switches and lights work as a 3 way.

Thanx for the input but, these do not apply in my country’s/house’s wiring standards. They require a neutral cable at the point of the switch to operate and my house is not wired that way. Thanks for the input though

Even with MQTT completely disabled it is acting strange :frowning::

00:00:00 Project sonoff Sonoff Stairs Up (Topic sonoff_stairs, Fallback sonoff_stairs_up, GroupTopic sonoffs) Version 5.9.1
00:00:00 WIF: Connecting to AP1 XXXX in mode 11N as sonoff_stairs-4940...
00:00:02 RSL: RESULT = {"POWER":"OFF"}
00:00:02 RSL: POWER = OFF
00:00:02 RSL: INFO1 = {"Module":"Sonoff Basic", "Version":"5.9.1", "FallbackTopic":"sonoff_stairs_up", "GroupTopic":"sonoffs"}
00:00:02 RSL: INFO2 = {"WebServerMode":"Admin", "Hostname":"sonoff_stairs-4940", "IPAddress":"XXXX"}
00:00:02 RSL: INFO3 = {"RestartReason":"Power on"}
00:00:03 WIF: Connected
00:00:03 DNS: Initialized
00:00:03 HTP: Web server active on sonoff_stairs-4940.local with IP address XXXXXX
00:00:04 RSL: RESULT = {"POWER":"OFF"}
00:00:04 RSL: POWER = OFF
13:29:16 RSL: STATE = {"Time":"2018-01-17T13:29:16", "Uptime":0, "Vcc":3.196, "POWER":"OFF", "Wifi":{"AP":1, "SSId":"XXXXX", "RSSI":76, "APMac":"XXXXXX"}}
13:29:16 RSL: SENSOR = {"Time":"2018-01-17T13:29:16", "Switch1":"OFF"}
13:29:17 RSL: RESULT = {"POWER":"ON"}
13:29:17 RSL: POWER = ON
13:29:20 RSL: RESULT = {"POWER":"OFF"}
13:29:20 RSL: POWER = OFF
13:30:02 CMD: poweronstate 
13:30:02 RSL: RESULT = {"PowerOnState":1}

Go figure…

If you haven’t got silly US wiring you can fit the Sonoff at the light fitting and still use the original switch connected to the gpio. I posted instructions on one of the many threads discussing this.

Otherwise, just short the wires together at the switch so it doesn’t do anything, that should confuse them enough that they’ll learn how to use it as you intended :slight_smile:

I think This is where your Problem is

the way I have wire mine

Powder → input side of the Sonoff output Side to Light

the GPI0 14 to the wall switch and then back to ground

watch DrZzs video he pointed me down the right path

https://www.youtube.com/watch?v=ab472a40-co

hope this turn the Light on for you as it did for me LOL

I am out now but will definitely check the video as soon as I get home.
Is your sonoff near your switch?
Do you have two cables reaching your switch or three?

are you talking about a 3 way switch

then if so then watch DrZzs other video about 3 way switching

he does a in a way home ass control the light not the switch controling the light
it work great

1 sonoff on the light
2 and 3 … are just MQTT sender and home ass turns the 1 sonoff on light on/off

its behind the switch face plate

watch all of DrZzs sonoff vidoes hes done a bloody good job putting them together

had watch a number of other one and they all miss some steps he didin’t

This does not have anything to do with Tree-Way switches.
Unfortunately, i cannot go the way DrZz is describing because i do not have neutral cables inside my switchboxes.
My problem is mqtt configuration, not electrical.
Pretty nice videos though, ill keep them in mind, Thanks!

Did you disable MQTT on the sonoff device under config ?

The device should turn on and stay on if you flip the wall switch from off to on again. Or does it still turn off automatically after 5-10 seconds ?

I still think the hue emulation could work, if you remove the MQTT switch from hass, turn on MQTT on the device again and keep the MQTT sensor (PIR sensor) in hass.

Exactly, here is the information page:
image

When restarting through the web server the light remains off.
This is the console output :

00:00:00 Project sonoff Sonoff Stairs Up (Topic sonoff_stairs, Fallback sonoff_stairs_up, GroupTopic sonoffs) Version 5.9.1
00:00:00 WIF: Connecting to AP1 XXXXin mode 11N as sonoff_stairs-4940...
00:00:01 RSL: RESULT = {"POWER":"OFF"}
00:00:01 RSL: POWER = OFF
00:00:02 RSL: INFO1 = {"Module":"Sonoff Basic", "Version":"5.9.1", "FallbackTopic":"sonoff_stairs_up", "GroupTopic":"sonoffs"}
00:00:02 RSL: INFO2 = {"WebServerMode":"Admin", "Hostname":"sonoff_stairs-4940", "IPAddress":"XXXXX"}
00:00:02 RSL: INFO3 = {"RestartReason":"Software/System restart"}
00:00:03 WIF: Connected
00:00:03 DNS: Initialized
00:00:03 HTP: Web server active on sonoff_stairs-4940.local with IP address XXXXX
00:00:04 RSL: RESULT = {"POWER":"OFF"}
00:00:04 RSL: POWER = OFF
15:46:04 RSL: STATE = {"Time":"2018-01-22T15:46:04", "Uptime":0, "Vcc":3.197, "POWER":"OFF", "Wifi":{"AP":1, "SSId":"XXXX", "RSSI":76, "APMac":"XXXXX"}}
15:46:04 RSL: SENSOR = {"Time":"2018-01-22T15:46:04", "Switch1":"OFF"}
15:46:36 CMD: poweronstate 
15:46:36 RSL: RESULT = {"PowerOnState":1}

When restarting by flipping the switch on and off the light comes on and turns off automatically after exactly 3 seconds, then on and off again 3 times… i am completely confused :confused:
Note: there is definately no motion detected
Here is the console output:

00:00:00 Project sonoff Sonoff Stairs Up (Topic sonoff_stairs, Fallback sonoff_stairs_up, GroupTopic sonoffs) Version 5.9.1
00:00:00 WIF: Connecting to AP1 XXX in mode 11N as sonoff_stairs-4940...
00:00:02 RSL: INFO1 = {"Module":"Sonoff Basic", "Version":"5.9.1", "FallbackTopic":"sonoff_stairs_up", "GroupTopic":"sonoffs"}
00:00:02 RSL: INFO2 = {"WebServerMode":"Admin", "Hostname":"sonoff_stairs-4940", "IPAddress":"XXXX"}
00:00:02 RSL: INFO3 = {"RestartReason":"Software/System restart"}
00:00:03 WIF: Connected
00:00:03 DNS: Initialized
00:00:03 HTP: Web server active on sonoff_stairs-4940.local with IP address XXXX
00:00:03 RSL: RESULT = {"POWER":"OFF"}
00:00:03 RSL: POWER = OFF
00:00:04 RSL: RESULT = {"POWER":"OFF"}
00:00:04 RSL: POWER = OFF
15:53:14 RSL: RESULT = {"POWER":"ON"}
15:53:14 RSL: POWER = ON
15:53:17 RSL: STATE = {"Time":"2018-01-22T15:53:17", "Uptime":0, "Vcc":3.199, "POWER":"ON", "Wifi":{"AP":1, "SSId":"XXXXX", "RSSI":80, "APMac":"XXXX"}}
15:53:17 RSL: SENSOR = {"Time":"2018-01-22T15:53:17", "Switch1":"ON"}
15:53:19 RSL: RESULT = {"POWER":"OFF"}
15:53:19 RSL: POWER = OFF
15:53:27 RSL: RESULT = {"POWER":"ON"}
15:53:27 RSL: POWER = ON
15:53:30 RSL: RESULT = {"POWER":"OFF"}
15:53:30 RSL: POWER = OFF

I tried disabling the PIR sensor altogether in the configuration:
image

Now it stays on after the switch flip.
The console still outputs the same power = off

00:00:00 Project sonoff Sonoff Stairs Up (Topic sonoff_stairs, Fallback sonoff_stairs_up, GroupTopic sonoffs) Version 5.9.1
00:00:00 WIF: Connecting to AP1 XXX in mode 11N as sonoff_stairs-4940...
00:00:02 RSL: INFO1 = {"Module":"Sonoff Basic", "Version":"5.9.1", "FallbackTopic":"sonoff_stairs_up", "GroupTopic":"sonoffs"}
00:00:02 RSL: INFO2 = {"WebServerMode":"Admin", "Hostname":"sonoff_stairs-4940", "IPAddress":"XXX"}
00:00:02 RSL: INFO3 = {"RestartReason":"Software/System restart"}
00:00:03 WIF: Connected
00:00:03 DNS: Initialized
00:00:03 HTP: Web server active on sonoff_stairs-4940.local with IP address XXX
00:00:03 RSL: RESULT = {"POWER":"OFF"}
00:00:03 RSL: POWER = OFF
15:56:58 RSL: STATE = {"Time":"2018-01-22T15:56:58", "Uptime":0, "Vcc":3.198, "POWER":"ON", "Wifi":{"AP":1, "SSId":"XXX", "RSSI":80, "APMac":"XXX"}}

And lastly, MQTT enabled and pir sensor off,
Again working as intended, the light turns and stays on.

Console output:

00:00:00 Project sonoff Sonoff Stairs Up (Topic sonoff_stairs, Fallback sonoff_stairs_up, GroupTopic sonoffs) Version 5.9.1
00:00:00 WIF: Connecting to AP1 XXX in mode 11N as sonoff_stairs-4940...
00:00:03 WIF: Connected
00:00:03 DNS: Initialized
00:00:03 HTP: Web server active on sonoff_stairs-4940.local with IP address XXXX
16:34:22 MQT: Attempting connection...
16:34:24 MQT: Connected
16:34:24 MQT: tele/sonoff_stairs/LWT = Online (retained)
16:34:24 MQT: cmnd/sonoff_stairs/POWER = 
16:34:24 MQT: tele/sonoff_stairs/INFO1 = {"Module":"Sonoff Basic", "Version":"5.9.1", "FallbackTopic":"sonoff_stairs_up", "GroupTopic":"sonoffs"}
16:34:24 MQT: tele/sonoff_stairs/INFO2 = {"WebServerMode":"Admin", "Hostname":"sonoff_stairs-4940", "IPAddress":"XXX"}
16:34:24 MQT: tele/sonoff_stairs/INFO3 = {"RestartReason":"Power on"}
16:34:26 MQT: stat/sonoff_stairs/RESULT = {"POWER":"ON"}
16:34:26 MQT: stat/sonoff_stairs/POWER = ON
16:34:34 MQT: tele/sonoff_stairs/STATE = {"Time":"2018-01-22T16:34:34", "Uptime":0, "Vcc":3.199, "POWER":"ON", "Wifi":{"AP":1, "SSId":"XXX", "RSSI":80, "APMac":"XXX"}}

So… does this tell us that the pir sensor originally connected to GPIO14 as 09 switch1 messes everything up?

Note: Tried setting up the GPIO14 as switch2 with the same switchtopic as above, now sends cmnd/motion/stairs/up/POWER2 = ON
Still getting the same behavior on boot, on and then off after 3 seconds (only once)

you still having problem with the switch " they just stay on for 4-5 seconds then go off again."

had the same problem

I was setting up a 3 way switch

what i did was put the sonoff on the first switch and set GPIO14 to push switch
everything work good happy camper then I went to the 2rd switch found the right wire and wired them into the GPIO14 of the sonoff THAT WHEN lights would come on / OFF stay off for a while the on again then flash
so I took the 2rd switch out of the loop again and everything when OK :slight_smile:

found a 2rd sonoff rewire the wire so send 240 v to the switch (no switch there)
wired the 2rd sonoff in just the input side wire the switch to GPIO14
then watched
DrZzs video about 3way switching and now everything works as it should

So im thinking its the PWM signal form the sonoff GPIO14 to the sec switch about 4 mtr away. was my problem

Hey there, thanks for the input.
Unfortunately my issue does not fall into DRZzs videos category.
I have different wiring and not enough cables installed to do the 3way switch he is describing.
I think we cleared it out on github, unless i am still missing something :frowning:

I need a software solution to my problem.
I must be missing something in the mqtt configuration :S

@krash you are misunderstanding DRZz 's setup, there is no need for what you are calling “neutral cables inside my switchboxes”.

His setup is pretty simply, wire a Sonoff at every light. So these Sonoffs have L+N going into the input side, and they have L+N coming out of output going to the light. This is the basic straightforward wiring, nothing special here.

Then install as many extra Sonoffs as you want, these have only L+N going into their input, and nothing coming out of the output. These are going to be your mqtt switches.
When you activate any of the switches, Home Assistant sends Power On to the devices that are connected to the actual lights.

Once this is working, you can start adding more complexity, such as the PIR sensors.

Hey @tommmii, That’s exactly how i am set up right now.
It works like a charm if no sensor is enabled.
MQTT works great, poweronstate works great too.

When i enable the mqtt sensor, everything works great too except one thing.

Poweronstate on the sonoffs ignores me, just turns on for 3 seconds on boot, then turns off, when i would like it to stay on.
Other features work ok after that power off. (HA switch, and motion detection automations)

This is only when you connect the PIR, right ?

Without the PIR, the Sonoff powers up, and the light comes ON and stays ON, right ?