Page 1 of 1

If Then

Posted: Wednesday 16 August 2017 15:19
by bing69
Another problem. The first IF THEN works. The second not. And I do not know why ??? :oops:



Code: Select all

 return {
    active = true,
    on = {
        devices = {
            'Voordeur',
            'Pir_Gang2',
            'Pir_Gang'
        }
    },
    execute = function(domoticz,Voordeur)
            local Pir_gang = domoticz.devices('Pir_Gang')
            local Pir_gang2 = domoticz.devices('Pir_Gang2')
            local BridgeLamp = domoticz.devices('Bridge Lamp')
            local gang = domoticz.devices('Gang')
            local zonondergang = domoticz.devices('zonondergang')
        if (Voordeur.state == 'Open') and (zonondergang.state == 'On')  then
            gang.switchOn()
            BridgeLamp.switchOn()
        else
            BridgeLamp.switchOff()
            gang.switchOff().afterSec(30)
        end  
        if (Voordeur.state == 'Open') and (zonondergang.state == 'Off') then
            BridgeLamp.switchOn()
        else
            BridgeLamp.switchOff()
        end
            
    end
}

Re: If Then

Posted: Wednesday 16 August 2017 16:07
by mivo
Hi,

I think there is a problem with IF conditions and ELSE parts of these conditions. When first IF is evaluated as true (Voordeur.state == 'Open') and (zonondergang.state == 'On'), this part is executed:

Code: Select all

gang.switchOn()
BridgeLamp.switchOn()
But second IF condition is inverse of first in some cases (Voordeur.state == 'Open') and (zonondergang.state == 'Off'), so ELSE part can be executed also in same script run:

Code: Select all

BridgeLamp.switchOff()
Commands from dzVents (LUA) are passed to Domoticz after all scripts finishes, so last command for same device wins - BridgeLamp.switchOff() in this case.
You need to better figure out possible states of devices and then modify IF conditions - maybe nested IFs, or IF..ELSEIF will solve your problem.

Re: If Then

Posted: Friday 18 August 2017 19:07
by bing69
Thanks, fixit now!