Selectord.lastLevel never takes the value 0

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

Moderator: leecollings

Post Reply
boggiz
Posts: 46
Joined: Thursday 07 March 2019 11:40
Target OS: NAS (Synology & others)
Domoticz version: 2024.4
Location: France
Contact:

Selectord.lastLevel never takes the value 0

Post by boggiz »

Hi all,
I am trying to program a watering selector so as not to disrupt a watering in progress: it is mandatory to go through STOP before changing the watering mode.
When level 0 is hidden my script works correctly but the icon remains blue even in the STOP position which is not normal.
On the other hand, when I activate level 0 the script does not work because devSel.lastLevel never takes the value 0. On the other hand, the icon becomes grayed out which I like more.
Image

Code: Select all

	execute = function(dz, item)
	    local devSel = dz.devices('Arrosage')
        local varEtat = dz.variables('Etat Arrosage Auto')

            print('==> Selecteur NEW = ' .. devSel.level)
            print('==> Selecteur LAST = ' .. devSel.lastLevel)
            
        -- Selecteur sur Auto ou Auto fixe
        if devSel.level > 30 then 
            varEtat.set ('Manuel') 
        elseif  devSel.level > 10 then 
                varEtat.set ('En cours')
            else
                varEtat.set ('Terminé')
                print('Color ' ..devSel.getColor)
                devSel.icon= Light
                devSel.setHotWater(true) -- non defini

            end
    
        if  devSel.level > 10 and devSel.lastLevel > 10  then   -- <> de STOP on interdit la maj
                devSel.switchSelector(devSel.lastLevel).silent()
        end
    end
Do you know how to either change the color of the STOP icon or force devSel.lastLevel = 0?
NAS Syno DS718+ with 12Go ram
RFXtrx433XL v1044 with 3dBi antenna
Domoticz 2024.4 on Docker
TFA rain gauge, 4 ways automatic watering program, LINKY consumption, waterflow counter
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Selectord.lastLevel never takes the value 0

Post by waaren »

boggiz wrote: Monday 05 April 2021 21:11 Do you know how to either change the color of the STOP icon or force devSel.lastLevel = 0?
The lastLevel is not set to 0 when switching the selector to Off.
You will have to store the level yourself. You can do that using a uservariable or (like in below example) using dzVents persistent storage.

Code: Select all

return
{
    on =
    {
        devices =
        {
            'Arrosage'
        },
    },
    data =
    {
        lastLevel =
        {
            initial = -1,
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'selectorStop',
    },

    execute = function(dz, item)

        local devSel = dz.devices('Arrosage')
        local varEtat = dz.variables('Etat Arrosage Auto')

        dz.log('==> Selecteur NEW = ' .. devSel.level,dz.LOG_DEBUG)
        dz.log('==> Selecteur LAST = ' .. devSel.lastLevel,dz.LOG_DEBUG)

        -- Selecteur sur Auto ou Auto fixe
        if devSel.level > 30 then
            varEtat.set ('Manuel')
        elseif devSel.level > 10 then
            varEtat.set ('En cours')
        else
            varEtat.set ('Terminé')
            dz.log('Color ' .. devSel.getColor,dz.LOG_DEBUG)
            devSel.icon= Light
            devSel.setHotWater(true) -- non defini
        end

        if  devSel.level > 10 and dz.data.lastLevel > 10  then   -- <> de STOP on interdit la maj
            devSel.switchSelector(dz.data.lastLevel).silent()
        end
        dz.data.lastLevel = devSel.level
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
boggiz
Posts: 46
Joined: Thursday 07 March 2019 11:40
Target OS: NAS (Synology & others)
Domoticz version: 2024.4
Location: France
Contact:

Re: Selectord.lastLevel never takes the value 0

Post by boggiz »

Thank you Waaren for your response.
So I'll go through a persistent variable to store lastLevel.
Is this a bug or was it intended?
NAS Syno DS718+ with 12Go ram
RFXtrx433XL v1044 with 3dBi antenna
Domoticz 2024.4 on Docker
TFA rain gauge, 4 ways automatic watering program, LINKY consumption, waterflow counter
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Selectord.lastLevel never takes the value 0

Post by waaren »

boggiz wrote: Tuesday 06 April 2021 10:28 Is this a bug or was it intended?
It is intended.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
boggiz
Posts: 46
Joined: Thursday 07 March 2019 11:40
Target OS: NAS (Synology & others)
Domoticz version: 2024.4
Location: France
Contact:

Re: Selectord.lastLevel never takes the value 0

Post by boggiz »

OK. Thank you
... To the next what will inevitably happen !
Boggiz
NAS Syno DS718+ with 12Go ram
RFXtrx433XL v1044 with 3dBi antenna
Domoticz 2024.4 on Docker
TFA rain gauge, 4 ways automatic watering program, LINKY consumption, waterflow counter
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest