Page 1 of 1

Request: Icon change by dzvents in a selector switch

Posted: Monday 01 April 2019 11:48
by EddyG
I would like to change to icon of a selector switch by dzVents according to the level.

Re: Request: Icon change by dzvents in a selector switch

Posted: Monday 01 April 2019 13:43
by waaren
EddyG wrote: Monday 01 April 2019 11:48 I would like to change to icon of a selector switch by dzVents according to the level.
Attached script works for me.
The icon Numbers can be found by changing the icon manually using the GUI and peek in the database to see the result in the custom image field. Could be there is an easier way to get these ?

I don't think this function will make it as a native dzVents command but if it's useful for you and you want to use it for multiple devices and and if you experience no side effects, you can implement it as a global helper function.

Code: Select all

-- Icon changer

return  {   on =    {  
                       devices         = {1423}, -- change to your device
                    },

        logging = 
                    {
                        level       = domoticz.LOG_DEBUG,  -- switch to LOG_ERROR when OK
                        marker      = 'setIcon'
                    },

    execute = function(dz, item)

        local icons =     { -- level = iconNumber 
                            [0]  = 10,
                            [10] = 13,
                            [20] = 16,
                            [30] = 14,
                            [40] = 14,
                            [50] = 14,
                            [60] = 14,
                        }
        
        local function setIcon(iconNumber) 
            local url = dz.settings['Domoticz url'] .. '/json.htm?type=setused&used=true&name=' .. dz.utils.urlEncode(item.name) ..
            '&description=' .. dz.utils.urlEncode(item.description) .. -- Required. If not set it will be blanked out.
            '&idx=' .. item.id .. 
            '&switchtype=' .. item.switchTypeValue ..
            '&customimage=' .. iconNumber
            return dz.openURL(url)
        end    
        
        if item.level ~= item.lastLevel then 
            setIcon(icons[item.level])
        else
            dz.log('No Icon change necessary' .. item.id,dz.LOG_DEBUG)
        end
    end
}

Re: Request: Icon change by dzvents in a selector switch

Posted: Monday 01 April 2019 20:02
by EddyG
Perfect, TNX. :D I try it to morrow.

Re: Request: Icon change by dzvents in a selector switch

Posted: Tuesday 02 April 2019 16:00
by EddyG
Tnx again. It works perfectly. Now hunting for nice icons which fit my purpose. :D

Re: Request: Icon change by dzvents in a selector switch

Posted: Tuesday 13 October 2020 12:57
by Larsoss
Which program is the best way to see what the IconNumber is in the DB?

Re: Request: Icon change by dzvents in a selector switch

Posted: Tuesday 13 October 2020 13:07
by erem
@Larsoss

i use sqlitebrowser (sudo apt-get install sqlitebrowser) on buster.
Works well.

Re: Request: Icon change by dzvents in a selector switch  [Solved]

Posted: Tuesday 13 October 2020 13:17
by waaren
Larsoss wrote: Tuesday 13 October 2020 12:57 Which program is the best way to see what the IconNumber is in the DB?
sqlitebrowser does require a GUI to linux

Any sqlite db browser will do. I mostly use sqlite3 on Linux. Look for CustomImage field in DeviceStatus table.
Using dzVents you can set the icon on devicetypes for which it is allowed with the setIcon function.