Python Script Assistance - Meross Sensons

… and I bought that sensor because it allowed remote checking and IFTTT, which I set up. It was after that I had the idea to Integrate it (or try) into HG.

Do bear in mind that HG uses the Iron Python 2.7 engine and not the regular Python which has its own backend. Again it’s just something you may want to take note of.

Just as an aside, to save yourself a lot of time have you considered offloading the sensors to a separate instance of Python and deploying the results to an MQTT client/broker. Just food for thought.

Played around with this some more this morning. I needed to change the paths I was trying to append to match where the meross python library was:
import sys

this will tell HG where to look for libraries


But neither this:
import MerossManager

nor this:
from meross_iot.manager import MerossManager

is working and I get a runtime error.

On the pi itself via Putty, there is a meross_info_gather program in the /home/pi/.local/bin directory.
at the command line, I typed:
python3 meross_gather_info

And the program ran (it asks for your email and password and then connects and does some stuff). It creates a zip file (not sure how to open the zip file or copy it from my pi to my desktop to be able to see it however).

On another note, I do have the Meross sensor set up in IFTTT and it will send me a text message via an applet when the humidity is out of the defined range. Wondering if it may be simpler to have the IFTTT applet make a HG API call and turn on a device I create.

I found IFTTT to slow for my liking for turning on lights. Other things didn’t seem to bother me so it maybe worth atleast a try.
Also since you can get things done vis the command line you could have HG run the script via command line instead of directly. This may also be slower then you’d like. I do this for my broadlink stuff.

If it’s slow I’m not worried, it’s not a light I’m controlling. I basically want to see if I can have the AC in my basement turn on and off based on the Meross sensor readings.

Youd probably be happy with eirher approach. However I prefere to stay away from cloud automation services as much as I can.

I’d still like to get the Python script figured out- would be good to have more options. I haven’t been able to get the library files to import however.

Unfortunately there isn’t a large amount of Python examples available in the HG community. As you can see from searches it’s mainly C# and Javascript. Pity really as Python is such an easy environment to develop in.

You might be lucky if one of the HG Python programmers drop by here at some stage and steer you in the right direction if you haven’t found a solution yourself by then.

I made some progress with this the last few days (off and on working on this).

Using this:

appears to be the correct path now to the meross package and this:
from import SensorSubDevice

does not result in the same error about not finding the module - it does however result in an error on an unexpected “:”.

Similarly, this line:
from meross_iot.meross_event import MerossEventType

no longer has the unknown module error but instead has this error:
“no module named enum”

I think the issue is that the MerossEventType module has some dependencies on other modules that need to be loaded. In the code, this line:

import os

was giving me errors so I commented it out - my guess is that the enum module is part of that. In addition to the os module, this line is also in the code:

from random import randint

Similarly, that is giving me an error.

I am going to try and find where the os and random packages are on my pi unit and see if I can update the sys.path to include that and see if that resolves the import errors for those packages.

I resolved the enum module issue:
import enum

But getting an error on:
from meross_iot.manager import MerossManager

and a missing base64 module.

I tried one of the other python scripts in the same library and getting similar errors. I think its a dependency issue with some of the modules (i.e. base64) and their not being available in the HG Python Script editor - I tried multiple ways to get the missing modules imported with no luck.

So I’m moving on to try and replicate what the code was doing via an api call instead

which returns"
{“apiStatus”:1023,“sysStatus”:0,“data”:null,“info”:“Sign check failed”,“timeStamp”:“2020-06-10 12:23:47”}

I need to find out how to pass the user email and password and the other required fields as part of that api url.

Should you be trying to establish an https connection to Meross. Have you tried http instead.

A nice little write up for Meross in Domoticz that might be of use. I’ve Domoticz installed and it’s quite useful.

I just tried http instead of https - I don’t get anything back with that. With https I am at least getting the string returned I mentioned.

I may reach out to the person who developed the Python library and see if they could share the API documentation from Meross. In the meantime, I will check out the link you provided.

I read thru the info on the link (Domoticz) and it seems to be the same approach I am attempting. At least in HG, the issue appears to be trying to get the script to compile and run with the import commands finding the modules it needs without error - there appear to be dependencies in the meross modules to other modules that are not being loaded (i.e. the base64 error). I’m stuck trying to resolve that.

Interestingly, in the Domocticz post from the link you provided it is mentioned that IFTTT is also an option - and that is what I had been working on the other day. I have a dummy switch set up in HG and then defined an IFTTT applet to send an On or Off command (based on the humidity) to HG and that does seem to work.

If that proves reliable, I may just use that but the python script offered much more info and control (i.e. you can get the actual temp and humidity readings wheras the IFTTT applet just sends a message when the trigger is reached, and does not include the actual temp or humidity value).

Yes Alberto would be the man to contact on all things Meross and Python. Possibly the best route to go at this stage

I posted this on the github site for the Meross IOT library:

Perfect and the Github is active as can be seen from the latest update. I’ll give you one thing, you’re persistent and hopefully a solution will pay off as a result.

I got a reply from the Python script developer:
“The current version of the library 0.4.X.X requires Python 3.7+. I guess your version of HomeGenie is running the script with a lower version of Python. If that’s the case, the only way you have to run this library is to upgrade the Python version to 3.7 or 3.8.”

Which confirms what I thought - HG itself needs to be updated to allow use of the newest Python version.

I entered a new feature request on the HG GitHub site:

I commented in the GitHub on this.

HG deploys Iron Python and it does indeed use the latest version 2.7 so nothing can be done there on versioning.

You might want to read up on the differences between Iron Python and Python to get to the bottom of this. Iron Python is generally deployed in the .Net environment which would explain a lot here.