With the attached plugin it creates a device, but then when you are updating switchtype .... it create a 2nd entry in the DeviceStatus
26|13|Test Widget|1|Test Widget 1|0|241|7|8|0|12|255|0||2024-02-13 18:55:01|26|0.0|1.0|0.0|1.0|||0|0|0||||0
27|13|Test Widget|1|Test Widget 1|0|244|73|0|0|12|255|0||2024-02-13 18:54:31|27|0.0|1.0|0.0|1.0|||0|0|0||||0
Code: Select all
"""
<plugin key="UpdateType" name="Updating SwitchType ..." author="pipiche" version="0.1" externallink="">
<params>
<param field="Mode6" label="Debugging" width="150px" default="None" required="true">
<description><br/><h3>Plugin debug</h3>This debugging option has been moved to the WebUI > Tools > Debug<br/></description>
<options>
<option label="None" value="0" default="true" />
<option label="Python Only" value="2"/>
<option label="Basic Debugging" value="62"/>
<option label="Basic+Messages" value="126"/>
<option label="Connections Only" value="16"/>
<option label="Connections+Queue" value="144"/>
<option label="All" value="-1"/>
</options>
</param>
</params>
</plugin>
"""
HEARTBEAT_FEQ = 30
NUMBER_UNIT = 1
import DomoticzEx as Domoticz
DOMOTICZ_EXTENDED_API = True
DEVICE_ID = "Test Widget"
class BasePlugin:
def __init__(self):
self.plugin_ready = False
self.count = 0
return
def onStart(self):
Domoticz.Log('onStart called %s' % DOMOTICZ_EXTENDED_API)
for unit in range(0, NUMBER_UNIT):
device_unit = unit +1
device_create_unit(self, Devices, DEVICE_ID, "Test Widget %s" % device_unit, device_unit)
# Set plugin heartbeat to 1s
Domoticz.Heartbeat(HEARTBEAT_FEQ)
def onHeartbeat(self):
Domoticz.Debug('onHeartbeat called')
for unit in range(0, NUMBER_UNIT):
device_unit = unit +1
if self.count % 2 == 0:
domo_update_witchType_SubType_Type(self, Devices, DEVICE_ID, device_unit, Type_=244, Subtype_=73, Switchtype_=0)
else:
domo_update_witchType_SubType_Type(self, Devices, DEVICE_ID, device_unit, Type_=241, Subtype_=7, Switchtype_=7)
self.count += 1
def onCommand(self, Unit, Command, Level, Hue):
Domoticz.Debug('onCommand called')
def onStop(self):
Domoticz.Debug('onStop called')
def device_create_unit(self, Devices, deviceId, Name, unit):
if DOMOTICZ_EXTENDED_API:
if deviceId in Devices and unit in Devices[deviceId].Units:
return
elif not DOMOTICZ_EXTENDED_API and unit in Devices:
return
Domoticz.Log('device_create_unit %s %s/%s' % (Name, deviceId ,unit))
domoticz_device_api_class = Domoticz.Unit if DOMOTICZ_EXTENDED_API else Domoticz.Device
myDev = domoticz_device_api_class(Name=str(Name),DeviceID=str(deviceId), Unit=unit, Type=241, Subtype=7, Switchtype=8 )
myDev.Create()
Domoticz.Log('device_create_unit %s/%s %s created!!!' % (deviceId ,unit, myDev))
def domo_update_witchType_SubType_Type(self, Devices, DeviceID_, Unit_, Type_=0, Subtype_=0, Switchtype_=0):
Domoticz.Log('domo_update_witchType_SubType_Type %s/%s %s %s %s' % (DeviceID_ ,Unit_, Type_, Subtype_, Switchtype_))
if DOMOTICZ_EXTENDED_API:
Devices[DeviceID_].Units[Unit_].Type = Type_
Devices[DeviceID_].Units[Unit_].SubType = Subtype_
Devices[DeviceID_].Units[Unit_].SwitchType = Switchtype_
Devices[DeviceID_].Units[Unit_].Update(Log=True)
return
nValue = Devices[Unit_].nValue
sValue = Devices[Unit_].sValue
Devices[Unit_].Update(nValue, sValue, Type=Type_, SubType=Subtype_, SwitchType=Switchtype_)
global _plugin
_plugin = BasePlugin()
def onStart():
global _plugin
_plugin.onStart()
def onStop():
global _plugin
_plugin.onStop()
def onHeartbeat():
global _plugin
_plugin.onHeartbeat()
def onCommand(Unit, Command, Level, Hue):
global _plugin
_plugin.onCommand(Unit, Command, Level, Hue)
Logs produced by the plugin. we can see
Code: Select all
CSQLHelper::UpdateValueInt: Notifying plugin 13 about creation of device 1
Feb 13 18:52:01 rasp domoticz[18624]: 2024-02-13 18:52:01.367 Update Device: onStart called True
Feb 13 18:52:31 rasp domoticz[18624]: 2024-02-13 18:52:31.079 Update Device: domo_update_witchType_SubType_Type Test Widget/1 244 73 0
Feb 13 18:52:31 rasp domoticz[18624]: 2024-02-13 18:52:31.082 Debug: CSQLHelper::UpdateValueInt: Notifying plugin 13 about creation of device 1
Feb 13 18:53:01 rasp domoticz[18624]: 2024-02-13 18:53:01.087 Update Device: domo_update_witchType_SubType_Type Test Widget/1 241 7 7