Page 1 of 1

Add custom icons from pyhton plugin

Posted: Tuesday 21 May 2019 14:21
by ag74
Hi,

I've been trying to add custom icons for a plugin as described in the wiki page https://www.domoticz.com/wiki/Developin ... gin#Images but it doesn't work as expected.

Here's my code in the onStart callback:

Code: Select all

if 'girl' not in Images:
	Domoticz.Image( Filename='girl_icons.zip' ).Create()
if 'boy' not in Images:
	Domoticz.Image( Filename='boy_icons.zip' ).Create()
	
if deviceIdx not in Devices:
	Domoticz.Device(	Unit = deviceIdx, 
				Name = user, 
				Type = 244, 
				Subtype = 62, 
				Switchtype = 2, 
				Image = Images[ 'boy' ].ID, 
				Options = { 'mac' : mac },
				Used = 0 ).Create()
The icons are correctly inserted in the database and I can see them in the custom icons web page but when checking the python variable Images they are not always defined in it.Sometimes both are defined and sometimes only one is defined so they get always created.

Plus, the 'girl' icons are correctly displayed but the 'boy' icons are not displayed, a light bulb is displayed instead but as I sayed I can see them in the custom icons web page (see attached screenshot). The zip files are attached to this message.

Any ideas of I'm missing ?

Re: Add custom icons from pyhton plugin

Posted: Tuesday 25 August 2020 23:49
by kurt
Hi, i was struggling with the same for a whole day.
Solution is simple, you MUST TO name file beginings with key from your XML file in plugin.
In my example:
<plugin key="eSterownik" name="eSterownik.pl v1.0" author="Kurt" ....

and zip file should be f.e. Pump.zip
in file should be:
icons.txt (containing only one line: eSterownikPump;Pump;Pompa Logo)
and pictures:
eSterownikPump48_On.png
eSterownikPump48_Off.png
eSterownikPump.png

And in code you do:

Code: Select all

if 'Feeder' not in Images:
	Domoticz.Image(Filename='Feeder.zip').Create()
if 'Pump' not in Images:
        Domoticz.Image(Filename='Pump.zip').Create()

Domoticz.Device(Name=device_name, Unit=i + 1, DeviceID=device_id, Type=244,Subtype=73, Switchtype=11, Used=1, Image=Images['eSterownikPump'].ID).Create()
Domoticz.Device(Name=device_name, Unit=i + 1, DeviceID=device_id, Type=244, Subtype=73, Switchtype=11, Image=Images['eSterownikFeeder'].ID, Used=1).Create()

Domoticz docs SUX!
Devs if You read this, please make the wiki more usable, or add some docs for someone who wants to develop sth more than bash scripts sending data to dummy switches;-)

Re: Add custom icons from pyhton plugin

Posted: Sunday 06 September 2020 17:49
by 0rsa
@kurt I love you

Re: Add custom icons from pyhton plugin

Posted: Thursday 10 September 2020 10:19
by mariopeters
Orsa,
you could also look in my Domoticz Home-Connect plugin (https://github.com/mario-peters/Domotic ... ect-Plugin) for an example of changing an icon runtime?

Re: Add custom icons from pyhton plugin

Posted: Saturday 12 September 2020 10:58
by Snake40
Hello
Is it possible to have the full python plugin program working?
Originally I have the same problem with changing icons but I don't know anything about python so I'm not sure how to change the program that was not working to one that was working taking kurt's remarks into account. ..
Thank you in advance.

Re: Add custom icons from pyhton plugin

Posted: Tuesday 15 September 2020 13:37
by mariopeters
I think what's going wrong is the filename.
It must be the same pattern as the name of the plugin with a number attached.
Just look at my example.

Re: Add custom icons from pyhton plugin

Posted: Saturday 17 October 2020 20:53
by gekk
kurt wrote: Tuesday 25 August 2020 23:49 Hi, i was struggling with the same for a whole day.
Solution is simple, you MUST TO name file beginings with key from your XML file in plugin.
In my example:
<plugin key="eSterownik" name="eSterownik.pl v1.0" author="Kurt" ....

and zip file should be f.e. Pump.zip
in file should be:
icons.txt (containing only one line: eSterownikPump;Pump;Pompa Logo)
and pictures:
eSterownikPump48_On.png
eSterownikPump48_Off.png
eSterownikPump.png

And in code you do:

Code: Select all

if 'Feeder' not in Images:
	Domoticz.Image(Filename='Feeder.zip').Create()
if 'Pump' not in Images:
        Domoticz.Image(Filename='Pump.zip').Create()

Domoticz.Device(Name=device_name, Unit=i + 1, DeviceID=device_id, Type=244,Subtype=73, Switchtype=11, Used=1, Image=Images['eSterownikPump'].ID).Create()
Domoticz.Device(Name=device_name, Unit=i + 1, DeviceID=device_id, Type=244, Subtype=73, Switchtype=11, Image=Images['eSterownikFeeder'].ID, Used=1).Create()
Domoticz docs SUX!
Devs if You read this, please make the wiki more usable, or add some docs for someone who wants to develop sth more than bash scripts sending data to dummy switches;-)
Wow, kurt, are you working on esterownik plugin ? Will you make it public available ? I was just thinking about the same, but if there would be something already existing, I dont want to reinvent wheel :-)