Page 1 of 1

Basic plugin with DomoticzEx question

Posted: Tuesday 06 December 2022 21:00
by brjhaverkamp
Hello all,

I am trying to create a plugin, based on the Basetemplate.py
I am able to create some devices (or are they called units now?

Code: Select all

BurnerSwitch = Domoticz.Unit(Name="BurnerSwitch", DeviceID="AduroHx", Unit=1, Type=244, Subtype=73, Switchtype=0).Create()
But I am not able to use the devices that are created.
It shows up under switches. But when I click the lightbulb it doesn't switch on.
It does call the onCommand callback and I can e.g. print something to the log, but I can not figure out how to change the state of the switch.
I'm pretty sure I'm missing something obvious. But most examples are still based on the old Domoticz framework, instead of DomoticzEx.

Can anyone give me a pointer?

Regards,

Bert

Re: Basic plugin with DomoticzEx question

Posted: Tuesday 06 December 2022 21:56
by waltervl
Zigbee2mqtt plugin is DomoticzEx so that could give some inspiration (I am not a programmer)

Re: Basic plugin with DomoticzEx question

Posted: Wednesday 07 December 2022 20:57
by brjhaverkamp
Hi Waltervl,

Thanks. Indeed it is one of the few I could find. But the onCommand doesn't seem to have an update function. Or at least not that I could find/recognise.

I now got it working with the following code. But is this indeed the expected way? It looks quite convoluted. so any suggestion/advice is welcome.

Code: Select all

def onCommand(self, DeviceID, Unit, Command, Level, Color):
        Domoticz.Log("onCommand called for Device " + str(DeviceID) + " Unit " + str(Unit) + ": Parameter '" + str(Command) + "', Level: " + str(Level))
        if Devices[DeviceID].Units[Unit].nValue == 1:
            Domoticz.Log("Switching off: ")
            Devices[DeviceID].Units[Unit].nValue= 0
            Devices[DeviceID].Units[Unit].sValue= "Off"
            Devices[DeviceID].Units[Unit].Update()
        else:
            Domoticz.Log("Switching on")
            Devices[DeviceID].Units[Unit].nValue= 1
            Devices[DeviceID].Units[Unit].sValue= "On"
            Devices[DeviceID].Units[Unit].Update()

Re: Basic plugin with DomoticzEx question

Posted: Wednesday 07 December 2022 23:06
by waltervl
Sorry, as mentioned I am not a programmer.

Re: Basic plugin with DomoticzEx question

Posted: Thursday 08 December 2022 0:20
by waltervl

Re: Basic plugin with DomoticzEx question

Posted: Thursday 22 December 2022 18:41
by brjhaverkamp
Hi Waltervi,

Just to close this thread: Thanks for the example!!.
It helped a lot! I got my basic Aduro plugin working.
Now working on expanding and cleaning up!
Regards,

Bert