If Then

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

Moderator: leecollings

Post Reply
bing69
Posts: 139
Joined: Thursday 05 June 2014 10:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: 's-Hertogenbosch, NL
Contact:

If Then

Post 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
}
mivo
Posts: 80
Joined: Friday 21 April 2017 8:58
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Czechia
Contact:

Re: If Then

Post 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.
My toys:
Raspberry Pi 3 + UPS PIco HV3.0 A Stack
Minibian (Raspbian Jessie) + Domoticz beta
RFLink 433 Gateway, 1wire DS18B20 temp sensors (GPIO)
RaZberry module + 2x Comet Z-Wave + Z-wave socket
---
Plugins: WeMo Switch, UPS PIco HV3.0A on GitHub
bing69
Posts: 139
Joined: Thursday 05 June 2014 10:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: 's-Hertogenbosch, NL
Contact:

Re: If Then

Post by bing69 »

Thanks, fixit now!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest