question

macjl avatar image
macjl asked

No value shown with Shelly PRO 1PM

Hello,

I’m triying to add a Shelly Pro 1 PM to my Venus system.

The Shelly device is configured with Outbound Websocket to the Venus device. Now I can see a Shelly energy meter" in device list, but no data are shown :

img-0332.jpeg

Should it work ? Is it a bug ? Or did I forget some steps ?

The Shelly Pro 1 PM device firmware is 1.0.8-gdba0ee3.

Energy Meter
img-0332.jpeg (130.4 KiB)
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

3 Answers
kurtinge avatar image
kurtinge answered ·

Have the same experience. If I enter the "Device" menu under the "Shelly energy meter" I can see the Venus is having contact. Need restart of the Shelly to make this activated.
But still no energy data. I believe this have someting to do with the tags in the websocket, but I couldn't figure it out.
1713869967214.png


1713869967214.png (25.3 KiB)
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

macjl avatar image
macjl answered ·

There is an issue in the dbus-shelly github, which seems related :

https://github.com/victronenergy/dbus-shelly/issues/3


I hope this will be fixed soon !

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

matt1309 avatar image
matt1309 answered ·

Hi @MacJL @kurtinge


It's the data structure of the data sent from shelly that's the cause. The driver is written for Energy meter devices whereas 1 PM pro i believe is seen more as a switch from shelly's point of view, with power metering added in.


I've not got a shelly 1PM pro to test this. However I'll talk you through the steps.


1. Run the below script on any machine that can run python. This will output the structure of the data sent from the shelly devices. From this you can work out what you need to edit on the victron code to get it working.

import asyncio
import websockets
 
async def echo(websocket, path):
    async for message in websocket:
        print(f"Received message from client: {message}")
        await websocket.send(message)
 
async def main():
    # Start the WebSocket server on localhost, port 8765
    async with websockets.serve(echo, "192.168.3.138", 8765):
        print("WebSocket server started on ws://192.168.3.138:8765")
        # Keep the event loop running forever
        await asyncio.Future()
 
# Run the main function to start the WebSocket server
asyncio.run(main())


Changing the IP of 192.168.3.138 to whatever the ip of the machine you're running this test script on. Then setup the shelly 1pm pro to use websockets and connect to the ip and port noted above. In my test script it's 192.168.3.138:8765.


Then you wait for data to be received on on the test machine. The above script will show you what the data looks like when it's received. Once you have that you can work out how to edit the meter.py in the victron code.


My guess is it'll look something like this:

Received message from client: {"src":"shellypro1pm-30c6f781a900","dst":"ws","method":"NotifyStatus","params":{"ts":2.32,"switch:0":{"id":0,"voltage":218.5}}}



If it does then you can add this code to meter.py and it should work:

 try:
                            d = data['params']['switch:0']
                        except KeyError:
                            pass
                        else:
                            with service as s:
                                avoltage = d.get("voltage")
                                if avoltage is not None:
                                   s['/Ac/L1/Voltage'] = avoltage #could add option to getPhase from settings. 
                                acurrent = d.get("current")
                                if acurrent is not None:
                                    s['/Ac/L1/Current'] = acurrent #could add option to getPhase from settings. 
                                apower = d.get("apower")
                                if apower is not None:
                                    s['/Ac/L1/Power'] = apower #could add option to getPhase from settings. 
                                    s['/Ac/Power'] = apower
                                    #to add the total energy lookups not sure if can do reverse
                                    #aenergy = d.get("aenergy")
                                    s["/Ac/Energy/Forward"] = round(aenergy.get("total")/1000,1)
                                    s["/Ac/L1/Energy/Forward"] = round(aenergy.get("total")/1000,1)



I've not got a shelly 1pm pro so cannot test this. However you should be able to just add the above code in the if statement:

if self.service and data.get('method') == 'NotifyStatus':


under the em0 code for the energy meter shelly devices.


Hope this helps.




EDIT: I had a look on github and someone has already complete the task i explained above:

You just need to edit your meter.py to include the PM code that he has here:


GitHub - jjdejong/dbus-shelly: HTTP based driver for Shelly energy meters to be used on VenusOS

3 comments
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

kurtinge avatar image kurtinge commented ·

@matt1309
We discussed this matter in the thread https://community.victronenergy.com/questions/274629/dbus-shelly-problem-showing-blank-in-console.html?childToView=276142#comment-276142

But couldn't figure it out still. I might did something wrong - don't know :-)

My last message from this thread tells me there is something wrong in the meter.py:

changed the line:

old value: s['/Ac/L1/Voltage'] = d["a_voltage"]
new value: s['/Ac/L1/Voltage'] = d["voltage"]

This resulted in the following error in the log:

@400000006616511e0dd0183c Error in connection handler
@400000006616511e0dd02fac Traceback (most recent call last):
@400000006616511e0dd0377c File "/usr/lib/python3.8/site-packages/websockets/server.py", line 191, in handler
@400000006616511e0dd04b04 await self.ws_handler(self, path)
@400000006616511e0dd056bc File "/opt/victronenergy/dbus-shelly/dbus_shelly.py", line 73, in __call__
@400000006616511e0dd06a44 await m.update(data)
@400000006616511e0dd07214 File "/opt/victronenergy/dbus-shelly/meter.py", line 134, in update
@400000006616511e0dd28554 s['/Ac/L1/Voltage'] = d["voltage"]
@400000006616511e0dd294f4 KeyError: 'voltage'


0 Likes 0 ·
matt1309 avatar image matt1309 kurtinge commented ·

Yes you also need to change

Line to be

d = data['params']['switch:0']


You may also want to do this instead:


avoltage = d.get("voltage")
                                if avoltage is not None:
                                   s['/Ac/L1/Voltage'] = avoltage #could add option to getPhase from settings. 


This will help incase voltage isn't sent in every message. say shelly sends voltage every other message then you'll get error just using d["voltage"]

1 Like 1 ·
kurtinge avatar image kurtinge matt1309 commented ·
Tnx... I will check out later this evening
0 Likes 0 ·

Related Resources