checkFirst not working

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:

checkFirst not working

Post 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
}

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: checkFirst not working

Post 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

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: checkFirst not working

Post by pvklink »

problem is that i get two (same) messages....
after the first the device is one, so why is there another message?
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