bytespider / Meross

Investigating the Meross/Refoss MSS310 Smart Plug and getting these devices to communicate with our private MQTT brokers
113 stars 19 forks source link

Help troubleshooting Meross Light Switch Connection #28

Closed dyordan1 closed 3 years ago

dyordan1 commented 3 years ago

I seem to have tried everything in guides around the interwebs to convince my Meross(?) device to connect to my Home Assistant MQTT broker. The reason I put (?) is because I'm not entirely convinced it's a Meross but it presents itself in that way. The WiFi SSID for setup is Meross_SW_XXXX and ./meross info seems to work just fine. However, it displays an MSS560m model, which I couldn't find on the Meross website, neither visually nor by model number. Only places I could find selling a Meross MSS560m are Ali Express and Alibaba. The switches were present when I moved in so I have no history on them :)

With the history out of the way, here's my meross setup command & output:

./meross setup --wifi-ssid '<SSID>' --wifi-pass '<PW>' --mqtt mqtts://192.168.1.<HA>
Setting up device with IP 10.10.10.1
┌────────────────────────────────────┬────────────────────────────────────────────────────────┐
│MQTT broker                         │192.168.1.<HA>:8883                                     │
├────────────────────────────────────┼────────────────────────────────────────────────────────┤
│MQTT broker                         │192.168.1.<HA>:8883                                     │
└────────────────────────────────────┴────────────────────────────────────────────────────────┘
┌─────────────────┬───────────────────────────────────────────────────────────────────────────┐
│Device           │mss560m us mt7682 (hardware:3.0.0 firmware:3.1.6)                          │
├─────────────────┼───────────────────────────────────────────────────────────────────────────┤
│UUID             │<REDACTED>                                                                 │
├─────────────────┼───────────────────────────────────────────────────────────────────────────┤
│Mac address      │<MAC>                                                                      │
├─────────────────┼───────────────────────────────────────────────────────────────────────────┤
│WIFI             │ (<MAC>)                                                                   │
├─────────────────┼───────────────────────────────────────────────────────────────────────────┤
│MQTT broker      │192.168.1.<HA>:8883                                                        │
├─────────────────┼───────────────────────────────────────────────────────────────────────────┤
│Status           │Online                                                                     │
├─────────────────┼───────────────────────────────────────────────────────────────────────────┤
│Credentials      │User: 0                                                                    │
│                 │Password: 0_<MD5(MAC)>                                                     │
└─────────────────┴───────────────────────────────────────────────────────────────────────────┘
┌────────────────────────────────────────────────────┬────────────────────────────────────────┐
│Encoded WIFI SSID                                   │<REDACTED>                              │
├────────────────────────────────────────────────────┼────────────────────────────────────────┤
│Encoded WIFI password                               │<REDACTED>                              │
└────────────────────────────────────────────────────┴────────────────────────────────────────┘

After running the command, the switch does indeed restart and goes right back into pairing mode (with the pairing WiFi still available).

I've validated that the MQTT broker at 192.168.1.<HA>:8883 is available by sending a message with mosquitto_pub, but it does use a custom ca cert. I've read Meross switches don't validate CAs so I'm hoping that's not a tripping point. The broker will accept anonymous messages (as long as I give the ca cert to mosquittopub), but it does seem to reject with Connection error: Connection Refused: not authorised. if I use the verbatim `-u '' -P '0<MD5(MAC)>'`. I did read in #12 that Home Assistant will do some user encoding before passing on the username, so I'm hoping this is a non-issue, but would like to verify what a good mosquitto_pub u/P would be to sanity check whatever username/password the switch attempts using will actually publish to my local broker.

I also noticed a fair bit more logging / debugging data in #12 - is there any way to enable that level of logging for the info/setup tools? Couldn't parse it out of the JS source, but maybe I missed something.

What's my logical next steps to figure out what's going on here?

bytespider commented 3 years ago

Hi @dyordan1

What version of the HA MQTT broker are you using?

dyordan1 commented 3 years ago

Thanks for the quick response. Using 6.0.1 and have it set to auto-update.

Btw, something I forgot to mention and saw discussed in other places is the switches and HA are on different subnets (192.168.1. vs 192.168.30.). I can try to connect the switch temporarily to a WiFi with the same subnet when I'm home later if we think that can help, but ultimately I'd like them to be on the different ones.

bytespider commented 3 years ago

6.0.1 is the issue. https://github.com/home-assistant/addons/issues/2014

dyordan1 commented 3 years ago

Ah. I had misread one of your comments in #12 that the colon in username was a non-issue because of the way HA handles passing the logins.

OK, let me try to figure out how to downgrade when I'm home. IIRC, HA makes this not very friendly :)

Thanks for the help.

dyordan1 commented 3 years ago

Yup. That was totally it. Ha. With my luck it was exactly 6 days ago I started trying this whole Meross fiasco, the day of MQTT 6.0 release :)

I had to manually fork the 5.1.1 and install a local add-on but it seems to hook up to my MQTT broker now, so this tool works like a charm, thank you.

Only piece of feedback I have is that "Online" status in output where there are network/MQTT connection issues can make debugging a bit frustrating / confusing. Is there any way to listen for the device and confirm it's connected? Maybe add a mosquitto_sub on its expected topic and confirm it's publishing state?

bytespider commented 3 years ago

Most of that information is pulled directly from the device.

I agree with your feedback, I also think the username should be the MAC address rather than the Meross account user id since we're not using it here.

The problem with this tool subscribing to the topic is that every user may have a different set up, but I will add a list of the topics to the output so that users may know which topics to subscribe to themselves should they need want to.

dyordan1 commented 3 years ago

FYI, it does look like some Meross devices (The 560m I have, for example), require internet connectivity for setup. Makes a few DNS and https calls, but didn't look too far into it beyond that. Might be worth pointing out in setup instructions. However, once setup I locked down internet traffic and only allowed local MQTT and it works like a charm.

bytespider commented 3 years ago

A few others have reported devices making NTP requests, but I've not experienced this on the MSS310 device I have. If you have the DNS/HTTP traffic captured it would be helpful if you could email it.

I can't see anything in the app source code that might suggest any device "Calls Home" so to speak.

dyordan1 commented 3 years ago

I don't have it captured, unfortunately. I was going off my network controller's deep inspection stats in the timeframe I was setting it up, so accuracy may be off. I still have a few switches to setup, I'll try to capture the traffic for the next one, probably later this week.

DHCP NTP should be setup on the switch's network to point at a local NTP server. I'll double check that's the case, good call. It doesn't do anything silly like hardcode an NTP server or domain name, right?

bytespider commented 3 years ago

@dyordan1 could you provide a link to your fork and a guide how to roll back? The longer the issue persists the more people are upgrading and breaking their systems

dyordan1 commented 3 years ago

It was rather easy actually. For someone comfortable with git, just pull https://github.com/home-assistant/addons @14cbbc6 (just prior to MQTT 6.0 bump) and then follow the custom add-on guide from HA: https://developers.home-assistant.io/docs/add-ons/tutorial/ [updated with correct guide link]

Here's a bit more detailed "my component broke how do I fix" that others can follow though:

Fetch an older version of the component

Go to the GitHub repo of the addon. All the built in add-ons are at https://github.com/home-assistant/addons. Once there, navigate to the list of commits (upper right corner of file list), the URL is usually /commits/master (or commits/main for newer repos).

Find the latest commit prior to the one that broke you. For MQTT 5.1, that'd be 14cbbc63fcc33ae698c00c136421729694b964a3, since the very next one is the MQTT bump to 6.0. Click on the commit in the list and then "Browse Files" in the upper right corner of the commit description. Use the green "Files" button to download a Zip file of the repository.

You should end up with a zip archive with the repo name and commit #, for example addons-14cbbc63fcc33ae698c00c136421729694b964a3.zip. Extract the folder and fetch only the files you need - mosquitto folder in addons for MQTT Broker.

Make sure SSH is enabled and functional on your Home Assistant

Install the "Terminal & SSH" Add-On and make sure you have a password set under the Configuration tab. If you have another way to get your files to your HA, you don't have to do this, but I found this to be the easiest way. You should probably disable SSH access after this by removing the password, if you don't use SSH often.

Copy the downloaded add-on files to your HA

Before you copy anything to your HA - remove the existing add-on and restart HA (hard reboot (Reboot Host) from Supervisor/System)! If you have any SSL or various other MQQT config, make sure to note them down, since they won't persist over the downgrade.

Next, you need to copy the files you downloaded to <HA_IP>:/addons/<name>. I used scp to run this command from the downloaded addons folder, renaming mosquitto to MQTT5.1 locally for clarity:

scp -r MQTT5.1 root@<IP>:/addons

When asked for password, use the one you setup in the SSH add-on config (not any of your HA account passwords).

With any luck, another reboot and you should see and enable MQTT from your add-ons, since it will be recognized as a custom component :) Configure the component as needed, if you backed up any config above. Make sure to disable auto-updates. HA seems to recognize the plugin as the official one in the UI, so I'm not sure how it'd behave re: updates.


(Well this turned out a bit longer than I was hoping, but I know I would've appreciated this paint-by-numbers guide when I was getting started so hopefully it helps someone).

bytespider commented 3 years ago

Thank you

balbulator commented 3 years ago

dyordan1 I copied the files into Raspberry downloads (/home/user/Downloads) Then I copied the MQTT5.1 folder from this directory to the folder /usr/share/hassio/addons/data After rebooting, nothing appeared in Home Assistant It seems I did something wrong. Tell me the correct copy path to Raspberry (not from another computer, but from the Raspberry itself) Thank you

balbulator commented 3 years ago

Thank you

Did you manage to roll back to the old version?

dyordan1 commented 3 years ago

dyordan1 I copied the files into Raspberry downloads (/home/user/Downloads) Then I copied the MQTT5.1 folder from this directory to the folder /usr/share/hassio/addons/data After rebooting, nothing appeared in Home Assistant It seems I did something wrong. Tell me the correct copy path to Raspberry (not from another computer, but from the Raspberry itself) Thank you

Try putting the folder straight into /addons such that the following is a valid path: /usr/share/hassio/addons/MQTT5.1/config.json

Then, go to your supervison, Add-On Store, and click Refresh from the overflow menu. Do make sure to remove the MQTT 6.0 integration and hard reboot your pi. I was having some weird issues prior to reboot.

bytespider commented 3 years ago

@balbulator if you're having issues you can try using my temporary add-on repository.

Go to Supervisor > Add-On Store. Click the vertical ... then Repositories. Enter https://github.com/bytespider/home-assistant-addons in the field and click add. After you add you should see: Screen Shot 2021-05-31 at 12 58 44 You want to disable or uninstall the official Mosquitto broker before installing mine.

balbulator commented 3 years ago

@balbulator if you're having issues you can try using my temporary add-on repository.

Go toy Supervisor > Add-On Store. Click the vertical ... then Repositories. Enter https://github.com/bytespider/home-assistant-addons in the field and click add. After you add you should see: Screen Shot 2021-05-31 at 12 58 44 You want to disable or uninstall the official Mosquitto broker before installing mine.

Super solution, thank you

balbulator commented 3 years ago

Super solution, thank you

balbulator commented 3 years ago

Alas, this integration disables all sensors and all devices. Objects become inaccessible

balbulator commented 3 years ago

At the same time, everything worked as it should, but before the first reboot

balbulator commented 3 years ago

It worked, I don’t know how I managed it, many reboots Thank you all for your help.

Ostepanov commented 3 years ago

It was rather easy actually. For someone comfortable with git, just pull https://github.com/home-assistant/addons @14cbbc6 (just prior to MQTT 6.0 bump) and then follow the custom add-on guide from HA: https://developers.home-assistant.io/docs/add-ons/tutorial/ [updated with correct guide link]

Here's a bit more detailed "my component broke how do I fix" that others can follow though:

Fetch an older version of the component

Go to the GitHub repo of the addon. All the built in add-ons are at https://github.com/home-assistant/addons. Once there, navigate to the list of commits (upper right corner of file list), the URL is usually /commits/master (or commits/main for newer repos).

Find the latest commit prior to the one that broke you. For MQTT 5.1, that'd be 14cbbc63fcc33ae698c00c136421729694b964a3, since the very next one is the MQTT bump to 6.0. Click on the commit in the list and then "Browse Files" in the upper right corner of the commit description. Use the green "Files" button to download a Zip file of the repository.

You should end up with a zip archive with the repo name and commit #, for example addons-14cbbc63fcc33ae698c00c136421729694b964a3.zip. Extract the folder and fetch only the files you need - mosquitto folder in addons for MQTT Broker.

Make sure SSH is enabled and functional on your Home Assistant

Install the "Terminal & SSH" Add-On and make sure you have a password set under the Configuration tab. If you have another way to get your files to your HA, you don't have to do this, but I found this to be the easiest way. You should probably disable SSH access after this by removing the password, if you don't use SSH often.

Copy the downloaded add-on files to your HA

Before you copy anything to your HA - remove the existing add-on and restart HA (hard reboot (Reboot Host) from Supervisor/System)! If you have any SSL or various other MQQT config, make sure to note them down, since they won't persist over the downgrade.

Next, you need to copy the files you downloaded to <HA_IP>:/addons/<name>. I used scp to run this command from the downloaded addons folder, renaming mosquitto to MQTT5.1 locally for clarity:

scp -r MQTT5.1 root@<IP>:/addons

When asked for password, use the one you setup in the SSH add-on config (not any of your HA account passwords).

With any luck, another reboot and you should see and enable MQTT from your add-ons, since it will be recognized as a custom component :) Configure the component as needed, if you backed up any config above. Make sure to disable auto-updates. HA seems to recognize the plugin as the official one in the UI, so I'm not sure how it'd behave re: updates.

(Well this turned out a bit longer than I was hoping, but I know I would've appreciated this paint-by-numbers guide when I was getting started so hopefully it helps someone).

It works! I've downgraded my mqtt and now all my meross devices are working as they should!

I would like to add that better and easier doing it with smb addon. It enables a simple copy/paste from windows explorer to addons folder. After that, it's important to modify config.json, changing name of plugin, like "name": "Mosquitto broker 5". This step allows HA detecting it as different mqtt addon and show it like this: imagen

Thanks @bytespider and @dyordan1 for making this work