Dynamic Device Creation?

Posted on
Fri Feb 19, 2021 11:33 am
autolog offline
Posts: 3500
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Dynamic Device Creation?

At the moment, in my under development plugin to link to Hubitat, I have created a number of devices in devices.xml, each with a device type such as relay, thermostat, sensor etc.

I was wondering if it is possible just to define one device type i.e. custom with all the properties associated with the other device types and just switch on the properties specific to a particular device type. Then when the device is created, to dynamically change the device type from custom to say relay?

I think the device type needs to be specific as a number of other plugins check for specific device types, e.g. Occupatum for sensors with on/off. I want the linked Hubitat devices to work with existing plugins as if they were native Indigo devices.

At the moment I am only creating one device per Hubitat device but I think a number of devices would benefit from using the Factory model which would be more Indigo like.
Is the removal of the User

At the moment, the devices defined in devices.xml share a lot of common fields e.g. selecting hub and device, listing properties of the device and selecting which ones to enable. This means a lot of cutting and pasting when things are changed as the plugin is developed.

I suspect the answer is going to no, but thought I would ask. :)

Posted on
Fri Feb 19, 2021 3:07 pm
FlyingDiver offline
User avatar
Posts: 5321
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Dynamic Device Creation?

Yeah, I've done this a couple times. Check out the code for https://github.com/FlyingDiver/Indigo-RFPlayer

The XML file has a bare-bones definition for a "Discovered Device". When the device is created, the protocol module for the device type sets up the device with all the appropriate features. The oregon.py module is probably the best example.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Fri Feb 19, 2021 3:27 pm
matt (support) offline
Site Admin
User avatar
Posts: 20539
Joined: Jan 27, 2003
Location: Texas

Re: Dynamic Device Creation?

autolog wrote:
At the moment, the devices defined in devices.xml share a lot of common fields e.g. selecting hub and device, listing properties of the device and selecting which ones to enable. This means a lot of cutting and pasting when things are changed as the plugin is developed.

I think we can attack this problem a bit differently than trying to dynamically switch the device type.

Indigo's XML parser has the ability to substitute in an array of <Field> nodes from another file, so you can put all the reusable properties/UI into its own file. Its use it documented here. I use this technique for Indigo's Z-Wave plugin devices.

Image

Posted on
Sat Feb 20, 2021 7:19 am
autolog offline
Posts: 3500
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: Dynamic Device Creation?

matt (support) wrote:
autolog wrote:
At the moment, the devices defined in devices.xml share a lot of common fields e.g. selecting hub and device, listing properties of the device and selecting which ones to enable. This means a lot of cutting and pasting when things are changed as the plugin is developed.

I think we can attack this problem a bit differently than trying to dynamically switch the device type.

Indigo's XML parser has the ability to substitute in an array of <Field> nodes from another file, so you can put all the reusable properties/UI into its own file. Its use it documented here. I use this technique for Indigo's Z-Wave plugin devices.

Thanks Matt - I had forgotten about that feature. Now implemented. :D

Posted on
Sat Feb 20, 2021 7:27 am
autolog offline
Posts: 3500
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: Dynamic Device Creation?

FlyingDiver wrote:
Yeah, I've done this a couple times. Check out the code for https://github.com/FlyingDiver/Indigo-RFPlayer

The XML file has a bare-bones definition for a "Discovered Device". When the device is created, the protocol module for the device type sets up the device with all the appropriate features. The oregon.py module is probably the best example.

I think the template solution will work for me.

However, thanks for the link to your plugin. I have been studying the oregon.py file with interest. It certainly gives me food for thought. :)

Posted on
Sat Feb 20, 2021 7:35 am
DaveL17 offline
User avatar
Posts: 5900
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Dynamic Device Creation?

matt (support) wrote:
Indigo's XML parser has the ability to substitute in an array of <Field> nodes from another file, so you can put all the reusable properties/UI into its own file. Its use it documented here. I use this technique for Indigo's Z-Wave plugin devices.

Templates are a super feature, which I use as much as possible. I use them "internally" with plugins when I'm repeating the same control for multiple plugin devices, but I also use them "externally" where I use the same XML blocks across multiple plugins. For example, my plugin preferences debug logging settings are the same in all my plugins -- so I can tweak the code in one place.

<OT> I also use symlinked files in a similar way. For example, I use a single file to build the footers of all my plugin wikis. </OT>

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest