Admittedly, the solution for HomeAssistant looks completely fleshed out. Sorry, this is sadly not that.
For those who are interested, I did some work on a meross-bridge to connect Meross Thermostats with OpenHAB. It is still an external service that translates Meross MQTT to OpenHAB MQTT.
Maybe a native OH2 add-on would be better but this is using the meross-iot Python library and I didnât want to re-invent the weel.
So feel free to use it, feedback is welcome:
Alle die mit dem klasse Skript gerne den Status ihres Garagentors in mqtt gepublished haben möchten:
Einfach in Zeile 59:
client.publish("meross/%s" %(eventobj.device.name),eventobj.door_state)
einfĂŒgen
PS: Danke fĂŒr das Skript und die Beschreibung!
Hello, everybody. First of all, thank you very much for this nice tutorial. I was able to follow more or less everything and I think almost everything works, but since the Meross plug is only the second thing I implemented in Openhab, I have some basic problems with the connection between OH and the plug.
So I have an item in OH and I can switch the âplugâ on and off and I also get the message in MQTT.fx âmeross/device_name = OFFâ, but the real plug does not switch off. I also used the examples from https://github.com/albertogeniola/MerossIot/ and was able to switch the plug off with putty and ssh. The meross2mqtt.service is also running.
Now I cannot get connections from OH to the ms310 plug. Do I need to add anything before which is basic and not mentioned here? How does OH know where the Python script is located? Is there something like in the exec-binding where I have to write the path or something like that?
Thanks for your help!
Great tutorial and sample code using albertogeniola MerossIot python library
This code works fine using meross_iot==0.3.1.9.
But is there someone that succeeded to rewrite it using the latest meross_iot 0.4 which is a complete rewrite of the meross_iot library using async functions ?
Maybe I will have a check on Daniel Morlock Meross-bridge as a great inspiration !
I finally did it .
For those interested by an upgraded version using merossiot 0.4 and Python3.9, have a look at this code
extensively inspired by excellent code from Daniel Morlock / meross-bridge
Hi, I am using âmeross2mqttv2â, use it successfully in terminal, but when I create a service for it, it failed to start. Is anyone successfully created service for it?
Eric
Hi Denis,
thank you so much, Iâm using your amended Phython 3.9 script with my Openhab 3.0 Raspberry Pi system. It works perfectly! Iâm using it with my Meross MSS550X wallswitches.
so following is needed:
for those who need to configure the MS550X Openhab 3.0 channel should also work with Openhab 2.5:
Meross outgoing value transformation .js:
setMerossState.js.txt (119 Bytes)
Hi supoeric,
this is my service unit configuration, I copied Denis script into my openhab folder at /etc/openhab/scripts
[Unit]
Description=meross2mqttV2
After=mosquitto.service[Service]
Type=simple
ExecStart=/usr/bin/python3 /etc/openhab/scripts/meross2mqttV2.py --mqtt-server 127.0.0.1 --mqtt_usr openhab --mqtt_pswd <âyour mqtt pwdâ> -e <âyour meross mailâ> -p <âyour meross pwdâ> -l var/log/meross2mqtt/meross.log
Restart=always
User=openhab
Group=openhab
Environment=PATH=/usr/bin:/usr/sbin:/etc/openhab/scripts
Environment=NODE_ENV=production
WorkingDirectory=/etc/openhab/scripts[Install]
WantedBy=multi-user.target
Status of my service - it works with the above config despite the last column itâs not Gone or Offline.
No clue what this means, but the service is running at I can control my switches via openhab.
Thanks BetahydriïŒ
I will try it tonight.
Eric
@Denis_Lambert and @betahydri thanks a lot for your effort. I finally came around to update to oh3 and try the new version for merossIot.
Running the script from âmeross2mqtt v2â I encountered a TimeOutError. I âfixedâ it putting a try - except around line 204. Not proper, but works when I run it from the command line. I am still having troubles when using the service though.
Edit: Okay, I had a few errors in my service file. It is working!
I am still getting this error, as mentioned before:
Mar 23 09:57:12 openHABianPi python3.9[1922]: File "/usr/local/lib/python3.9/asyncio/base_events.py", line 596, in run_forever
Mar 23 09:57:12 openHABianPi python3.9[1922]: self._run_once()
Mar 23 09:57:12 openHABianPi python3.9[1922]: File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1890, in _run_once
Mar 23 09:57:12 openHABianPi python3.9[1922]: handle._run()
Mar 23 09:57:12 openHABianPi python3.9[1922]: File "/usr/local/lib/python3.9/asyncio/events.py", line 80, in _run
Mar 23 09:57:12 openHABianPi python3.9[1922]: self._context.run(self._callback, *self._args)
Mar 23 09:57:12 openHABianPi python3.9[1922]: File "/etc/openhab/scripts/meross02.py", line 79, in start
Mar 23 09:57:12 openHABianPi python3.9[1922]: self.log.info("Setting Last will message=", lwm, "topic is", self.args.mqtt_ident)
Mar 23 09:57:12 openHABianPi python3.9[1922]: Message: 'Setting Last will message='
Mar 23 09:57:12 openHABianPi python3.9[1922]: Arguments: ('Meross Gone Offline', 'topic is', 'meross')
Is this normal?
Hello @daJoe ,
The error you got was simply caused by old formatting code. It was not harmful and offending line could have been commented out but it is now corrected in the latest version of this code. Also added the try ⊠except in case the asyn_update takes more time than expected (5 sec)
Youre right. Measuring the power, voltage and current is not published by the device itself. You have to make a request to get the data.
Im new to openhab. But i think its easy to adapt the python scripts here to do an active polling
Hi
Iâm running OH 3.1.0
Python3 --version 3.8.10
Meross_iot 0.4.2.3
Sorry for all the text, but I canât get my Meross switch to work with my local MQTT / openhab
I use Albertogeniola Merosslot example script regarding to this link and my mss710 turns on and off.
I look at daJoe Johannes R:s script, regarding to this link
If Iâm running daJoe Johannes R âoldâ script meross2mqtt.py with meross_iot==0.3.1.5 and tested with meross_iot==0.4.2.3
I got error on line 3, (I canât import MerossEvent)
error
No module named meross_iot.meross.event
Where can I found this module?
Next step
Then I followed Opus Terra this link
My ânewâ meross2mqttV2.py file and I changed following
parser.add_argument(ââmqtt-serverâ, dest=â192.168.1.174â,
parser.add_argument (â-eâ, ââemailâ, dest=âmy real email@hotmail.comâ,
It says in the script that meross password can be set later
When I run
'sudo python3 meross2mqttV2.py
I get this error
meross2mqttV2.py: error: the following arguments are required: -e/âemail
Why this error?
Then I add my password in meross2mqttV2.py file
parser.add_argument (â-pâ, ââpasswordâ, dest=âmy real meross passwordâ
I get this error
File âMeross2mqttV2.pyâ, line 63
self.loop = loop:
^
SyntaxError: invalid syntax
When Iâm running meross-bridge manual with meross_iot 0.4.0.0rc9
regarding to this link meross bridge
I installed meross bridge via suggestion 2 and ssh
Then run
sudo meross-bridge --mqtt-server 192.168.1.174 -e myemail@hotmail.com -p my merosspassword
I get this error
INFO:Initializing the MQTT connectionâŠ
INFO:Discovery found a new Meross device Fönstret (18072498697172251axxxxxxxxx).
ERROR:Timeout occurred while waiting a response for message bâ{âheaderâ: {âfromâ: â/app/68xxx-4aa4594b7e208d39xxxxxxxxx/subscribeâ, âmessageIdâ: âd2134e453b1170xxxxxxxxxxâ, âmethodâ: âGETâ, ânamespaceâ: âAppliance.System.Abilityâ, âpayloadVersionâ: 1, âsignâ: â0775fc51a3080b4a687d43afexxxxxxxxxâ, âtimestampâ: 1632xxxxxx}, âpayloadâ: {}}â sent to device uuid 18072498697172251xxxxxxxxx. Timeout was: 5.0 seconds
ERROR:Failed to retrieve abilities for device Fönstret (1807249869717225xxxxxxxxxx). This device wonât be enrolled.
INFO:Starting consumer for OpenHAB MQTT messgaes âŠ
If I keep following the meross bridge guide.
I add/made a file in /etc/default/meross-bridge with my email and meross password
chmod 0600
Then I looked for a meross-bridge.service file in /etc/systemd/, but I donât have anyone so I canât enable/start meross-bridge.service
My Meross info
My meross switch info
INFO:The following devices are new to me: [{âuuidâ: â18072498697172251axxxxxxxâ, âonline_statusâ: âONLINEâ, âdev_nameâ: âF\u00f6nstretâ, âdev_icon_idâ: âdevice027_unâ, âbind_timeâ: â2021-05-07T20:25:04â, âdevice_typeâ: âmss710â, âsub_typeâ: âunâ, âchannelsâ: [{}], âregionâ: âeuâ, âfmware_versionâ: â2.1.4â, âhdware_versionâ: â2.0.0â, âuser_dev_iconâ: ââ, âicon_typeâ: 1, âskill_numberâ: ââ, âdomainâ: âmqtt-eu-2.meross.comâ, âreserved_domainâ: âmqtt-eu-2.meross.comâ}]
My snifferlog
INFO - USER-TOPIC (/app/68xxx/subscribe) â {âheaderâ: {âtimestampMsâ: xxx, âtimestampâ: 163xxxxxx, âsignâ: â18c9ef6e1411170138axxxxxxxxâ, âpayloadVersionâ: 1, ânamespaceâ: âAppliance.Control.ToggleXâ, âmethodâ: âPUSHâ, âmessageIdâ: âbedb780340b1xxxxxxxxxxxâ, âfromâ: â/appliance/18072498697172251axxxxxxxxx/publishâ}, âpayloadâ: {âtogglexâ: [{âonoffâ: 1, âlmTimeâ: 1632xxxxxx, âchannelâ: 0}]}}
2021-09-19 15:34:43,721 - Sniffer - INFO - --------------- More data -----------------
2021-09-19 15:34:43,721 - Sniffer - DEBUG - Disconnected from MQTT brocker
2021-09-19 15:34:46,293 - Sniffer - INFO - Sysdata for Fönstret (18072498697172251axxxxxxx): {âallâ: {âsystemâ: {âhardwareâ: {âtypeâ: âmss710â, âsubTypeâ: âusâ, âversionâ: â2.0.0â, âchipTypeâ: âmt7682â, âuuidâ: â18072498697172251axxxxxxxxxxâ, âmacAddressâ: â34:29:xx:xx:xx:xxâ}, âfirmwareâ: {âversionâ: â2.1.4â, âcompileTimeâ: â2018/11/30 11:02:57 GMT +08:00â, âwifiMacâ: â74:ac:xx:xx:xx:xxâ, âinnerIpâ: â192.168.1.113â, âserverâ: âmqtt-eu-2.meross.comâ, âportâ: 443, âuserIdâ: 68xxx}, âtimeâ:
âonlineâ: {âstatusâ: 1}}, âdigestâ: {âtogglexâ: [{âchannelâ: 0, âonoffâ: 1, âlmTimeâ: 1632058482}], âtriggerxâ: [], âtimerxâ: [{âchannelâ: 0, âidâ: â26786d69xxxxxxxxxâ, âcountâ: 1}, {âchannelâ: 0, âidâ: âe844fddaeb4xxxxxâ, âcountâ: 1}]}}}
I have been reading Albertogiola:s page regarding to this link but I guess I have missed something:
Do I have to add some file somewhere with my mqtt broker(mosquitto) info or is it OK with just have my local ip in the meross2mqttV2.py file as above?
I donât understand where I have to put my device info, from my snifferlog and which info is relevant in that file (and file ending/ for example devices.xx ?).
I guess I need to add my local device ipaddress, device mac address, uuid etc somewhere?
My mosquitto is tested/running via MQTT explorer
Thank you
Anyone is running Meross Garage Door Opener MSG100 with the script based on Meross 0.4 bridge?
The script recognizes my device, but I cannot integrate into OpenHAB.
I solved some of it.
I have miscalculated or lack of knowledge
I went back and changed mersso2mqttV2.py so with no changes in the file.
Then run
sudo python3 meross2mqttV2.py --email myemail@email.com --password mypassword
And I got connected.
mqtt explorer says
{âstateâ: âOFFâ, âtypeâ: âmss710â, âChannelNameâ: âMain channelâ, âfriendlyNameâ: âF\u00f6nstretâ, âonlineâ: true}
Now I am in the same situation as @demichve
I canât connect my channel to openhab.
The log says
string OFF could not be converted to JSON
string ON could not be converted to JSON Handling message from topic âmeross/Fönstret/setâ: OFF with qos 0 and retain flag 0
Openhab
I have just add in channel
mqtt state topic
meross/Fönstret/channel_0
mqtt command topic
meross/Fönstret/set
custom on
ON
custom off
OFF
Is command
switch to on
@Andreas3
You have to active the right transformations in OpenHab:
JSONPath Transformation
Javascript Transformation
Then it should work.
Yes. You need to go in Advance mode for the regarding channel and fix those two fields:
incoming Value Transformations
JSONPATH:$.state
Outgoing Value Transformation
JS:setZigbeeState.js
where setZigbeeState.js is simply this code that goes in the transform Openhab3 directory:
(function(x){
var result = new Object();
result.state = x;
return JSON.stringify(result);
})(input)
Great, Thanks!
(I also forgot to install Javascript transformation )
I add/update the incoming and outgoing value in OH3.
I add the merossfile.js in /etc/openhab/transform
reboot
run meross2mqttV2.py script
Mqtt explorer
meross ={âstateâ:true}
Fönstret
channel_0 ={âstateâ:âOFFâ,âtypeâ etc etc
set = {âstateâ:âOFFâ}
Now when I toggle ON/OFF I get a number of errors instead
-- Logging error ---
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/meross_iot/manager.py", line 630, in _async_send_and_wait_ack
return await asyncio.wait_for(future, timeout, loop=self._loop)
File "/usr/lib/python3.7/asyncio/tasks.py", line 423, in wait_for
raise futures.TimeoutError()
concurrent.futures._base.TimeoutError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/etc/openhab/scripts/Meross2/meross2mqttV2.py", line 162, in handle_message
await device[0].async_turn_on(channel=0)
File "/usr/local/lib/python3.7/dist-packages/meross_iot/controller/mixins/toggle.py", line 110, in async_turn_on
drop_on_overquota=drop_on_overquota)
File "/usr/local/lib/python3.7/dist-packages/meross_iot/controller/device.py", line 233, in _execute_command
drop_on_overquota=drop_on_overquota)
File "/usr/local/lib/python3.7/dist-packages/meross_iot/manager.py", line 624, in async_execute_cmd
timeout=timeout)
File "/usr/local/lib/python3.7/dist-packages/meross_iot/manager.py", line 634, in _async_send_and_wait_ack
raise CommandTimeoutError()
meross_iot.model.exception.CommandTimeoutError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.7/logging/__init__.py", line 1034, in emit
msg = self.format(record)
File "/usr/lib/python3.7/logging/__init__.py", line 880, in format
return fmt.format(record)
File "/usr/lib/python3.7/logging/__init__.py", line 619, in format
record.message = record.getMessage()
File "/usr/lib/python3.7/logging/__init__.py", line 380, in getMessage
msg = msg % self.args
TypeError: not all arguments converted during string formatting
Call stack:
File "/etc/openhab/scripts/Meross2/meross2mqttV2.py", line 374, in <module>
main()
File "/etc/openhab/scripts/Meross2/meross2mqttV2.py", line 370, in main
Runner().run()
File "/etc/openhab/scripts/Meross2/meross2mqttV2.py", line 333, in run
loop.run_until_complete(self.bridge.consume())
File "/usr/lib/python3.7/asyncio/base_events.py", line 571, in run_until_complete
self.run_forever()
File "/usr/lib/python3.7/asyncio/base_events.py", line 539, in run_forever
self._run_once()
File "/usr/lib/python3.7/asyncio/base_events.py", line 1775, in _run_once
handle._run()
File "/usr/lib/python3.7/asyncio/events.py", line 88, in _run
self._context.run(self._callback, *self._args)
File "/etc/openhab/scripts/Meross2/meross2mqttV2.py", line 122, in consume
await self.async_handle_openhab_mqtt_message(client, userdata, message)
File "/etc/openhab/scripts/Meross2/meross2mqttV2.py", line 141, in async_handle_openhab_mqtt_message
await self.handle_message("/".join(msg_split[1:-1]), str(message.payload.decode("utf-8")))
File "/etc/openhab/scripts/Meross2/meross2mqttV2.py", line 189, in handle_message
self.log.error("Unexpected error in MQTT message handling:", sys.exc_info()[0])
Message: 'Unexpected error in MQTT message handling:'
Arguments: (<class 'meross_iot.model.exception.CommandTimeoutError'>,)
As stated here , this code was written for python 3.9. maybe thatâs why you got all those errors âŠ