Fixed counters, and Total power meter with "Return" Channel
This commit is contained in:
61
plugin.py
61
plugin.py
@ -73,13 +73,16 @@ class BasePlugin:
|
|||||||
# Create the devices if they does not exists
|
# Create the devices if they does not exists
|
||||||
if 1 not in Devices:
|
if 1 not in Devices:
|
||||||
#Domoticz.Device(Name="Total Energy", Unit=1, Type=0x71, Subtype=0x0, Used=0).Create()
|
#Domoticz.Device(Name="Total Energy", Unit=1, Type=0x71, Subtype=0x0, Used=0).Create()
|
||||||
Domoticz.Device(Name="Total Energy", Unit=1, Type=248, Subtype=33, Used=0).Create()
|
#Domoticz.Device(Name="Total Energy", Unit=1, Type=248, Subtype=33, Used=0).Create()
|
||||||
|
Domoticz.Device(Name="Total Energy", Unit=1, Type=0xfa, Subtype=0x01, Used=0).Create()
|
||||||
if 2 not in Devices:
|
if 2 not in Devices:
|
||||||
#Domoticz.Device(Name="Export Energy", Unit=2, Type=0x71, Subtype=0x0, Used=0).Create()
|
#Domoticz.Device(Name="Export Energy", Unit=2, Type=0x71, Subtype=0x0, Used=0).Create()
|
||||||
Domoticz.Device(Name="Export Energy", Unit=2, Type=248, Subtype=33, Used=0).Create()
|
#Domoticz.Device(Name="Export Energy", Unit=2, Type=248, Subtype=33, Used=0).Create()
|
||||||
|
Domoticz.Device(Name="Export Energy", Unit=2, Type=0xfa, Subtype=0x01, Used=0).Create()
|
||||||
if 3 not in Devices:
|
if 3 not in Devices:
|
||||||
#Domoticz.Device(Name="Import Energy", Unit=3, Type=0x71, Subtype=0x0, Used=0).Create()
|
#Domoticz.Device(Name="Import Energy", Unit=3, Type=0x71, Subtype=0x0, Used=0).Create()
|
||||||
Domoticz.Device(Name="Import Energy", Unit=3, Type=248, Subtype=33, Used=0).Create()
|
#Domoticz.Device(Name="Import Energy", Unit=3, Type=248, Subtype=33, Used=0).Create()
|
||||||
|
Domoticz.Device(Name="Import Energy", Unit=3, Type=0xfa, Subtype=0x01, Used=0).Create()
|
||||||
if 4 not in Devices:
|
if 4 not in Devices:
|
||||||
Domoticz.Device(Name="Voltage", Unit=4, TypeName="Voltage", Used=0).Create()
|
Domoticz.Device(Name="Voltage", Unit=4, TypeName="Voltage", Used=0).Create()
|
||||||
if 5 not in Devices:
|
if 5 not in Devices:
|
||||||
@ -96,6 +99,8 @@ class BasePlugin:
|
|||||||
if 9 not in Devices:
|
if 9 not in Devices:
|
||||||
Options = { "Custom": "1;Hz" }
|
Options = { "Custom": "1;Hz" }
|
||||||
Domoticz.Device(Name="Frequency", Unit=9, TypeName="Custom", Used=0, Options=Options).Create()
|
Domoticz.Device(Name="Frequency", Unit=9, TypeName="Custom", Used=0, Options=Options).Create()
|
||||||
|
if 10 not in Devices:
|
||||||
|
Domoticz.Device(Name="Total Power Meter",Unit=10,Type=0xfa, Subtype=0x01, Used=0).Create()
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -135,6 +140,15 @@ class BasePlugin:
|
|||||||
Devices[7].Update(1, "0")
|
Devices[7].Update(1, "0")
|
||||||
Devices[8].Update(1, "0")
|
Devices[8].Update(1, "0")
|
||||||
Devices[9].Update(1, "0")
|
Devices[9].Update(1, "0")
|
||||||
|
Devices[10].Update(1, "0")
|
||||||
|
|
||||||
|
# 3 counters
|
||||||
|
total_e = "0"
|
||||||
|
export_e = "0"
|
||||||
|
import_e = "0"
|
||||||
|
export_w = 0
|
||||||
|
import_w = 0
|
||||||
|
power = "0"
|
||||||
|
|
||||||
# Total Energy
|
# Total Energy
|
||||||
data = client.read_holding_registers(0, 2)
|
data = client.read_holding_registers(0, 2)
|
||||||
@ -144,9 +158,9 @@ class BasePlugin:
|
|||||||
# Value
|
# Value
|
||||||
value = decoder.decode_32bit_int()
|
value = decoder.decode_32bit_int()
|
||||||
# Scale factor / 100
|
# Scale factor / 100
|
||||||
value = str ( round (value / 100, 3))
|
#value = str ( round (value / 100, 3))
|
||||||
Domoticz.Debug("Value after conversion : "+str(value))
|
#Domoticz.Debug("Value after conversion : "+str(value))
|
||||||
Devices[1].Update(1, value)
|
total_e = str(value)
|
||||||
|
|
||||||
# Export Energy
|
# Export Energy
|
||||||
data = client.read_holding_registers(0x8, 2)
|
data = client.read_holding_registers(0x8, 2)
|
||||||
@ -156,9 +170,9 @@ class BasePlugin:
|
|||||||
# Value
|
# Value
|
||||||
value = decoder.decode_32bit_int()
|
value = decoder.decode_32bit_int()
|
||||||
# Scale factor / 100
|
# Scale factor / 100
|
||||||
value = str ( round (value / 100, 3))
|
#value = str ( round (value / 100, 3))
|
||||||
Domoticz.Debug("Value after conversion : "+str(value))
|
#Domoticz.Debug("Value after conversion : "+str(value))
|
||||||
Devices[2].Update(1, value)
|
export_e = str(value)
|
||||||
|
|
||||||
# Import Energy
|
# Import Energy
|
||||||
data = client.read_holding_registers(0xA, 2)
|
data = client.read_holding_registers(0xA, 2)
|
||||||
@ -168,9 +182,9 @@ class BasePlugin:
|
|||||||
# Value
|
# Value
|
||||||
value = decoder.decode_32bit_int()
|
value = decoder.decode_32bit_int()
|
||||||
# Scale factor / 100
|
# Scale factor / 100
|
||||||
value = str ( round (value / 100, 3))
|
#value = str ( round (value / 100, 3))
|
||||||
Domoticz.Debug("Value after conversion : "+str(value))
|
#Domoticz.Debug("Value after conversion : "+str(value))
|
||||||
Devices[3].Update(1, value)
|
import_e = str(value)
|
||||||
|
|
||||||
# Voltage
|
# Voltage
|
||||||
data = client.read_holding_registers(0xC, 1)
|
data = client.read_holding_registers(0xC, 1)
|
||||||
@ -181,7 +195,7 @@ class BasePlugin:
|
|||||||
value = decoder.decode_16bit_int()
|
value = decoder.decode_16bit_int()
|
||||||
# Scale factor / 10
|
# Scale factor / 10
|
||||||
value = str ( round (value / 10, 3))
|
value = str ( round (value / 10, 3))
|
||||||
Domoticz.Debug("Value after conversion : "+str(value))
|
#Domoticz.Debug("Value after conversion : "+str(value))
|
||||||
Devices[4].Update(1, value)
|
Devices[4].Update(1, value)
|
||||||
|
|
||||||
# Current
|
# Current
|
||||||
@ -193,7 +207,7 @@ class BasePlugin:
|
|||||||
value = decoder.decode_16bit_int()
|
value = decoder.decode_16bit_int()
|
||||||
# Scale factor / 100
|
# Scale factor / 100
|
||||||
value = str ( round (value / 100, 3))
|
value = str ( round (value / 100, 3))
|
||||||
Domoticz.Debug("Value after conversion : "+str(value))
|
#Domoticz.Debug("Value after conversion : "+str(value))
|
||||||
Devices[5].Update(1, value)
|
Devices[5].Update(1, value)
|
||||||
|
|
||||||
# Active Power
|
# Active Power
|
||||||
@ -205,8 +219,13 @@ class BasePlugin:
|
|||||||
value = decoder.decode_16bit_int()
|
value = decoder.decode_16bit_int()
|
||||||
# Scale factor / 100
|
# Scale factor / 100
|
||||||
#value = str ( round (value / 100, 3))
|
#value = str ( round (value / 100, 3))
|
||||||
Domoticz.Debug("Value after conversion : "+str(value))
|
#Domoticz.Debug("Value after conversion : "+str(value))
|
||||||
Devices[6].Update(1, str(value))
|
Devices[6].Update(1, str(value))
|
||||||
|
if value > 0.0:
|
||||||
|
import_w = value
|
||||||
|
if value < 0.0:
|
||||||
|
export_w = value
|
||||||
|
power = str(abs(value))
|
||||||
|
|
||||||
# Reactive Power
|
# Reactive Power
|
||||||
data = client.read_holding_registers(0xF, 1)
|
data = client.read_holding_registers(0xF, 1)
|
||||||
@ -217,7 +236,7 @@ class BasePlugin:
|
|||||||
value = decoder.decode_16bit_int()
|
value = decoder.decode_16bit_int()
|
||||||
# Scale factor / 100
|
# Scale factor / 100
|
||||||
#value = str ( round (value / 100, 3))
|
#value = str ( round (value / 100, 3))
|
||||||
Domoticz.Debug("Value after conversion : "+str(value))
|
#Domoticz.Debug("Value after conversion : "+str(value))
|
||||||
Devices[7].Update(1, str(value))
|
Devices[7].Update(1, str(value))
|
||||||
|
|
||||||
# Power Factor
|
# Power Factor
|
||||||
@ -229,7 +248,7 @@ class BasePlugin:
|
|||||||
value = decoder.decode_16bit_int()
|
value = decoder.decode_16bit_int()
|
||||||
# Scale factor / 1000
|
# Scale factor / 1000
|
||||||
value = str ( round (value / 1000, 3))
|
value = str ( round (value / 1000, 3))
|
||||||
Domoticz.Debug("Value after conversion : "+str(value))
|
#Domoticz.Debug("Value after conversion : "+str(value))
|
||||||
Devices[8].Update(1, value)
|
Devices[8].Update(1, value)
|
||||||
|
|
||||||
# Frequency
|
# Frequency
|
||||||
@ -241,10 +260,16 @@ class BasePlugin:
|
|||||||
value = decoder.decode_16bit_int()
|
value = decoder.decode_16bit_int()
|
||||||
# Scale factor / 100
|
# Scale factor / 100
|
||||||
value = str ( round (value / 100, 3))
|
value = str ( round (value / 100, 3))
|
||||||
Domoticz.Debug("Value after conversion : "+str(value))
|
#Domoticz.Debug("Value after conversion : "+str(value))
|
||||||
Devices[9].Update(1, value)
|
Devices[9].Update(1, value)
|
||||||
|
|
||||||
|
|
||||||
|
# Do insert data on counters
|
||||||
|
Devices[1].Update(1, sValue=total_e+"0;0;0;0;"+power+";0")
|
||||||
|
Devices[2].Update(1, sValue=export_e+"0;0;0;0;"+str(abs(export_w))+";0")
|
||||||
|
Devices[3].Update(1, sValue=import_e+"0;0;0;0;"+str(abs(import_w))+";0")
|
||||||
|
Devices[10].Update(1, sValue=import_e+"0;0;"+export_e+"0;0;"+str(abs(import_w))+";"+str(abs(export_w)))
|
||||||
|
|
||||||
|
|
||||||
global _plugin
|
global _plugin
|
||||||
_plugin = BasePlugin()
|
_plugin = BasePlugin()
|
||||||
|
|||||||
Reference in New Issue
Block a user