A small update...
As I am a noob with Python language.. I got lost about the command
Code: Select all
Devices[2].Update(0,str(Total_kWh))
Environment:
SDM630-Modbus V2 together with a USB to RS485 Adapter - CH340
I changed the SDM120-Modbus software
Raspberry Pi 4 - 4GB.
OS: Raspbian GNU/Linux 11 (bullseye)
Python 3.9.2.
Domoticz Version: 2023.2 (build 15459)
I prefer in the GUI a device with the type of Managed Counter. Or General, kWh. It should show a bar for every different day. A line graph is less readable...
But not the results I expected.
So I tried 3 different sort of devices from the list in the Wiki:
https://www.domoticz.com/wiki/Developin ... vice_Types
But not always input from the plugin to the devic in Domoticz
The device with IDX 1, SubType kWh, is updated but has no data in graph.
The device with IDX 2, custom sensor, is updated and had data in graph.
The device with IDX 3, Managed Counter, is not updated
This is my script: Original authors still readable
Code: Select all
#!/usr/bin/env python
"""
Eastron SDM120-Modbus Smart Meter Single Phase Electrical System. The Python plugin for Domoticz
Original Author: MFxMF and bbossink and remcovanvugt
Better Error handling and event recovery added by simat-git 2023.
Edited by PieterS for Eastron SDM630
Works with Eastron SDM120M / SDM120CT-M, can be easily adapted to any Modbus meter.
Requirements:
1.python module minimalmodbus -> http://minimalmodbus.readthedocs.io/en/master/
(pi@raspberrypi:~$ sudo pip3 install minimalmodbus)
2.Communication module Modbus USB to RS485 converter module
"""
"""
<plugin key="SDM630-Pieter" name="SDM630" version="2" author="simat-git">
<params>
<param field="SerialPort" label="Modbus Port" width="200px" required="true" default="/dev/ttyUSB0" />
<param field="Mode1" label="Baud rate" width="40px" required="true" default="9600" />
<param field="Mode2" label="Device ID" width="40px" required="true" default="1" />
<param field="Mode3" label="Reading Interval min." width="40px" required="true" default="1" />
<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 minimalmodbus #v2.0.1
#import serial #minimalmodbus imports this now.
import Domoticz #tested on Python 3.9.2 in Domoticz 2023.2
class BasePlugin:
def __init__(self):
self.runInterval = 1
self.rs485 = ""
return
def onStart(self):
devicecreated = []
Domoticz.Log("SDM630 Pieter plugin start")
self.runInterval = int(Parameters["Mode3"]) * 1
if 2 not in Devices:
Domoticz.Device(Name="Total kWh Unit2", Unit=2,TypeName="General",Subtype=29,Used=0).Create() #Subtype Name:kWh, TypeName:kWh, Electric (Instant+Counter)
Options = { "Custom" : "1;kWh"}
if 3 not in Devices:
Domoticz.Device(Name="Total kWh Unit3", Unit=3,TypeName="Custom",Used=0,Options=Options).Create()
Options = { "Custom" : "1;kVArh"}
if 4 not in Devices:
Domoticz.Device(Name="Total kWh Unit4", Unit=4,TypeName="General",Subtype=33,Used=0).Create()
def onStop(self):
Domoticz.Log("SDM630 plugin stop")
def onHeartbeat(self):
self.runInterval -=1;
if self.runInterval <= 0:
Total_System_Power = 0 # Declare these to keep the debug section at the bottom from complaining. 1
Import_Wh = 0 # Var 2
# Export_Wh = 0 # Var 3
Total_kWh = 0 #Fix door Pieter: kwh naar kWh Var 4
# Get data from SDM630
try:
self.rs485 = minimalmodbus.Instrument(Parameters["SerialPort"], int(Parameters["Mode2"]))
#class minimalmodbus.Instrument(port: str, slaveaddress: int, mode: str = 'rtu', close_port_after_each_call: bool = False, debug: bool = False)
self.rs485.serial.baudrate = Parameters["Mode1"]
self.rs485.serial.bytesize = 8
self.rs485.serial.parity = minimalmodbus.serial.PARITY_NONE
self.rs485.serial.stopbits = 1
self.rs485.serial.timeout = 1
self.rs485.serial.exclusive = True # Fix From Forum Member 'lost'
self.rs485.debug = False
self.rs485.mode = minimalmodbus.MODE_RTU
self.rs485.close_port_after_each_call = True
Total_kWh = self.rs485.read_float(342, 4, 2)
#self.rs485.read_float(register, functioncode, numberOfRegisters)
self.rs485.serial.close() # Close that door !
except:
Domoticz.Heartbeat(1) # set Heartbeat to 1 second to get us back here for quick retry.
self.runInterval = 1 # call again in 1 second
Domoticz.Log("**** SDM120M Connection problem ****");
else:
#Update devices
Devices[2].Update(0,str(Total_kWh))
Devices[3].Update(0,str(Total_kWh))
Devices[4].Update(0,str(Total_kWh))
self.runInterval = int(Parameters["Mode3"]) * 6 # Success so call again in 60 seconds.
Domoticz.Heartbeat(10) # Sucesss so set Heartbeat to 10 second intervals.
if Parameters["Mode6"] == 'Debug':
Domoticz.Log("SDM630 Modbus Data")
Domoticz.Log('Total kWh: {0:.3f} kWh'.format(Total_kWh))
#self.runInterval = int(Parameters["Mode3"]) * 6
global _plugin
_plugin = BasePlugin()
def onStart():
global _plugin
_plugin.onStart()
def onStop():
global _plugin
_plugin.onStop()
def onHeartbeat():
global _plugin
_plugin.onHeartbeat()
# Generic helper functions
def DumpConfigToLog():
for x in Parameters:
if Parameters[x] != "":
Domoticz.Debug("'" + x + "':'" + str(Parameters[x]) + "'")
Domoticz.Debug("Device count: " + str(len(Devices)))
for x in Devices:
Domoticz.Debug("Device: " + str(x) + " - " + str(Devices[x]))
Domoticz.Debug("Device ID: '" + str(Devices[x].ID) + "'")
Domoticz.Debug("Device Name: '" + Devices[x].Name + "'")
Domoticz.Debug("Device nValue: " + str(Devices[x].nValue))
Domoticz.Debug("Device sValue: '" + Devices[x].sValue + "'")
Domoticz.Debug("Device LastLevel: " + str(Devices[x].LastLevel))
return
In my opinion it has to do with the command
#Update devices
Devices[2].Update(0,str(Total_kWh))
Devices[3].Update(0,str(Total_kWh))
Devices[4].Update(0,str(Total_kWh))
I do not understand what is wrong.
3 different devicetypes, 1 command should do the job? No errors in the logfile of Domoticz.
Code: Select all
2023-07-27 12:27:00.495 SDM630: Worker thread started.
2023-07-27 12:27:00.682 SDM630: SDM630 Pieter plugin start
2023-07-27 12:27:00.495 Status: SDM630: Entering work loop.
2023-07-27 12:27:00.495 Status: SDM630: Started.
2023-07-27 12:27:00.680 Status: SDM630: Initialized version 3, author 'PieterS'
2023-07-27 12:27:10.168 SDM630: SDM630 Modbus Data
2023-07-27 12:27:10.168 SDM630: Total kWh: 81.025 kWh
2023-07-27 12:28:10.160 SDM630: SDM630 Modbus Data
2023-07-27 12:28:10.160 SDM630: Total kWh: 81.083 kWh
2023-07-27 12:29:10.156 SDM630: SDM630 Modbus Data
2023-07-27 12:29:10.156 SDM630: Total kWh: 81.142 kWh
2023-07-27 12:30:10.149 SDM630: SDM630 Modbus Data
2023-07-27 12:30:10.149 SDM630: Total kWh: 81.201 kWh
2023-07-27 12:31:10.145 SDM630: SDM630 Modbus Data
2023-07-27 12:31:10.145 SDM630: Total kWh: 81.258 kWh
Any help appreciated. Did not find info on the wiki about the syntax how update a device..
Thnx in advance!