|
| 1 | +import device |
| 2 | +import probe |
| 3 | +from register import * |
| 4 | + |
| 5 | +# Thys Python script adds support for Modbus enabled Shelly devices in dbus-modbus-client |
| 6 | +# version 1.58 and later. |
| 7 | +# |
| 8 | +# https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/Modbus |
| 9 | +# |
| 10 | +class Shelly_Meter(device.CustomName, device.EnergyMeter): |
| 11 | + vendor_id = 'shelly' |
| 12 | + vendor_name = 'Shelly' |
| 13 | + min_timeout = 0.5 |
| 14 | + |
| 15 | + # Shelly uses input registers! |
| 16 | + default_access = 'input' |
| 17 | + |
| 18 | + def device_init(self): |
| 19 | + self.info_regs = [ |
| 20 | + Reg_text(0, 6, '/Serial', little=True), |
| 21 | + ] |
| 22 | + |
| 23 | + self.data_regs = [ |
| 24 | + Reg_f32l(1162, '/Ac/Energy/Forward', 1000, '%.1f kWh'), |
| 25 | + Reg_f32l(1164, '/Ac/Energy/Reverse', 1000, '%.1f kWh'), |
| 26 | + Reg_f32l(1013, '/Ac/Power', 1, '%.1f W'), |
| 27 | + |
| 28 | + Reg_f32l(1020, '/Ac/L1/Voltage', 1, '%.1f V'), |
| 29 | + Reg_f32l(1022, '/Ac/L1/Current', 1, '%.1f A'), |
| 30 | + |
| 31 | + ] |
| 32 | + |
| 33 | +class Shelly_Pro_3EM(Shelly_Meter): |
| 34 | + productname = 'Shelly Pro 3EM' |
| 35 | + productmodel = 'SPEM-003CEBEU' |
| 36 | + nr_phases = 3 |
| 37 | + |
| 38 | + # Shelly doesn't have a purely numerical Product ID and it's unclear what could |
| 39 | + # be a good placeholder for it. Using the Base16 encoded value of 'PEM3'. |
| 40 | + productid = 0x50454D33 |
| 41 | + |
| 42 | + def device_init(self): |
| 43 | + super().device_init() |
| 44 | + |
| 45 | + self.data_regs += [ |
| 46 | + Reg_f32l(1182, '/Ac/L1/Energy/Forward', 1000, '%.1f kWh'), |
| 47 | + Reg_f32l(1184, '/Ac/L1/Energy/Reverse', 1000, '%.1f kWh'), |
| 48 | + Reg_f32l(1024, '/Ac/L1/Power', 1, '%.1f W'), |
| 49 | + |
| 50 | + Reg_f32l(1040, '/Ac/L2/Voltage', 1, '%.1f V'), |
| 51 | + Reg_f32l(1042, '/Ac/L2/Current', 1, '%.1f A'), |
| 52 | + Reg_f32l(1202, '/Ac/L2/Energy/Forward', 1000, '%.1f kWh'), |
| 53 | + Reg_f32l(1204, '/Ac/L2/Energy/Reverse', 1000, '%.1f kWh'), |
| 54 | + Reg_f32l(1044, '/Ac/L2/Power', 1, '%.1f W'), |
| 55 | + |
| 56 | + Reg_f32l(1060, '/Ac/L3/Voltage', 1, '%.1f V'), |
| 57 | + Reg_f32l(1062, '/Ac/L3/Current', 1, '%.1f A'), |
| 58 | + Reg_f32l(1222, '/Ac/L3/Energy/Forward', 1000, '%.1f kWh'), |
| 59 | + Reg_f32l(1224, '/Ac/L3/Energy/Reverse', 1000, '%.1f kWh'), |
| 60 | + Reg_f32l(1064, '/Ac/L3/Power', 1, '%.1f W'), |
| 61 | + ] |
| 62 | + |
| 63 | +models = { |
| 64 | + Shelly_Pro_3EM.productmodel: { |
| 65 | + 'model': Shelly_Pro_3EM.productmodel, |
| 66 | + 'handler': Shelly_Pro_3EM, |
| 67 | + }, |
| 68 | +} |
| 69 | + |
| 70 | +probe.add_handler(probe.ModelRegister(Reg_text(6, 10, 'model', little=True), models, |
| 71 | + methods=['tcp'], |
| 72 | + units=[1])) |
0 commit comments