switch wont go to selector item off  [Solved]

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

Moderator: leecollings

Post Reply
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

switch wont go to selector item off

Post 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 1022 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
}
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

Re: switch wont go to selector item off

Post by pvklink »

thanks
And yes, previous state is indead handy!
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

Re: switch wont go to selector item off

Post by pvklink »

and it works, thanks @waaren
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest