-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
connecting Refoss EM06 via local MQTT #476
Comments
Hello @cbergmann, As a starter (and hopefully finisher) we'd need at least a 'Download diagnostics' from the device so that these features (called 'namespaces' in Meross jargon) are euristically queried and dumped. After that, if everything works as usual, we should be able to infer the meaning of the different data and add decoding/encoding capabilities to meross_lan in order to map these to useful entities. Another option (in parallel), would be to enable the 'Create diagnostic entities' in meross_lan -> Configuration -> Diagnostic. The final (more powerful) option would be to use the 'Start diagnostic trace' (always in meross_lan-> Conf -> Diagnostics) to grab the full protocol exchange over a longer period of time so that you could physically operate the device (if anything is 'operable' from that) and meross_lan would dump every single message occuring. I don't know the device but it looks like being just an energy/power sensor with maybe some configuration options. I think we could get it to work at least in a basic scenario, maybe more... |
Hi, Attach is the downloaded diagnostics information. config_entry-meross_lan-98f787ca444fe061299056061a3fddc6.json |
Awesome! The trace is saved under |
The The I think the last missing value (i.e. the actual power reading) is being reported by |
Hi, |
I've released a preview with some (small) improvements on entities mapping for EM06. You could try install the preview and see if anything improves (the consumption readings should be there though). |
Hi, I installed the preview version and got a new diagnostics file. At the first glance this has not helped but maybe you can see something in the file. |
Hello,
Now switch to YAML mode and correct the Now to the (verbose) details: I've found in the original Refoss code that the query payload should be Having said that, you should try and see if any of these queries work and then post the service reply (I'm confident at least 1 should work) so that I have the correct payload response to inspect. Thank you! (by the way, just curious: did you try to use the Refoss integration? if so did it work or not?) |
Hi this is the result for
and this is the result for
That looks good. On your question about the Refoss integration: I looked into this but at that time i did not figure out a way to join the device to the WIFI without using the official app and therefore also using the refoss cloud. That was not an option for me. Now that You mentioned that I tried adding it and after fiddeling a little bit with my firewall I got it working. The only problem was that my HA and the device are on differnt networks. The Integration has no option to specify the IP and relies on sending a broadcast to port 9988. That would not reach the device and therefore setup would fail. When configuring iptables to rewrite the broadcast adress to the device adress before sending the udp datagram out the setup completes and everything works. |
I didn't dig too much in the refoss-ha library supporting this but the traffic over UDP could just be the discovery part since I've found parts of code using 'standard' http traffic to query the device. But the trace could become useful in the future...I've sent you a PM |
I looked into the pcap files and it seems that your are right. The UDP datagrams are always the same and seem to only contain basic information. The main data seems to be transmitted via http. |
Updated pre-release. Beside the naive naming of some sensors it should work. I've removed the decoding of consumption hourly history since the statistics should be better available through HA. The only 'open question', provided everything else works as expected, is the interpretation of the energy reading. We have to see what will happen on these. At the moment I've just used |
Also I would suggest naming the entities with a1,b1,c1,a2,b2,c2 because the sensors on the device are labeld like this. This would make it more easy to identify which reading is from wich sensor. |
Hello, I'd like to read data from my em06 to publish it on EmonCMS. Would it be possible to have a simple sample code to gather infos via API? I've tried this:
but the device replies this: I guess that in Could someone please help me? |
Hello @gponzo, Going back to your code, the first thing to check by the way is the url: devices respond to the |
Grazie @krahabb, I've just analyzed the code you suggested me, but unfortunately my knowledge on Python is not so deep. Anyway I'll try this evening to do some test. Consider that I did |
Hey @gponzo, I'm also not very expert with python running modules and stuff..I've just started learning python while developing meross_lan and, in the beginning, I was just copying over samples for HA components development so I'm a bit lost too when trying to use the code outside of HA. Anyway... I suggest you a few steps (just tried and confirmed working):
import asyncio
from meross_lan.merossclient.httpclient import MerossHttpClient
async def async_main():
client = MerossHttpClient("192.168.1.70", key="")
response = await client.async_request("Appliance.System.All", "GET", {})
print(response)
response = await client.async_request("Appliance.Control.Electricity", "GET", {"electricity": {}})
print(response)
if __name__ == "__main__":
loop = asyncio.new_event_loop()
loop.run_until_complete(async_main()) Once the file is in place you can either run it from vscode ('Run python file' from the top-right corner of the editor window) or, from the command line by just typing When initializing the MerossHttpClient, beside the host address, you have to provide the 'device key' (long story here if you don't know what I mean...but if you have installed and running in HA you can copy the device key from the configuration there) The first request ("Appliance.System.All") works on every device and replies a general device status/config while the second one ("Appliance.Control.Electricity") is very specific for metering plugs (like mss310) and will not work on every device. For EM06 you should be good using "Appliance.Control.ElectricityX" instead (every other param is the same). The This could be a start for some experiments, feel free to ask more if any. As for the call we could arrange that on skype when you want. |
Thank you so much! I've just tried creating main.py with the code you wrote, but when I run it I receive this error:
I'm afraid that the previous line contains a referral to HomeAssistant:
I didn't fill the key value: where can I find the device key in Home Assistant? |
Yep...I was scared of that since the package itself as a whole is an HA custom component so it has to have all of the dependencies installed (using Getting some help here in order to correctly import everything I've tried this:
import asyncio
from merossclient.httpclient import MerossHttpClient
async def async_main():
client = MerossHttpClient("192.168.1.70", key="")
response = await client.async_request("Appliance.System.All", "GET", {})
print(response)
response = await client.async_request("Appliance.Control.Electricity", "GET", {"electricity": {}})
print(response)
if __name__ == "__main__":
loop = asyncio.new_event_loop()
loop.run_until_complete(async_main())
If you succesfully configured your EM06 in HA (so that's working) then you're done: enter the meross_lan integrations page and hit 'CONFIGURE' for the device entry. On the menu choose 'Configure' and you should see the device key there. This value was likely automatically retrieved from your Meross cloud account when you configured that in HA too - if you did it) |
No way :( I've done what you wrote but I stil get an error:
About the key, I've been able to configure and I'm using the em06 in Home Assistant, but via Refoss integration. I'm so frustrated about not being able to simply ask the info to this device... I've been inspecting Refoss integration code too, but I didn't find anywhere an http request... |
I don't understand the error tbh...what's the complete output (when you run the I'm pretty sure my suggested approach is working (i'm testing it on the 'dev' branch but the 'master' one should be safer in this regard) regarding the key, I've digged a bit into the refoss_ha repo and it is using an empty key (i.e. a void string: "") so that my example should work as is. Only, the As for the I'm curious about what happens when you try to configure the device in meross_lan. |
Hi, sorry for being silent for so long... That's the complete output:
It tells about syntax... just like if the name object is not recognized... About the code in
I'd say that it enters that
So the parser shouldn't rise an error, as if it is
|
Anyway I solved!!! The solution is in this file:
So, my final code is:
|
Awesome! |
You known the own Refoss implementation? |
Yep..more or less |
Hi how fast can this integration of the em06 query the data? the original refoss integration is set to 15s. However, in my opinion this is not useful for current measurement because the error is too large with fluctuating loads. |
I haven't seen any time limitation with my script. But I think you could change these timings at your disposal. This is my final code, translated for Python 2.x since I'm running it on an old Single Board Computer:
|
@linuxdep, Nevertheless it doesn't mean the device internal sampling rate is as fast (it could be though). At any rate you could experiment a bit (lowering the meross_lan polling period) and see if you get better results for your needs. P.S. could you confirm the device 'generally works' in meross_lan ? |
Hi,
I have a Refoss Smart Energy Monitor EM06 to monitor the power usage of some of my appliances. It seems that Refoss and Meross are somehow connected/the same company therefore I tried this integration but only with limited success. Following is my writeup of what I did and what works.
When using the Refoss app I can pair the device with the Refoss cloud and see the collected data.
On my HA setup I strive to not have any dependencies to external cloud services. Therefore I wanted to pair this device locally to my local mosquitto MQTT server.
As my mosquitto Server normally does not allow anonymous connections I added another listener with the following config:
The DHCP server is configured to give the EM06 a fixed IP and the firewall is configured to only allow that IP to connect to that port.
/etc/mosquitto/meross.acl
reads as follows:Next I did a hardware-reset on the EM06 by pressing the button for around 5 seconds. The device confirmed that by a red LED and after restarting blinking green.
Thereafter I installed Version v5.3.0 of the meross_lan Integration from via HACS and restarted Home Assistant.
I then installed the MerossBLE app onto my phone. The device was found and correctly reported in the Discovered Device secion as followed.
I entered the hostname of my MQTT Server (redacted as mqtt.my.local) in the "Server" field and 8884 in the "Port" field. I kept 0 the UserId field and entered a short passphrase as "Key". Then I selected "Write".
In the "Time Configuration" section I selected "Europe/Berlin" as my "Timezone" and also selected "Write".
As a last step in the app I selecte "Scan" in the "WIFI Configuration" section. Then selecting my wifi and entering the password before also confirming with "Write".
The LED of the device then turns to solid green.
In the mosquitto log I see the device connecting with username 48:e1:e9:e9:2d:1d. It subscribes to
/appliance/2401066372070174070148e1e9e92d1d/subscribe
and the following three messages are exchanged:This seems to repeat every few seconds.
Next I go to Home Assistant and it discovers the Meros Lan Integration (my HA is in german so some labels might be not correct here). I select "Configure" and enter the same passphrase as device key. It discovers the em06 device immediately and I can configure it.
While doing that the following MQTT messages are exchanged:
The device is added to Home Assistant with two entities. A disabled one for the sensor protocol and one for the signal strenght which reports 100%.
This is it. After that I don't get any more information in Home Assistant.
While testing this I also got the following messages but I was not able to reproduce them. They are not sent frequently. Maybe the are only sent after a certain power usage but I don't know that.
It seems that these contain the correct power consumtions of the devices in mW. The negative numbers seem to be related to the accuracy of the sensor.
I don't know if this is the correct integration or if I should try something different. If this seems interessting for this integration I am more then happy to provied more information or test a new version. I am sufficentily fluent in python to also write a PR if youre are able to give me a hint where to start.
with kind regards
Clemens
The text was updated successfully, but these errors were encountered: