Customize plugin for personal usage
This commit is contained in:
41
plugin.py
41
plugin.py
@@ -175,7 +175,8 @@ class BasePlugin:
|
||||
# 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
|
||||
|
||||
#######################################################################
|
||||
@@ -306,7 +307,9 @@ class BasePlugin:
|
||||
#
|
||||
#######################################################################
|
||||
def onStart(self):
|
||||
|
||||
#Hearthbeat
|
||||
Domoticz.Heartbeat(self.__HB)
|
||||
|
||||
# Debug mode
|
||||
Domoticz.Debugging(int(Parameters["Mode6"]))
|
||||
Domoticz.Debug("onStart called")
|
||||
@@ -347,22 +350,22 @@ class BasePlugin:
|
||||
self.__unit2dps_id_list[max_unit].append(int(val))
|
||||
max_unit = max_unit + 1
|
||||
|
||||
#create domoticz devices
|
||||
#create domoticz devices
|
||||
if(len(Devices) == 0):
|
||||
for val in self.__unit2dps_id_list:
|
||||
|
||||
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.")
|
||||
## After the last DPS add the global devices
|
||||
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.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.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.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.")
|
||||
|
||||
else: #group: selector switch
|
||||
@@ -370,7 +373,7 @@ class BasePlugin:
|
||||
"LevelNames": "Off|On",
|
||||
"LevelOffHidden": "false",
|
||||
"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.")
|
||||
|
||||
#manage always on
|
||||
@@ -437,16 +440,16 @@ class BasePlugin:
|
||||
return
|
||||
|
||||
error = False
|
||||
for key in self.__plugs:
|
||||
for key in self.__plugs:
|
||||
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+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+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.__watt)]/10) + " Watt Key is:" + str(key+12))
|
||||
Domoticz.Debug("Updated: " + str(state[str(self.__voltage)]/10) + " Voltage Key is:" + str(key+13))
|
||||
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+3].Update(0,str(state[str(self.__voltage)]/10)) # TypeName="Voltage"
|
||||
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.__watt)]/10) + " Watt Key is:" + str(key+4))
|
||||
Domoticz.Debug("Updated: " + str(state[str(self.__voltage)]/10) + " Voltage Key is:" + str(key+3))
|
||||
|
||||
if(error):
|
||||
self.__command_to_execute()
|
||||
@@ -492,7 +495,7 @@ class BasePlugin:
|
||||
#######################################################################
|
||||
def onHeartbeat(self):
|
||||
self.__runAgain -= 1
|
||||
if(self.__runAgain == 0):
|
||||
if(self.__runAgain <= 0):
|
||||
self.__command_to_execute()
|
||||
|
||||
#######################################################################
|
||||
|
||||
Reference in New Issue
Block a user