Page 1 of 1

python hardware plugin - one instance per device ?!?

Posted: Sunday 02 March 2025 17:35
by AchilleTalon
Hello all,

I already have developped a couple of simple python plugins (very specific, fixed and predifined number of devices), but I'd like to create a more flexible hardware device. A good starting point for me would be to buil a plugin based on pyShelly (I have plenty of those and already have a good knowledge of this library).

Since I coulnd't find a way to provide then store information relative to the devices that would be created through this plugin, here are my questions:

One way to do things would be to have one instance of the plugin for each and every device I want to create.
??? Is this the way to go? ???

It would definitely work, but how efficient would it be? I would have to run several instances, possibly leading to a lot of resources, more than if I could manage everything in the same session.

Any help or advice will be really appreciated. Thank you in advance.

Re: python hardware plugin - one instance per device ?!?

Posted: Sunday 02 March 2025 22:31
by waltervl
Running a plugin instance per Shelly device seems not logical, especially if you have a lot of devices.

You can look at the abandoned Shelly MQTT plugin how the author has set it it up to identify each shelly device. https://github.com/enesbcs/Shelly_MQTT

Sometimes you also see that the plugin maintaines a simple text device list with some extra information. See for example the Zigbee4Domoticz plugin. But that is a very big plugin so be warned... :)

Re: python hardware plugin - one instance per device ?!?

Posted: Sunday 02 March 2025 23:54
by FlyingDomotic
Anyway, even if this is not the best solution, it's always possible for a plugin to read/store data into a json file in plugin's folder.

Re: python hardware plugin - one instance per device ?!?

Posted: Monday 03 March 2025 17:49
by waltervl
Also check this Shelly Cloud plugin for a start: https://github.com/mario-peters/ShellyCloudPlugin2

Re: python hardware plugin - one instance per device ?!?

Posted: Tuesday 04 March 2025 7:53
by AchilleTalon
Thank you all for your replies. I needed that little push to really get into this. I'll look into these examples.

Re: python hardware plugin - one instance per device ?!?

Posted: Wednesday 26 March 2025 22:28
by JanJaap
it really depends on the type of info you want to store. If this info is obtained at startup you can simply do it in memory. I contributed to the sOMFY PLUGIN where the device id is storing the device address which is not visible on the UI (you do see it in the device list page) which provides a nice scalable setup for a variable devicelist (the mentioned zigbee2mqtt plugin does something similar but then more elaborate/complicated)