combine if statement

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

Moderator: leecollings

Post Reply
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

combine if statement

Post by poudenes »

Hi All,

is it possible and if so better to combine those lines that are for Scene statements:

Code: Select all

    if
    domoticz.devices(56).lux < 350 and -- Lux
    domoticz.variables(7).value == 0 and -- Lux Variable
    domoticz.devices(65).state == 'Off' and -- Scene Goodnight
    domoticz.devices(59).state == 'Off' and -- Scene Evening
    domoticz.devices(62).state == 'Off' and -- Scene Movie
    domoticz.devices(61).state == 'Off' and -- Scene TV
    (domoticz.devices(85).state == 'On' or domoticz.devices(86).state == 'On') -- iPhone Sensors
    then
maybe you can combine them domoticz.devices(65,59,62,61).state == 'Off' ?
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: combine if statement

Post by emme »

that would be nice.... not only in the if statement, but i could be also
domoticz.devices(65,59,62,61).switchOn().checkFirst()

+1
The most dangerous phrase in any language is:
"We always done this way"
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: combine if statement

Post by dannybloe »

First of all, I'd not use indexes like this as it makes your code hard to read (you always have to cross-reference it to figure out what is what). I'd create either a set of constants like local GOODNIGHT=65 and then use domoticz.device(GOODNIGHT) or local goodNight = domoticz.devices(65) and then if (goodNight.active and tv.active and move.active) etc.

I don't think I will add such a combined command but you can easily create one yourself using helper functions. Just pass in a table of ids or names and create a loop that will do it for you: domoticz.helpers.batchSwitch(domoticz, 'On', { 65, 59, 62, 61 })
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: combine if statement

Post by poudenes »

dannybloe wrote: Friday 24 November 2017 9:01 First of all, I'd not use indexes like this as it makes your code hard to read (you always have to cross-reference it to figure out what is what). I'd create either a set of constants like local GOODNIGHT=65 and then use domoticz.device(GOODNIGHT) or local goodNight = domoticz.devices(65) and then if (goodNight.active and tv.active and move.active) etc.

I don't think I will add such a combined command but you can easily create one yourself using helper functions. Just pass in a table of ids or names and create a loop that will do it for you: domoticz.helpers.batchSwitch(domoticz, 'On', { 65, 59, 62, 61 })
Thanks for the example and the explanation. Ill go back to the dzVents documents :). You pushed me to right direction!
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest