I noticed with my friends that many of our dzVents scripts have simple logic and too many lines .
That's why below the module planModule.lua in which it proposes additional functionality in a compact syntax. I hope that someday similar functionality will be directly in dzVents. (Requires dzVents 2.3 or later)
How to install: download, change extension and name to plansModule.lua, copy to folder depending on your LUA configuration
/home/pi/domoticz/scripts/dzVents/scripts/ or /home/pi/domoticz/scripts/lua/
The simplest script to check the operation of the module in spoiler
- Spoiler: show
Code: Select all
package.path = package.path .. ';' .. '/home/pi/domoticz/scripts/lua/?.lua'
and other trigger by timer and have 3 rules in one plan.
Code: Select all
-- 3 rules
-- 1: rule for when, where, notify, email
-- 2: simple rule with where
-- 3: simple rule for dimTo
local plans={
{switchOff={'Garage Door 1', 'Garage Door 2', when='lastUpdate.minutesAgo >15' }, where={{'temperature-out', when='temperature < 25'}, {'ImNotHome', state='On'}},
log={message='Lamp1 flash '}, notify={subject='RULE 1',message='Auto close garage door'} , email= false },
{switchOn={'Lamp outside 1','Lamp outside 2'}, where={'ImInHome', state='On'}},
{dimTo={'Status Alarm',lvl='Arming'}},
}
local oPlans = require('plansModule')
return {
on = {
timer= {'at 22:00'},
},
execute = function(domoticz, device,triggerInfo)
oPlans.onPlans(domoticz,device,triggerInfo,plans)
end
}
Change log and release notices:
Version 1.8 -Future, new function, generic, openURL, dimFromTo. Now in where You can use OR=true. See example in this topis.
Version 1.5 -Future, add property cancelQueuedCommands for all function. Require dzVents 2.4. See example in this topic
Version 1.4 -fix for bug level for dimTo. Future, add color do output debug and as new property to Log object. With color= in log you can use standard color: Red, Blue, Black, Green, Brown etc. See example in this topic
Version 1.3 -fix/future for debug mode, now also dispaly current value for false condytion, lastLevel now can be name level not only number
Version 1.2 -fix/future for debug mode, now also dispaly function, fix to handling lvl, level in some situation
Version 1.1 - new syntex and build as extension in module. Previous in scripted version described here. viewtopic.php?f=59&t=21529
If You wil be interested i will do documentation on wiki. The syntax has a lot of flexible possibilities. Below short description
All of the following properties are not mandatory in plan's rules
The order of elements in the rule can be any, does not matter
FUNCTION for acction:
switchOn,switchOff,switchSelector,toggleSwitch,dimTo, updateSetPoint, openURL, dimFromTo
switchOn='test1', switchOff={'test2'}, dimTo={'test3',lvl=10}, switchSelector={'test4',lvl='Level1'}, toggleSwitch={{'test5'},{'test6'},{'test7'}}
dimTo={'test10',lvl=10, when='temperature < 10'} , switchOn={{'test20', when='temperature > 20}, 'test21'}
switchOn={'test40', fun='checkFirst().forSec(5)'}, {onDevice='test1', updateSetPoint={'Temperatura WYJAZD',setPoint=23}},
FUNCTION for ON
onDevice - You can use in dzVents - in on section devices = {'*'} and next by Plans filtering action On
eg onDevice={'telefon*',when='status=="On"'}
onTime - You can use in dzVents in on section timer={'every minute'} and next by Plans filtering onTime={{'at 10:00', {'at 11:00'}}
FUNCTION for filters
where is function dedicated for check other device than was triggered.
where={'test1',when='temperature>10'} , {{'test1',when='temperature>10'}, {'test2',when='temperature>20'}
PROPERTY
You can use in al function property like this: with 3 specjal property:
when - logical condition for the device that needs to be met. eg. when='lastUpdate.minutesAgo > 10'
fun - function to run on device eg. fun='checkFirst().forSec(5)'
level, lastLevel - parameters for selectors. Can be numeric or label.
setPoint - parameter for updateSetPoint
cancelQueuedCommands - for cancel delay command (require dzVents 2.4)
Rest proporty is standard property from dzVents devices eg. state, temperature etc.
PROPERTY: (all property is not obligatory)
description: used in write to log end and body notify eg description = ' It is description '
notify: notify only if present and is true to system defined default in global variable NOTIFY but y can inline overwrite in object notify all or some elements NOTIFY={subject, message, priority, sound, extra, subsystem, notify=true }
email: email only if present and is true to system defined default in global variable EMAIL but y can inline overwrite in object all or some elements EMAIL={subject, message, mailTo, email=true}
sms: sms only if present and is true to system defined default in global variable SMS but y can inline overwrite in object all or some elements SMS={message, sms=true}
log : log only if present and is true to system defined default in global variable LOG but y can inline overwrite in object all or some elements LOG={message,level, log=true, time=' '}
dontLog: if true script dont write to log action. If not present or is false script will write to log when LOGGING = true eg. donLog = true dontlog=true is the same as log=false
debug: debug="debugin rules nr 1 >>>' . Log more information about excecution current rule.
If You have question about this script just ask.