krahabb / meross_lan

Home Assistant integration for Meross devices
MIT License
449 stars 47 forks source link

MSS310 Button shows incorrect state in MQTT mode #230

Closed fritut08 closed 1 year ago

fritut08 commented 1 year ago

I followed this guide on how to setup the mqtt add-on for home assistant and on how to use @bytesnider's software to pair my Meross MSS310 smart plugs with my wifi network and the mqtt add-on. Afterwards, the devices are auto-discovered by DHCP and I can start to configure them. I use "Hack Mode" because none of the other modes work for me.

Whenever the device is in "auto" or "http" mode, it works fine. I can switch the plug on and off by clicking on the corresponding button. When I want it to use the "MQTT" mode, though, and click on the button to switch it off, it successfully switches the plug off but the button will indicate the "off" state only for 1 second or so and then jump right back to "on" without actually switching the smart plug on. Now, when I click on the button again, the smart plug stays off and the button will again briefly indicate "off" and switch back to "on" shortly after. The only way for me to turn the smart plug back on is to click the button twice fast, so that the button has not yet switched back to "on" by itself.

krahabb commented 1 year ago

Hello @fritut08, I'm actually a bit busy and can't really test this right now..I'll definitely check it in the coming days anyway, maybe this is really a bug in th emeross_lan MQTT implementation which never shows up since I guess we're in the likes of 5-6 people using meross_lan in this way ;) Btw, my setup, on MQTT works but it may be, like you said, I'm using them in AUTO mode so any MQTT bug is hidden behind. Pls be patient until I get back to meross_lan with more time

fritut08 commented 1 year ago

@krahabb Thanks for the effort! I really appreciate the work you put into this. I'll keep them on 'auto' for now as well but eventually would like to replace it with 'mqtt' entirely.

krahabb commented 1 year ago

Hello @fritut08, I've tried a bit but everything looks good with my mss310 on MQTT.

I'll do some more testing but if you can get a diagnostic trace (https://github.com/krahabb/meross_lan/wiki/Diagnostics#download-diagnostics) from the device and post it here I could better investigate what is not working in your environment.

Also: does meross_lan/HA correctly and immediately report the switch state when you operate it directly on the device? On MQTT the device should push an instant message to the broker on every state change and you can see this behavior is working by effectively checking the state gets immediately reflected in HA. If meross_lan is using HTTP (or does not receive any notification through MQTT) you would see the state update only every so often (30 seconds polling by default)

Frenelius commented 1 year ago

Hello, I have the same problem as @fritut08 with a new pack of 4 MSS310, hardware version 6.0.0, firmware 6.x.x

I have another 4 old ones, HW version 2.0.0, firmware 2.1.10, which work wonderfully with your hack, but not these new ones.

I will try to send some debugs, but the behavior is as described.

Thanks krahabb for your effort.

jkp commented 1 year ago

Also having the same issue. I did a trace and see the following MQTT messages when I try to toggle the power:

2023/01/09 - 09:39:51 TX mqtt SET Appliance.Control.ToggleX {"togglex": {"channel": 0, "onoff": 1}} 2023/01/09 - 09:39:51 RX mqtt SETACK Appliance.Control.ToggleX {}

The behaviour is that the device turns off, but the outlet state in HomeAssistant toggles back to on after the SETACK. I cannot then toggle the device back on without using the Meross app. When I do that I'll see a message with the following content:

2023/01/09 - 09:45:29 RX mqtt PUSH Appliance.Control.ToggleX {"togglex": {"channel": 0, "onoff": 1, "lmTime": 1673257527}}

I'm using the fixed device key setting and all the other sensors are reporting data correctly (e.g power consumption etc).

Firmware version: 6.3.21 Hardware version: 6.0.0

Does that help to narrow it down at all?

krahabb commented 1 year ago

Hello @jkp, The problem is, like I was suspecting, the device doesn't send the PUSH with the updated state when operated through MQTT which, instead, is always sent on older firmwares. I'm getting 'back to work' and looking forward to overcome this. The main problem being my actual code implementation doesn't support any kind of MQTT transaction state so the SETACK received after the SET (on MQTT) is not actually meaningful since it doesnt carry the actual state.

jkp commented 1 year ago

@krahabb makes sense, though I'm not sure that is the only issue! We'll find out as you get a chance to look at fixing it though...

I guess you're already deeply familiar with the reversed engineered protocol specification that's been put together elsewhere?

If there is anything I can do to help shout. I have a background in software development and know Python well so I can help test or debug things as needed if it would help.

fritut08 commented 1 year ago

@krahabb Sorry, but I did not get around to reply until now.

does meross_lan/HA correctly and immediately report the switch state when you operate it directly on the device?

Yes, it does in auto and mqtt mode (with a delay of 1 s or so). When in http mode it does not immediately report the switch state but takes much longer (due to the delay you described).