Page 1 of 3

Meross wi-fi Plug

Posted: Monday 24 September 2018 11:20
by CLEMENT99
Anybody is using this Meross wi-fi plug ?
1-1P5301F411338.png
1-1P5301F411338.png (55.19 KiB) Viewed 11102 times
It works fine with IFTTT command to swith on/off devices but I want to retrieve the power usage.
The goal is to create a python script to send energy data from Meross to a Domoticz virtual sensor.


Thanks

Cheers
Clement

Re: Meross wi-fi Plug

Posted: Tuesday 25 September 2018 19:14
by CLEMENT99
I found this https://github.com/albertogeniola/MerossIot and it's what I was looking for !
After implementation, it seems to work, I get the following for energy data :
Connected with result code {'session present': 0}
Subscribing to topics...
Succesfully subscribed!
Succesfully subscribed!
--> {"payload": {}, "header": {"sign": "e23d225a40a10b7acfc7bf60c33205a3", "namespace": "Appliance.Control.Electricity", "payloadVersion": 1, "from": "/app/58143-afb5195e5fd962bb10d0f881ec66a886/subscribe", "method": "GET", "timestamp": 1537895123, "messageId": "77b0308f7568adc7a78caf7d17b0b0ec"}}
/app/58143-afb5195e5fd962bb10d0f881ec66a886/subscribe --> b'{"header":{"messageId":"77b0308f7568adc7a78caf7d17b0b0ec","namespace":"Appliance.Control.Electricity","method":"GETACK","payloadVersion":1,"from":"/appliance/18071932131318251a0534298f1370ab/publish","timestamp":1537895119,"timestampMs":160,"sign":"a2c890dee095d42e8c03da253ee67963"},"payload":{"electricity":{"channel":0,"current":41,"voltage":2331,"power":4042}}}'
{'electricity': {'channel': 0, 'power': 4042, 'current': 41, 'voltage': 2331}}
The current power is 4,042W

Now find a way to retrieve the value from the string in the python script and send it to a virtual sensor ...

Re: Meross wi-fi Plug

Posted: Tuesday 25 September 2018 20:22
by heggink
Interesting devices. My key concern would be the data being retrieved from someone's cloud rather than being able to access the devices directly. I would not want my data to leave my house...

Re: Meross wi-fi Plug

Posted: Friday 28 September 2018 13:23
by CLEMENT99
Well here is the python program to get the power value and set the virtual sensor.
This code is based on the following github: https://github.com/albertogeniola/MerossIot

Just install and create the following python:
import time
import sys
import requests
from meross_cloud import MerossHttpClient

if __name__=='__main__':
httpHandler = MerossHttpClient(email="your meross email", password="your meross password")

# Retrieves the list of supported devices
devices = httpHandler.list_supported_devices()

# Returns the current power consumption and voltage from the plug
# (Note: this is not really realtime, but close enough)
electricity = devices[0].get_electricity()

current_status = devices[0].get_electricity()
str1 = str(current_status)
start1=str1.find('power')+8
end1=str1.find(",",start1)

output_s=str1[start1:end1-1]
output_n=int(output_s)/100
output_h=round(int(output_n))
# Parsing URL
httpurl = 'http://user:password@domoticz ip address/json.htm?type=command&param=udevice&idx=Device ID&nvalue=0&svalue='+str(output_h)+';0;0;0;'+str(output_n)+';0'
# Sending data to Domoticz
r = requests.get(httpurl)
Capture.JPG
Capture.JPG (13.74 KiB) Viewed 11036 times
Next step it be the ability to access the device directly.

Re: Meross wi-fi Plug

Posted: Thursday 20 December 2018 7:42
by jluc2808
hi , i started to intsall the same material under my domoticz , but the code above doesn't seem to work to create a plugin.py understadable as a plugin domoticz (i couldn't see any device to set as Meross plugin) , i surely miss some code in the plugin to set so !

Re: Meross wi-fi Plug

Posted: Thursday 10 January 2019 14:05
by Marv
@CLEMENT99

Any chance you could elaborate on how you got this working, i am just setting up a Domoticz server and i have a few of these around the house.

TIA

Re: Meross wi-fi Plug

Posted: Thursday 10 January 2019 14:20
by emme
I've setted up a script based on Meross IOT Api ( https://github.com/albertogeniola/MerossIot )
a simple python script that can interact with them

Unfortunately I do not receive back the status... just ON and OFF commands
her eis the link
https://www.domoticz.com/forum/viewtopi ... ss#p200291

Re: Meross wi-fi Plug

Posted: Tuesday 15 January 2019 10:33
by CLEMENT99
Marv wrote: Thursday 10 January 2019 14:05 @CLEMENT99

Any chance you could elaborate on how you got this working, i am just setting up a Domoticz server and i have a few of these around the house.

TIA
You need to create a dummy device type P1 Smart Meter and set the value with a URL:
# Parsing URL
httpurl = 'http://user:password@domoticz-ip-addres ... idx=Device ID&nvalue=0&svalue='+str(output_h)+';0;0;0;'+str(output_n)+';0'
# Sending data to Domoticz
r = requests.get(httpurl)

This is only to get the value.
To swith on/off with domotics, plese follow emme sample.

Re: Meross wi-fi Plug

Posted: Tuesday 15 January 2019 17:35
by CLEMENT99
Yes, it's also possbile to use IFTTT
Create a dummy device type switch.
Create 2 applets in IFTTT
In domoticz settings specify your IFTTT credentials
Change dummy device to call applets (see below) with the applet name and key
sample call -> https://maker.ifttt.com/trigger/applet- ... applet-key

Capture.JPG
Capture.JPG (29.99 KiB) Viewed 10206 times

Re: Meross wi-fi Plug

Posted: Tuesday 15 January 2019 17:36
by jluc2808
i tried to use the script to create a material with python plugin and meross_iot is installed in the same folder then the plugin script
i always get an error

2019-01-15 17:02:02.311 Error: (meross) Module Import failed, exception: 'ImportError'
2019-01-15 17:02:02.311 Error: (meross) Module Import failed: ' Name: requests'
2019-01-15 17:02:02.311 Error: (meross) Error Line details not available.

my plugin.py :

Code: Select all

# Author: JLB
#
"""
<plugin key="MerossPlug" name="Meross M310" author="JL" version="1.0.0">
    <params>
     <param field="Mode6" label="Debug" width="75px">
       <options>
          <option label="True" value="Debug"/>
          <option label="False" value="Normal"  default="true" />
       </options>
     </param>
    </params>
</plugin>
"""
import time
import sys
import requests
import Domoticz
from meross_iot.api import MerossHttpClient

if __name__=='__main__':
	httpHandler = MerossHttpClient(email='Myemail', password='MyPassword')

# Retrieves the list of supported devices
devices = httpHandler.list_supported_devices()

# Returns the current power consumption and voltage from the plug
# (Note: this is not really realtime, but close enough)
electricity = devices[0].get_electricity()

current_status = devices[0].get_electricity()
str1 = str(current_status)
start1=str1.find('power')+8
end1=str1.find(",",start1)

output_s=str1[start1:end1-1]
output_n=int(output_s)/100
output_h=round(int(output_n))
# Parsing URL
httpurl = 'http://192.168.1.45/json.htm?type=command&param=udevice&idx=Device ID&nvalue=0&svalue='+str(output_h)+';0;0;0;'+str(output_n)+';0'
# Sending data to Domoticz
r = Request.get(httpurl) 
[\code]

Re: Meross wi-fi Plug

Posted: Tuesday 15 January 2019 19:10
by CLEMENT99
Did you install everything in the folder \Domoticz\scripts\python\Meross ?

Re: Meross wi-fi Plug

Posted: Tuesday 15 January 2019 19:34
by jluc2808
Yes

Re: Meross wi-fi Plug

Posted: Tuesday 15 January 2019 19:59
by jluc2808
do you know the exact http request sent to Meross web server , if so if will be easier to create a dvEvents script with and store the results in virtual devices (or real one if it's better), if you have the log perhaps you could share what is sent .

thanks

Re: Meross wi-fi Plug

Posted: Wednesday 16 January 2019 17:08
by CLEMENT99
I'll check that with wireshark but I'm waiting for a new plug (my son left with my plug :( )

Re: Meross wi-fi Plug

Posted: Wednesday 16 January 2019 17:38
by emme
does Domoticz supports python ver >= 3.6 on the plugin framework?

Re: Meross wi-fi Plug

Posted: Wednesday 16 January 2019 18:52
by jluc2808
i have installed python 3.5 because it's on my NAS synology and i have no package of 3.6 for the system.

Re: Meross wi-fi Plug

Posted: Thursday 17 January 2019 13:22
by corederoma82
CLEMENT99 wrote: Tuesday 15 January 2019 19:10 Did you install everything in the folder \Domoticz\scripts\python\Meross ?
Which things I have to install in this folder?

Thanks

Re: Meross wi-fi Plug

Posted: Monday 21 January 2019 22:14
by corederoma82
Can someone explain me the full procedure to install it?

Thanks

Re: Meross wi-fi Plug

Posted: Saturday 20 April 2019 19:28
by mangoose
Hi,

I created a bridge in NodeJS based on Apollon77 allowing to control the plugs from Domoticz and to get the power consumption.
The bridge is available here:
https://github.com/mangoose002/Meross2Domoticz

I am using pm2 to run it.

Hope it can help you.

Re: Meross wi-fi Plug

Posted: Sunday 21 April 2019 7:48
by jluc2808
great, but sorry i don't understand how you install it ?
create a dummy ?
where is store the code ?
what need to be setted and what files ?
how you launch the application ?
what is needed inside domoticz ?