Page 1 of 1

replace active = true for dummy switch state

Posted: Tuesday 01 August 2017 10:30
by dk78
Today I tried to replace or add the 'active = true' with some logic and a dummy switch. A master switch which that enables or disables all scripts. But I could not get it working. Is this possible?

I tried many things but the latest was: "(tostring(domoticz.devices('Masterswitch').levelName == 'Automatisch'))"
Error: dzVents: Error: ...e/pi/domoticz/scripts/dzVents/generated_scripts/Test.lua:5: attempt to call field 'devices' (a nil value)

The master switch is a selector switch with the names Automatisch (= automatic) and Handmatig (= manual). Don't know why it isn't working. When I test the string with logging, I got 'true'. So I thought this would work.

Is it also possible to have some logic in it? like active = (switch 1 == 'On' and switch 2 == 'On')?

Re: replace active = true for dummy switch state

Posted: Tuesday 01 August 2017 12:22
by dk78
function: A function returning true or false. The function will receive the domoticz object with all the information about you domoticz instance: active = function(domoticz) .... end. So for example you could check for a Domoticz variable or switch and prevent the script from being executed. However, be aware that for every script in your scripts folder, this active function will be called, every cycle!! So, it is better to put all your logic in the execute function instead of in the active function.
source: https://www.domoticz.com/wiki/%27dzVent ... 7B_..._.7D

Maybe I need to do it a different way

Re: replace active = true for dummy switch state

Posted: Tuesday 01 August 2017 16:51
by randytsuch
Is there a reason not to put the logic in the execute section, as Danny recommends?

Randy

Re: replace active = true for dummy switch state

Posted: Wednesday 02 August 2017 9:17
by dannybloe
Ok, I tried it in my setting:

Code: Select all

active = function(domoticz)
    return domoticz.devices('mySelectorSwitch').levelName == 'Level3'
end,
That worked. No need to do string-casting as the active-function should return a boolean (true/false) and not a string value. Please try again.
And yes, you can put all kinds of logic in your active function but like I said in the documentation: be careful not to put too much stuff in there as that code is always executed for every change/trigger in Domoticz' event system.