Page 1 of 1

checkFirst not working

Posted: Saturday 28 September 2019 16:56
by pvklink
Hi,
I bought a sonoff key remote with fout buttons. When i push button B, i receive the signal three times.
So i made $remote_aan which is coupled to the remote (and changes three times)
When the script receives a ok, it changes another switch remote_aan_def and only changes this by checking it first with checkFirst

The switches are working by i get two messages when pushing the B button (this is $remote_uit)...

Code: Select all

return {
    on = {  devices = {'$remote_aan', '$remote_uit'},
        },
        
    logging =   { level   = domoticz.LOG_ERROR,                 
                  marker  = "Timers"},
              
    execute = function(dz,item,info)

    if (item.name == '$remote_aan')    then
        dz.devices('$remote_aan_def').switchOn().checkFirst()
        dz.devices('$remote_aan_def').switchOff().afterSec(10)

    elseif (item.name == '$remote_uit')    then
        dz.devices('$remote_uit_def').switchOn().checkFirst()
        dz.devices('$remote_uit_def').switchOff().afterSec(10)

    end

end
}

Code: Select all


return {
    on = {  devices = {'$remote_aan_def','$remote_uit_def'},
        },
        
    logging =   { level   = domoticz.LOG_ERROR,                 
                  marker  = "Timers"},
              
    execute = function(dz,item,info)

    local logcode = 3
    local messageTable = {}
    local add = 'add'
    local del = 'del'
    local chg = 'chg'
        
    local function globalMessage(action, message, logcode)
 
        if logcode == nil then logcode = 3 end
 
        if action == add and logcode > 0 then
            messageTable = dz.helpers.addMessage(dz, item, info, message, messageTable, logcode)
        elseif action == del then
            dz.globalData.mylogging = message
            dz.devices('timerlog').updateText(message)
        elseif action == chg then 
            dz.helpers.dumpMessages(dz, messageTable)
        end
 
    end

    if (item.name == '$remote_aan_def') and (item.state == 'On') then    -- reset
        globalMessage(add, ' REMOTE_AB_1: Aan aangezet...',logcode) 

    elseif (item.name == '$remote_uit_def') and (item.state == 'On') then    -- reset
        globalMessage(add, ' REMOTE_AB_1: UIT aangezet...',logcode) 

    end
    globalMessage(chg) -- dump

end
}


Re: checkFirst not working

Posted: Saturday 28 September 2019 19:06
by waaren
It' s not clear to me what the exact problem is.
checkFirst() is the same as
If device.state ~= 'On' then
device.switchOn()
end

and similar for 'Off'

So maybe code it like this and add some log statements. To see what the before state is.

Verstuurd vanaf mijn ONEPLUS A6003 met Tapatalk


Re: checkFirst not working

Posted: Saturday 28 September 2019 20:45
by pvklink
problem is that i get two (same) messages....
after the first the device is one, so why is there another message?