Page 1 of 1

switch wont go to selector item off

Posted: Tuesday 31 December 2019 10:48
by pvklink
Hi, i got a very little issue..
I use this script for my 86 years old grandfather to manage his lights (cant hardly walk)

i made a dummy selector switch(alarm clock) with options
0 = 'uit'
10 = '10:30'
20 = '10:35'

When i select the RED button from the dummy switch i like this switch to show option 0 = uit.
Current situation is that when you push the button, not selecting a value 10 or 20), the button switches the device off but still shows the previous value. Sort of a bug i think...
My grandfather does not understands that and thinks it is still on ...
Naamloos.jpg
Naamloos.jpg (8.38 KiB) Viewed 1020 times
So i like the selector switch shows 'uit' when pushing the device button from te selector switch
my code does not seems to work at this point.
The timer works great by the way....

Code: Select all

-- timers mogen niet op t exacte moment draaien, dus 5mn verschil
--
local timer_on1     = 'at 10:30'
local timer_on2     = 'at 10:35'

return {
    on =    { timer = {timer_on1,timer_on2},
              devices = {'Alarm clock'},
        },

    logging =   {
                level   = domoticz.LOG_ERROR ,                  
                },
              
    execute = function(dz,item,info)
    _G.logMarker = _G.moduleLabel 
    local now           = os.time(os.date('*t'))      
    local messageTable = {}
    local schakeltime = 'at ' .. dz.devices('Alarm clock').state

    if  (
         (item.isDevice and item.Name == 'Alarm clock') 
        ) then                       
            if item.state == 'Off' then  -- als je m uit zet, dan staat de waarde mogelijk nog op een tijd
                dz.devices('Alarm clock').switchSelector('uit') --- DIT WERKT NIET
            end

        dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: aanpassing gedaan op de schakelklok... ')

    elseif (item.isTimer) and schakeltime == item.trigger then
        --dz.devices('Sfeerverlichting').switchOn()
        dz.devices('test').switchOn()
        dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: schakelklok wordt ingeschakeld ... ')
        
    else
        -- doe niets
        
    end
    dz.helpers.globalMessage2(dz,item,info,messageTable,'chg') -- dump

end
}

Re: switch wont go to selector item off  [Solved]

Posted: Tuesday 31 December 2019 12:28
by waaren
pvklink wrote: Tuesday 31 December 2019 10:48 i made a dummy selector switch(alarm clock) with options
0 = 'uit'
10 = '10:30'
20 = '10:35'

When i select the RED button from the dummy switch i like this switch to show option 0 = uit.
This behavior is not a bug but a feature :D
Selector switches remember their level also when switched off. If you want them to go to another state you need to code that.

Below script is one way of doing that.

Code: Select all

-- timers mogen niet op t exacte moment draaien, dus 5mn verschil
--
local timer_on1 = '12:19'
local timer_on2 = '12:20'

return 
{
    on =    
    { 
        timer = 
        {
            'at ' .. timer_on1, 
            'at ' .. timer_on2
        },
        devices = {'Alarm clock'},
    },

    logging =   
    {
        level = domoticz.LOG_DEBUG ,                  
    },

    execute = function(dz, item, info)
        _G.logMarker = _G.moduleLabel 

        local messageTable = {}

        local alarm = dz.devices('Alarm clock')
        local test = dz.devices('test')

        if item.isDevice and item == alarm  then                       
            if item.level == 'uit' or item.nValue == 0 then 
                alarm.switchSelector(0).silent() 
            end
            dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: aanpassing gedaan op de schakelklok... ')
        elseif item.isTimer and item.trigger:find(alarm.levelName) then
            dz.devices('Sfeerverlichting').switchOn()
            test.switchOn()
            dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: schakelklok wordt ingeschakeld ... ')
        else
            -- doe niets
        end
            dz.helpers.globalMessage2(dz,item,info,messageTable,'chg') -- dump
	end
}

Re: switch wont go to selector item off

Posted: Tuesday 31 December 2019 12:39
by pvklink
thanks
And yes, previous state is indead handy!

Re: switch wont go to selector item off

Posted: Tuesday 31 December 2019 12:47
by pvklink
and it works, thanks @waaren