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')?
replace active = true for dummy switch state
Moderator: leecollings
- dk78
- Posts: 26
- Joined: Monday 07 March 2016 15:50
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Veldhoven
- Contact:
Re: replace active = true for dummy switch state
source: https://www.domoticz.com/wiki/%27dzVent ... 7B_..._.7Dfunction: 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.
Maybe I need to do it a different way
-
randytsuch
- Posts: 90
- Joined: Sunday 20 March 2016 18:56
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: LA, Ca USA
- Contact:
Re: replace active = true for dummy switch state
Is there a reason not to put the logic in the execute section, as Danny recommends?
Randy
Randy
-
dannybloe
- Posts: 1355
- Joined: Friday 29 August 2014 11:26
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Ermelo
- Contact:
Re: replace active = true for dummy switch state
Ok, I tried it in my setting:
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.
Code: Select all
active = function(domoticz)
return domoticz.devices('mySelectorSwitch').levelName == 'Level3'
end,
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.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Who is online
Users browsing this forum: No registered users and 1 guest