Customize plugin for personal usage

This commit is contained in:
2021-05-24 11:00:26 +02:00
parent 1b35f60894
commit 3f94318856

View File

@@ -175,7 +175,8 @@ class BasePlugin:
# constant definition # constant definition
# #
####################################################################### #######################################################################
__HB_BASE_FREQ = 2 #heartbeat frequency (val x 10 seconds) __HB_BASE_FREQ = 1 #heartbeat frequency (val x __HB seconds)
__HB = 10 #hDomoticz.heartbeat (seconds)
__VALID_CMD = ('On','Off') #list of valid command __VALID_CMD = ('On','Off') #list of valid command
####################################################################### #######################################################################
@@ -306,6 +307,8 @@ class BasePlugin:
# #
####################################################################### #######################################################################
def onStart(self): def onStart(self):
#Hearthbeat
Domoticz.Heartbeat(self.__HB)
# Debug mode # Debug mode
Domoticz.Debugging(int(Parameters["Mode6"])) Domoticz.Debugging(int(Parameters["Mode6"]))
@@ -352,17 +355,17 @@ class BasePlugin:
for val in self.__unit2dps_id_list: for val in self.__unit2dps_id_list:
if(val <= max_dps): #single socket dps if(val <= max_dps): #single socket dps
Domoticz.Device(Name="Tuya SmartPlug (Switch)", Unit=val, TypeName="Switch").Create() Domoticz.Device(Name="Switch", Unit=val, TypeName="Switch", Image=1, Used=0).Create()
Domoticz.Log("Tuya SmartPlug Device (Switch) #" + str(val) +" created.") Domoticz.Log("Tuya SmartPlug Device (Switch) #" + str(val) +" created.")
## After the last DPS add the global devices ## After the last DPS add the global devices
if(val == max_dps): if(val == max_dps):
Domoticz.Device(Name="Tuya SmartPlug (A)" , Unit=val+1, TypeName="Current (Single)").Create() Domoticz.Device(Name="A" , Unit=val+1, TypeName="Current (Single)", Used=0).Create()
Domoticz.Log("Tuya SmartPlug Device (A) #" + str(val+1) +" created.") Domoticz.Log("Tuya SmartPlug Device (A) #" + str(val+1) +" created.")
Domoticz.Device(Name="Tuya SmartPlug (kWh)", Unit=val+2, TypeName="kWh").Create() Domoticz.Device(Name="kWh", Unit=val+2, TypeName="kWh", Used=0).Create()
Domoticz.Log("Tuya SmartPlug Device kWh #" + str(val+2) +" created.") Domoticz.Log("Tuya SmartPlug Device kWh #" + str(val+2) +" created.")
Domoticz.Device(Name="Tuya SmartPlug (V)", Unit=val+3, TypeName="Voltage").Create() Domoticz.Device(Name="V", Unit=val+3, TypeName="Voltage", Used=0).Create()
Domoticz.Log("Tuya SmartPlug Device (V) #" + str(val+3) +" created.") Domoticz.Log("Tuya SmartPlug Device (V) #" + str(val+3) +" created.")
Domoticz.Device(Name="Tuya SmartPlug (W)", Unit=val+4, TypeName="Usage").Create() Domoticz.Device(Name="W", Unit=val+4, TypeName="Usage", Used=0).Create()
Domoticz.Log("Tuya SmartPlug Device (W) #" + str(val+4) +" created.") Domoticz.Log("Tuya SmartPlug Device (W) #" + str(val+4) +" created.")
else: #group: selector switch else: #group: selector switch
@@ -370,7 +373,7 @@ class BasePlugin:
"LevelNames": "Off|On", "LevelNames": "Off|On",
"LevelOffHidden": "false", "LevelOffHidden": "false",
"SelectorStyle": "0"} "SelectorStyle": "0"}
Domoticz.Device(Name="Tuya SmartPlug #" + str(val), Unit=val, TypeName="Selector Switch", Options=Options).Create() Domoticz.Device(Name="Tuya SmartPlug #" + str(val), Unit=val, TypeName="Selector Switch", Options=Options, Used=0).Create()
Domoticz.Log("Tuya SmartPlug Device #" + str(val) +" created.") Domoticz.Log("Tuya SmartPlug Device #" + str(val) +" created.")
#manage always on #manage always on
@@ -439,14 +442,14 @@ class BasePlugin:
error = False error = False
for key in self.__plugs: for key in self.__plugs:
error = error or self.__plugs[key].update_state(state[str(key)]) error = error or self.__plugs[key].update_state(state[str(key)])
Devices[key+1].Update(0,str(state[str(self.__ampere)]/1000)) # TypeName="Current (Single) Devices[key+1].Update(0,str(state[str(self.__ampere)]/1000)) # TypeName="Current (Single)
Devices[key+2].Update(0,str(state[str(self.__watt)]/10) + ";0") # kWh / Calculated Devices[key+2].Update(0,str(state[str(self.__watt)]/10) + ";0") # kWh / Calculated
Devices[key+3].Update(0,str(state[str(self.__voltage)]/10)) # TypeName="Voltage" Devices[key+3].Update(0,str(state[str(self.__voltage)]/10)) # TypeName="Voltage"
Devices[key+4].Update(0,str(state[str(self.__watt)]/10)) # TypeName="Usage" Devices[key+4].Update(0,str(state[str(self.__watt)]/10)) # TypeName="Usage"
Domoticz.Debug("Updated: " + str(state[str(self.__ampere)]/1000) + " Ampere Key is:" + str(key+1)) Domoticz.Debug("Updated: " + str(state[str(self.__ampere)]/1000) + " Ampere Key is:" + str(key+1))
Domoticz.Debug("Updated: " + str(state[str(self.__watt)]/10) + " Watt Key is:" + str(key+12)) Domoticz.Debug("Updated: " + str(state[str(self.__watt)]/10) + " Watt Key is:" + str(key+4))
Domoticz.Debug("Updated: " + str(state[str(self.__voltage)]/10) + " Voltage Key is:" + str(key+13)) Domoticz.Debug("Updated: " + str(state[str(self.__voltage)]/10) + " Voltage Key is:" + str(key+3))
if(error): if(error):
self.__command_to_execute() self.__command_to_execute()
@@ -492,7 +495,7 @@ class BasePlugin:
####################################################################### #######################################################################
def onHeartbeat(self): def onHeartbeat(self):
self.__runAgain -= 1 self.__runAgain -= 1
if(self.__runAgain == 0): if(self.__runAgain <= 0):
self.__command_to_execute() self.__command_to_execute()
####################################################################### #######################################################################