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

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Request: Icon change by dzvents in a selector switch

Post by EddyG »

I would like to change to icon of a selector switch by dzVents according to the level.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

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

Post by EddyG »

Perfect, TNX. :D I try it to morrow.
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

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

Post by EddyG »

Tnx again. It works perfectly. Now hunting for nice icons which fit my purpose. :D
Larsoss
Posts: 65
Joined: Friday 18 March 2016 10:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

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

Post by Larsoss »

Which program is the best way to see what the IconNumber is in the DB?
Raspberry 4 - USB boot Domoticz /|\ Raspberry 2B - Dashticz /|\ Tasmota device's /|\ Philips Hue & Yeelight
User avatar
erem
Posts: 230
Joined: Tuesday 27 March 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Amsterdam/netherlands
Contact:

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

Post by erem »

@Larsoss

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

Rob
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest