Compact syntax for dzVents

Easy to use, 100% Lua-based event scripting framework.
Post Reply
Eoreh
Posts: 67
Joined: Tuesday 13 October 2015 13:50
Target OS: Raspberry Pi
Domoticz version: beta
Location: Poland
Contact:

Compact syntax for dzVents

Post by Eoreh » Sunday 28 January 2018 0:58

Compact syntax for dzVents in plans its add-on to dzVents.
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)
plansModule_v1_8.txt
(30.59 KiB) Downloaded 26 times
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

-- test work module. only need two virtual switch. And toggle test2 on change on test1.
local plans={
    {toggleSwitch='test2'}
}
--
local oPlans = require('plansModule')
return {
	on = {
		devices={'test1'}
	},
	execute = function(domoticz, device,triggerInfo)
        oPlans.onPlans(domoticz,device,triggerInfo,plans)
	end
}
if dont work then on top of your script add

Code: Select all

package.path = package.path .. ';' .. '/home/pi/domoticz/scripts/lua/?.lua'
Other examples below (not too complicated): on trigger by device with 1 rule in "one line"

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
}
More examples in the next posts

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. :?:
Attachments
plansModule_v1_8.txt
(30.59 KiB) Downloaded 13 times
Last edited by Eoreh on Sunday 11 February 2018 17:35, edited 49 times in total.

Eoreh
Posts: 67
Joined: Tuesday 13 October 2015 13:50
Target OS: Raspberry Pi
Domoticz version: beta
Location: Poland
Contact:

Re: Compact syntax for dzVents

Post by Eoreh » Sunday 28 January 2018 11:11

Next egzample of simple plans with multiple rules trigger by timer for multiple devices
Spoiler: show

Code: Select all

--==================================================================================
-- an example of plans with multiple rules trigger by timer  for multiple devices
-- timer  trigger rules  can be any from dzVents, see-> https://www.domoticz.com/wiki/DzVents:_next_generation_LUA_scripting
-- *********************************************************************************

local funToRepeat='repeatAfterSec(1,3)'  -- to make sure that espEasy will made on/off :)
local plans = {
        { switchOn  ={ 'LED - Whisky',   time= '20 minutes before sunset', description=' LED-Whisky -> ON',  fun=funToRepeat}},
        { switchOff ={ 'LED - Whisky',   time={'at 21:45 on mon,tue,wed,thu', 'at 22:30 on fri,sat,sun'},    fun=funToRepeat}},

        { switchOn  ={ 'LED - Kitchen',  time= '30 minutes after sunset',                                    fun=funToRepeat}},
        { switchOff ={ 'LED - Kitchen',  time= 'at 21:15',                                                   fun=funToRepeat}},

        { switchOn  ={ 'LED - hall',     time= '40 minutes before sunset',                                   fun=funToRepeat}}, 
        { switchOf  ={ 'LED - hall',     time= {'at 22:00 on mon,tue,wed,thu', 'at 22:35 on fri,sat,sun'},   fun=funToRepeat}},

        { switchOn  ={ 'LIGHT-home',     time= {'at 05:30', '15 minutes before sunset'},                     fun=funToRepeat}},
        { switchOff ={ 'LIGHT-Dom',      time= {'20 minutes before sunrise', 'at 23:20'},                    fun=funToRepeat}},                    

        { switchOn  ={ 'LIGHT-Halogen',  time= {'5 minutes after sunset', 'at 06:20 on mon,tue,wed,thu'},    fun=funToRepeat}}, 
        { switchOff ={ 'LIGHT-Halogen',  time= {'at 21:45', 'at 07:40 on mon,tue,wed,thu'},                  fun=funToRepeat}},
}
local oPlans = require('plansModule')

return {
	on = {
		timer= {'every minute'},
	},
	execute = function(domoticz, device,triggerInfo)
        oPlans.onPlans(domoticz,device,triggerInfo,plans)
	end
}
)
eg11.png
eg11.png (57.92 KiB) Viewed 1078 times

Eoreh
Posts: 67
Joined: Tuesday 13 October 2015 13:50
Target OS: Raspberry Pi
Domoticz version: beta
Location: Poland
Contact:

Re: Compact syntax for dzVents

Post by Eoreh » Sunday 28 January 2018 12:45

an example of closing an automatic garage door at night. Rule testing with additional debugging in the log.
First we testing rules in virytual switch test1, test2 and with change time value of onTime={} to "every minute"
Spoiler: show

Code: Select all

 -- example with one rule, closing the garage door at night when it is longer than for example 15 minutes. 
-- of course, for other gates, we can add the same rules in this script
-- We check every 2 minutes and status device 
-- Message all the same for email, notify, log. sa we can define it before in local variable
local planSubject = 'Auto close garage'
local PlanMessage = 'Garage door Skody open more when 15 min after sunset'
--
plans={
    {description = 'Auto close garage door - skoda',
        onTime  = 'every minute',   -- 
        switchOn= 'test2', 
        where   = {'test1',state='On', when='lastUpdate.minutesAgo>1'},
        email   = {subject= planSubject, message= PlanMessage },
        notify  = {subject= planSubject, message= PlanMessage }, 
        log     = {message= PlanMessage, level='LOG_ERROR' },
        debug   = 'DEBUG Auto close garage >>>  ' 
    },
}
--
local oPlans = require('plansModule')
return {
	on = {
		timer= {'every minute'},
	},
	execute = function(domoticz, device,triggerInfo)
        oPlans.onPlans(domoticz,device,triggerInfo,plans)
	end
}
If test1 is OFF then in log you will see

Code: Select all

2018-01-28 11:30:00.577 dzVents: !Info: 1.1 +++ DEBUG Auto close garage >>> OK-> test1 when lastUpdate.minutesAgo>1
2018-01-28 11:30:00.577 dzVents: !Info: 1.1 +++ DEBUG Auto close garage >>> test1 ! state On
After manualy switch "test1" ON. Log should he should show something like that (becouse we change test1 few seconds ago :) ).

Code: Select all

2018-01-28 11:32:00.475 dzVents: !Info: 1.1 +++ DEBUG Auto close garage >>> not-> test1 when= lastUpdate.minutesAgo>1
Atfer more whan 1 minute show like this:

Code: Select all

2018-01-28 11:33:00.459 dzVents: !Info: 1.1 +++ DEBUG Auto close garage >>> OK-> test1 when lastUpdate.minutesAgo>1
2018-01-28 11:33:00.459 dzVents: !Info: 1.1 +++ DEBUG Auto close garage >>> OK-> test1 state On
2018-01-28 11:33:00.459 dzVents: !Info: 1.1 +++ DEBUG Auto close garage >>> domoticz.devices('test2').switchOn()
2018-01-28 11:33:00.461 dzVents: Error (2.4.1): Garage door Skody open more when 15 min after sunset
Now We can simple swap device names and change onTime to target.
Spoiler: show

Code: Select all

-- example with one rule, closing the garage door at night when it is longer than for example 15 minutes. 
-- of course, for other gates, we can add the same rules in this script
-- We check every 2 minutes and status device 
-- Message all the same for email, notify, log. sa we can define it before in local variable
local planSubject = 'Auto close garage'
local PlanMessage = 'Garage door Skody open more when 15 min after sunset'
--
plans={
    {description = 'Auto close garage door - skoda',
        onTime  = 'every 2 minutes between 20 minutes after sunset and 30 minutes after sunrise',
        switchOn= 'Garage door Skoda - pushbutton', 
        where   = {'Garage door - Skoda -status',state='Unlocked', when='lastUpdate.minutesAgo>15'},
        email   = {subject= planSubject, message= PlanMessage },
        notify  = {subject= planSubject, message= PlanMessage }, 
        log     = {message= PlanMessage, level='LOG_ERROR' },
    },
}
--
local oPlans = require('plansModule')
return {
	on = {
		timer= {'every minute'},
	},
	execute = function(domoticz, device,triggerInfo)
        oPlans.onPlans(domoticz,device,triggerInfo,plans)
	end
}
Of course, with one rule instead of using onTime in a rule, we could set it in the dzVents timer.
But if we have many rules in one script with different times, it can not be done in the dzVents timer. so we have to use onTime function from plansModule
eg12.png
eg12.png (42.07 KiB) Viewed 1056 times

Eoreh
Posts: 67
Joined: Tuesday 13 October 2015 13:50
Target OS: Raspberry Pi
Domoticz version: beta
Location: Poland
Contact:

Re: Compact syntax for dzVents

Post by Eoreh » Sunday 28 January 2018 17:39

Example with combine selector and switch. We can choose to turn on for 1h, 2h, 3h, always, off and it switches this OFF or ON switch to the right time. When You selected for example 1h - selector back to OFF after 1h and turn OFF switch.
NOTE: for test You can change fun on aferSec(10), 20, 30 etc. Code to copy in spoiler
Spoiler: show

Code: Select all

-- egzample with combine  selector and switch 
-- we can choose to turn on for 1h, 2h, 3h, always, off
-- and it switches this OFF or ON switch to the right time
selector='SELECTOR1'
switch='TEST1' 
plans={
        {switchOff  ={switch}, where={selector, state='Off'}},
	    {switchOn   ={switch}, where={selector,  state='always'}}, 
	    
	    {onDevice={selector, state='1h'},  switchOn  ={switch},  dimTo={selector,level='Off',fun='afterHour(1)'}},
	    {onDevice={selector, state='2h'},  switchOn  ={switch},  dimTo={selector,level='Off',fun='afterHour(2)'}},
	    {onDevice={selector, state='3h'},  switchOn  ={switch},  dimTo={selector,level='Off',fun='afterHour(3)'}},
}
--
local oPlans = require('plansModule')
return {
	on = {
		devices={selector}
	},
	execute = function(domoticz, device,triggerInfo)
        oPlans.onPlans(domoticz,device,triggerInfo,plans)
	end
}
eg14.png
eg14.png (22.9 KiB) Viewed 1008 times
eg15.png
eg15.png (33.38 KiB) Viewed 1007 times
Last edited by Eoreh on Monday 29 January 2018 0:40, edited 1 time in total.

Eoreh
Posts: 67
Joined: Tuesday 13 October 2015 13:50
Target OS: Raspberry Pi
Domoticz version: beta
Location: Poland
Contact:

Re: Compact syntax for dzVents

Post by Eoreh » Monday 29 January 2018 0:31

ver 2 previous script selector+switch. Now also handle the situation when we click on TEST1 (eg when we operate through a hardware button).
Note: to correct work requires the 1.2 or newer version of the plansModule to be downloaded from the first post
Spoiler: show

Code: Select all

-- ver 2. egzample with combine  selector and switch 
-- we can choose to turn on for 1h, 2h, 3h, always, off
-- and it switches this OFF or ON switch to the right time
local selector='SELECTOR1'
local switch='TEST1' 
plans={
	    {onDevice={switch, state='Off'},       where={selector, when="state~='Off'"}, dimTo={selector,level='Off',    fun='silent()'}},
        {onDevice={switch, state='On'},        where={selector, state='Off'},         dimTo={selector,level='always', fun='silent()'}},
	
        {onDevice={selector, state='Off'},     switchOff ={switch}},
	    {onDevice={selector, state='always'},  switchOn  ={switch}}, 
	    
	    {onDevice={selector, state='1h'},      switchOn  ={switch},  dimTo={selector,level='Off',fun='afterHour(1)'}},
	    {onDevice={selector, state='2h'},      switchOn  ={switch},  dimTo={selector,level='Off',fun='afterHour(2)'}},
	    {onDevice={selector, state='3h'},      switchOn  ={switch},  dimTo={selector,level='Off',fun='afterHour(3)'}},
}
--
local oPlans = require('plansModule')
return {
	on = {
		devices={selector, switch}
	},
	execute = function(domoticz, device,triggerInfo)
        oPlans.onPlans(domoticz,device,triggerInfo,plans)
	end
}
eg16.png
eg16.png (43.2 KiB) Viewed 974 times
Last edited by Eoreh on Monday 29 January 2018 15:57, edited 2 times in total.

Eoreh
Posts: 67
Joined: Tuesday 13 October 2015 13:50
Target OS: Raspberry Pi
Domoticz version: beta
Location: Poland
Contact:

Re: Compact syntax for dzVents

Post by Eoreh » Monday 29 January 2018 0:33

new Version 1.2 -fix/future for debug mode, now also dispaly function, fix to handling lvl, level in some situation.
Check first post.

Eoreh
Posts: 67
Joined: Tuesday 13 October 2015 13:50
Target OS: Raspberry Pi
Domoticz version: beta
Location: Poland
Contact:

Re: Compact syntax for dzVents

Post by Eoreh » Monday 29 January 2018 15:51

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
but in debug mode will show number value. Egzample new debug mode.

Code: Select all

2018-01-29 13:36:35.601 dzVents: !Info: 1.3 +++ 1 onDevice SELECTOR1 OK -> level always
2018-01-29 13:36:35.602 dzVents: !Info: 1.3 +++ 1 onDevice SELECTOR1 NOT-> lastLevel 10 is -> 20
2018-01-29 13:36:35.602 dzVents: !Info: 1.3 +++ 2 onDevice SELECTOR1 OK -> level 1h
2018-01-29 13:36:35.603 dzVents: !Info: 1.3 +++ 2 onDevice SELECTOR1 NOT-> lastLevel 10 is -> 20

TomBod
Posts: 2
Joined: Tuesday 30 January 2018 21:11
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Poland
Contact:

Re: Compact syntax for dzVents

Post by TomBod » Tuesday 30 January 2018 21:18

Great job Andrzej.
Thanks to this script I have reduced many of my scripts and many lines of code to a few simple commands.
For example, I use such formulas as:
examples.jpg
examples.jpg (341.92 KiB) Viewed 873 times
2xRPi - Synology DS212 - RFLink433 - Mi-Light lights - Kaku switches - Conrad RSL wall-mounted switches - Sonoff switches - IP Cameras

Eoreh
Posts: 67
Joined: Tuesday 13 October 2015 13:50
Target OS: Raspberry Pi
Domoticz version: beta
Location: Poland
Contact:

Re: Compact syntax for dzVents

Post by Eoreh » Thursday 01 February 2018 0:50

TomBod wrote:
Tuesday 30 January 2018 21:18
Great job Andrzej.
Thx, Tom. I'm glad that someone is using this library.

Eoreh
Posts: 67
Joined: Tuesday 13 October 2015 13:50
Target OS: Raspberry Pi
Domoticz version: beta
Location: Poland
Contact:

Re: Compact syntax for dzVents

Post by Eoreh » Thursday 01 February 2018 1:01

Version 1.4 -fix for bug to level in dimTo function. Future: add color to output for debug and as new property to object Log. Default color for log is green.
But now You can change log text from default color green to other. eg, Red, Blue, Green, Black, Brown, etc. See example.

Code: Select all

-- colored log. 
local selector='SELECTOR1'

plans={
    {where={selector, state='Off'},    log={message='Log color is default Green, cos no color property specyfied'}},  
    {where={selector, state='always'}, log={message='Log color is Red', color='Red'}}, 
    {where={selector, state='1h'},     log={message='Log color is Blue', color='Blue'}},
    {where={selector, state='2h'},     log={message='Log color is default Green, cos => wrong color type XXX', color='XXX'}}, 
}
--
local oPlans = require('plansModule')
return {
	on = {
		devices={selector}
	},
	execute = function(domoticz, device,triggerInfo)
        oPlans.onPlans(domoticz,device,triggerInfo,plans)
	end
}
After run this script and change levels in selector log should look like this
eg17.png
eg17.png (19.44 KiB) Viewed 829 times

Eoreh
Posts: 67
Joined: Tuesday 13 October 2015 13:50
Target OS: Raspberry Pi
Domoticz version: beta
Location: Poland
Contact:

Re: Compact syntax for dzVents

Post by Eoreh » Saturday 03 February 2018 13:54

Version 1.5 -Future, add property cancelQueuedCommands for all function. Require dzVents 2.4. See example below

ver 3 previous script "selector+switch". Now also handle the situation when we will change mind and click from shorter time 1h to 2h.
Note: to correct work requires the 1.5 or newer version of the plansModule to be downloaded from the first post
and of course dzVents 2.4 (with cancelQueuedCommands)
eg14.png
eg14.png (22.9 KiB) Viewed 742 times
Spoiler: show

Code: Select all

-- ver 3. require dzVents 2.4 or neweer egzample with combine  selector and switch 
-- we can choose to turn on for 1h, 2h, 3h, always, off
-- and it switches this OFF or ON switch to the right time
local selector='SELECTOR1'
local switch='TEST1' 
plans={
	    {onDevice={switch, state='Off'},       where={selector, when="state~='Off'"}, dimTo={selector,level='Off',    fun='silent()'}},
        {onDevice={switch, state='On'},        where={selector, state='Off'},         dimTo={selector,level='always', fun='silent()'}},
	
        {onDevice={selector, state='Off'},     switchOff ={switch}},
	    {onDevice={selector, state='always'},  switchOn  ={switch}}, 
	    
	    {onDevice={selector, state='1h'},      switchOn  ={switch},  dimTo={selector,level='Off',cancelQueuedCommands=true,fun='afterHour(1)'}},
	    {onDevice={selector, state='2h'},      switchOn  ={switch},  dimTo={selector,level='Off',cancelQueuedCommands=true,fun='afterHour(2)'}},
	    {onDevice={selector, state='3h'},      switchOn  ={switch},  dimTo={selector,level='Off',cancelQueuedCommands=true,fun='afterHour(3)'}},
}
--
local oPlans = require('plansModule')
return {
	on = {
		devices={selector, switch}
	},
	execute = function(domoticz, device,triggerInfo)
        oPlans.onPlans(domoticz,device,triggerInfo,plans)
	end
}
Text version script's code for copy in spoiler.
eg18.png
eg18.png (48.11 KiB) Viewed 743 times

Eoreh
Posts: 67
Joined: Tuesday 13 October 2015 13:50
Target OS: Raspberry Pi
Domoticz version: beta
Location: Poland
Contact:

Re: Compact syntax for dzVents

Post by Eoreh » Sunday 11 February 2018 17:30

Version 1.8:
New function:
1. generic
- the generic function has been added to run all other functions not directly supported by the library but exist in dzVents now and in future.
Of course everything else for the rule with function generic is also allowed as time, when or where
Here is an example of "setRGB(0, 255,0)"
Spoiler: show

Code: Select all

-- generic function 
local selector='SELECTOR1'
local plans={
	    {generic={'Lamp-RGB', fun='setRGB(0, 255,0)'}},  
}
--
local oPlans = require('plansModule')
return {
	on = {
		devices={selector}
	},
	execute = function(domoticz, device,triggerInfo)
        oPlans.onPlans(domoticz,device,triggerInfo,plans)
	end
}
eg21.png
eg21.png (12.69 KiB) Viewed 583 times


2. openURL
added special support becouse is not support by generic. Function openURL requires 2 parameters.
a) Some names - it may be a name from a device from domoticz or not (then it is just a description)
b) url = 'http: // domain / path / to / something? withparameters = 1'

As we will give as the name of the device from domoticza then
openURL = {'TEST2', state = 'On', url = 'http: //192.168.0.103: 8080 / json.htm? type = command & param = switchlight & idx = 256 & switchcmd = Toggle'}

Means that the command will only be executed when TEST2 has state = 'On'
Spoiler: show

Code: Select all

local switch='TEST2'
local selector='SELECTOR1'
local plans={
	    {openURL={'TEST2',state='On',url='http://192.168.0.103:8080/json.htm?type=command&param=setcolbrightnessvalue&idx=282&hue=5&brightness=95&iswhite=false'}},  
}
--
local oPlans = require('plansModule')
return {
	on = {
		devices={selector}
	},
	execute = function(domoticz, device,triggerInfo)
        oPlans.onPlans(domoticz,device,triggerInfo,plans)
	end
}

3. dimFromTo
Added special function which is not implemented in dzVents. This function it is used to change the dimmer value depending on the time.
a) syntax:
dimFromTo = {<name>, lvlFromTo = <array {from proc, to proc} or one number>, timeFromTo = {time1, time2}}
b) we can light up, for example, from 10 percent to 70 percent from 22.00 to sunrise. or vice versa (then from proc> to percent)
c) Time parameters you can use all the allowed syntax for dzVents but of course for a given moment. "at" is not necessary.
d) If lvlFromTo is a constant number (or maybe) then the total is the same as regular dimTo, i.e. such records are equivalent to
   {dimFromTo = {ledR, lvlFromTo = 70, timeFromTo = {'08:01', '60 minutes before sunset'}},
   {dimTo = {ledR, lvl = 70, time = 'between 08:01 and 60 minutes before sunset'},
Spoiler: show

Code: Select all

local ledR = 'Aqua-Red'
local plans={
    {dimFromTo={ledR,lvlFromTo={0,70},  timeFromTo={'22:01','15 minutes after sunrise'}}, where={{'Test', state='Off'},{'PIR', state='Off'}}}, 
    {dimFromTo={ledR,lvlFromTo=70,      timeFromTo={'08:01','60 minutes before sunset'}}},   
    {dimFromTo={ledR,lvlFromTo={70,10}, timeFromTo={'18:02','22:00'}}}, 
--  {dimTo={ledR, lvl=70, time='08:01-18.00'}}, 
}
--
local oPlans = require('plansModule')
return {
	on = {
		time={'every minute'}
	},
	execute = function(domoticz, device,triggerInfo)
        oPlans.onPlans(domoticz,device,triggerInfo,plans)
	end
}
eg22.png
eg22.png (24.77 KiB) Viewed 583 times

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests