Page 1 of 1

combine if statement

Posted: Thursday 23 November 2017 9:43
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' ?

Re: combine if statement

Posted: Thursday 23 November 2017 10:24
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

Re: combine if statement

Posted: Friday 24 November 2017 9:01
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 })

Re: combine if statement

Posted: Friday 24 November 2017 10:16
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!