Hello there!
@lwolf, I saw your hard work put on the scripts to get work the Shelly Devices. Really appreciate it.
Almost all devices working fine, but new Shelly Pro 4PM doesn't. I tried to do some modifications inside
https://github.com/enesbcs/Shelly_MQTT/ ... /plugin.py but without effect.
I know about new communication method on Shelly new gen devices.
What I need for my solution is get the data from Pro 4PM about Energy usage and cost calculation for each "switch id [0-3]". No need for now to control the relays.
Via MQTT I'm getting messages in this format:
Code: Select all
pi@raspberrypi:~$ mosquitto_sub -h localhost -t "#" -v
shellypro4pm-083af27cb654/events/rpc {"src":"shellypro4pm-083af27cb654","dst":"shellypro4pm-083af27cb654/events","method":"NotifyStatus","params":{"ts":1656440039.21,"switch:0":{"id":0,"apower":31.9}}}
shellypro4pm-083af27cb654/events/rpc {"src":"shellypro4pm-083af27cb654","dst":"shellypro4pm-083af27cb654/events","method":"NotifyStatus","params":{"ts":1656440040.20,"switch:0":{"id":0,"aenergy":{"by_minute":[597.673,587.033,586.901],"minute_ts":1656440039,"total":1484.366}}}}
shellypro4pm-083af27cb654/events/rpc {"src":"shellypro4pm-083af27cb654","dst":"shellypro4pm-083af27cb654/events","method":"NotifyStatus","params":{"ts":1656440040.21,"switch:1":{"id":1,"aenergy":{"by_minute":[734.940,805.348,791.949],"minute_ts":1656440039,"total":7441.695}}}}
shellypro4pm-083af27cb654/events/rpc {"src":"shellypro4pm-083af27cb654","dst":"shellypro4pm-083af27cb654/events","method":"NotifyStatus","params":{"ts":1656440040.33,"switch:2":{"id":2,"aenergy":{"by_minute":[769.093,773.691,782.623],"minute_ts":1656440039,"total":7162.738}}}}
shellypro4pm-083af27cb654/events/rpc {"src":"shellypro4pm-083af27cb654","dst":"shellypro4pm-083af27cb654/events","method":"NotifyStatus","params":{"ts":1656440040.34,"switch:3":{"id":3,"aenergy":{"by_minute":[229.611,227.116,227.247],"minute_ts":1656440039,"total":1983.964}}}}
shellypro4pm-083af27cb654/events/rpc {"src":"shellypro4pm-083af27cb654","dst":"shellypro4pm-083af27cb654/events","method":"NotifyStatus","params":{"ts":1656440041.19,"switch:0":{"id":0,"pf":0.57}}}
shellypro4pm-083af27cb654/events/rpc {"src":"shellypro4pm-083af27cb654","dst":"shellypro4pm-083af27cb654/events","method":"NotifyStatus","params":{"ts":1656440041.19,"switch:1":{"id":1,"apower":40.0}}}
shellypro4pm-083af27cb654/events/rpc {"src":"shellypro4pm-083af27cb654","dst":"shellypro4pm-083af27cb654/events","method":"NotifyStatus","params":{"ts":1656440041.19,"switch:1":{"id":1,"current":0.286}}}
shellypro4pm-083af27cb654/events/rpc {"src":"shellypro4pm-083af27cb654","dst":"shellypro4pm-083af27cb654/events","method":"NotifyStatus","params":{"ts":1656440042.18,"switch:0":{"id":0,"pf":-0.70}}}
shellypro4pm-083af27cb654/events/rpc {"src":"shellypro4pm-083af27cb654","dst":"shellypro4pm-083af27cb654/events","method":"NotifyStatus","params":{"ts":1656440042.18,"switch:1":{"id":1,"apower":44.7}}}
shellypro4pm-083af27cb654/events/rpc {"src":"shellypro4pm-083af27cb654","dst":"shellypro4pm-083af27cb654/events","method":"NotifyStatus","params":{"ts":1656440042.18,"switch:1":{"id":1,"current":0.310}}}
Also you're able to get same data via curl request to the device:
Get SWITCH status ID0:Room1:
Code: Select all
$ curl -X POST -d '{"id": 1, "method": "Switch.GetStatus", "params": {"id": 0}}' http://192.168.0.5/rpc
{"id":1,"src":"shellypro4pm-083af27cb654","result":{"id":0, "source":"init", "output":true, "apower":0.0, "voltage":238.0, "current":0.042, "pf":0.00, "aenergy":{"total":406.313,"by_minute":[0.000,0.000,0.000],"minute_ts":1656150937},"temperature":{"tC":57.2, "tF":135.0}}}
Get SWITCH status ID0:Room2:
Code: Select all
$ curl -X POST -d '{"id": 1, "method": "Switch.GetStatus", "params": {"id": 1}}' http://192.168.0.5/rpc
{"id":1,"src":"shellypro4pm-083af27cb654","result":{"id":1, "source":"init", "output":true, "apower":44.6, "voltage":237.8, "current":0.314, "pf":-0.72, "aenergy":{"total":2844.338,"by_minute":[261.925,749.784,743.873],"minute_ts":1656150979},"temperature":{"tC":57.1, "tF":134.8}}}
LEGEND:
id: number, id of the Switch component instance
source: string, source of the last command, for example: init, WS_in, http, ...
output: boolean, true if the output channel is currently on, false otherwise
apower: number, last measured instantaneous power (in Watts) delivered to the attached load (shown if applicable)
voltage: number, last measured voltage in Volts (shown if applicable)
current: number, last measured current in Amperes (shown if applicable)
pf: number, last measured power factor (shown if applicable)
aenergy: JSON object, information about the energy counter (shown if applicable)
total: number, total energy consumed in Watt-hours
by_minute: array of numbers, energy consumption by minute (in Milliwatt-hours) for the last three minutes (the lower the index of the element in the array, the closer to the current moment the minute)
minute_ts: number, unix timestamp of the first second of the last minute (in UTC)
It will be very good if you could give some advice or even if you have time to look on this if it's possible to get power usage calculations and graphs over Domoticz.
Dave