User Tools

Site Tools


time_math_tutorial

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
time_math_tutorial [2015/03/30 10:16]
Niek Removed ntp server from newdatetime protocol
time_math_tutorial [2015/11/27 21:09] (current)
Line 1: Line 1:
 ===== Time math ===== ===== Time math =====
 ==== Introduction ==== ==== Introduction ====
-Creating rules for pilight eventing based on time can be a tedious job and such rules can be difficult to debug. For that reason a few new operators ​and a modified ​datetime protocol have been created.+Creating rules for pilight eventing based on time can be a tedious job and such rules can be difficult to debug. For that reason a few new operators, an extended ​datetime protocol ​and an extended switch action ​have been created.
 ==== Compatibility ====  ==== Compatibility ==== 
-The new operators ​and the modified ​datetime protocol are ONLY compatible with the manually installed **development version** of pilight version 6.0. Both the source code and the installation procedure are based on the new pilight library structure. Compiling against a pilight version with the old library structure will fail. +The new operatorsthe extended ​datetime protocol ​and the extended switch action ​are ONLY compatible with the manually installed **development version** of pilight version 6.0. Both the source code and the installation procedure are based on the new pilight library structure. Compiling against a pilight version with the old library structure will fail. 
  
 You are strongly advised to install the most recent pilight development version before the installation of the time math modules. With older pilight versions they may give errors or unpredictable results. ​ You are strongly advised to install the most recent pilight development version before the installation of the time math modules. With older pilight versions they may give errors or unpredictable results. ​
Line 9: Line 9:
 For instructions on how to install pilight manually please look [[http://​www.pilight.org/​get-started/​installation/#​stable_git|here]]. For instructions on how to install pilight manually please look [[http://​www.pilight.org/​get-started/​installation/#​stable_git|here]].
 ==== Protocol and operators ==== ==== Protocol and operators ====
-The new operators are plustime (+t), minustime (-t) and random (~). The modified ​datetime protocol provides, as an additional item,  the time in hh.mm format (like in the sunriseset protocol).+The new operators are plustime (+t), minustime (-t) and random (~). The extended ​datetime protocol provides, as an additional item,  the time in hh.mm format (like in the sunriseset protocol). The extended switch action offers the posssibility to switch a device for a random duration.
  
-With the plustime and minustime operators and the modified datetime protocol ​you can create very simple rules to switch devices depending on the time of the day or sunrise- or sunset time.+With these modules ​you can create very simple rules to switch devices depending on the time of the day or sunrise- or sunset time.
  
 ==== Usage ==== ==== Usage ====
Line 36: Line 36:
 |IF datetime.time == 23.00 +t (0 ~ 90.01) +t (10 ~ 30.02) THEN ...|performs action 10 to 30 minutes after the action above| |IF datetime.time == 23.00 +t (0 ~ 90.01) +t (10 ~ 30.02) THEN ...|performs action 10 to 30 minutes after the action above|
  
-These operators ​and this protocol aren't part of pilight (yet). But don't worry, you can simply add them yourself as modules. This is how.+=== switch action === 
 +With the extended switch action you make a device swith on or off for a random duration. In addition you can set the unit size. 
 + 
 +Examples: 
 + 
 +|IF ... THEN switch DEVICE ... TO on FOR 1 ~ 10|switches the device on for a  period of between 1 and 10 seconds| 
 +|IF ... THEN switch DEVICE ... TO on FOR 1 ~ 10 UNIT 60|switches the device on for a  period of between 1 and 10 minutes| 
 +|IF ... THEN switch DEVICE ... TO on FOR 1 ~ 10 UNIT 3600|switches the device on for a  period of between 1 and 10 hours| 
 + 
 +These operatorsthis protocol ​and this action ​aren't part of pilight (yet). But don't worry, you can simply add them yourself as modules. This is how.
  
 ==== Installation ==== ==== Installation ====
Line 57: Line 66:
  
 <​code>​root@raspi2:/​home/​pi/​pilight#​ cp pilight-time-stuff/​operators/​*.* libs/​pilight/​events/​operators/​ <​code>​root@raspi2:/​home/​pi/​pilight#​ cp pilight-time-stuff/​operators/​*.* libs/​pilight/​events/​operators/​
-root@raspi2:/​home/​pi/​pilight#​ cp pilight-time-stuff/​protocols/​*.* libs/​pilight/​protocols/</​code>​+root@raspi2:/​home/​pi/​pilight#​ cp pilight-time-stuff/​protocols/​*.* libs/​pilight/​protocols
 +root@raspi2:/​home/​pi/​pilight#​ cp pilight-time-stuff/​actions/​*.* libs/​pilight/​events/​actions/</​code>​
  
 Then compile the sources to create the modules (.so files). Then compile the sources to create the modules (.so files).
Line 64: Line 74:
 root@raspi2:/​home/​pi/​pilight#​ gcc -fPIC -shared libs/​pilight/​events/​operators/​minustime.c -Ilibs/​pilight/​events -Iinc -o minustime.so -DMODULE=1 root@raspi2:/​home/​pi/​pilight#​ gcc -fPIC -shared libs/​pilight/​events/​operators/​minustime.c -Ilibs/​pilight/​events -Iinc -o minustime.so -DMODULE=1
 root@raspi2:/​home/​pi/​pilight#​ gcc -fPIC -shared libs/​pilight/​events/​operators/​random.c -Ilibs/​pilight/​events -Iinc -o random.so -DMODULE=1 root@raspi2:/​home/​pi/​pilight#​ gcc -fPIC -shared libs/​pilight/​events/​operators/​random.c -Ilibs/​pilight/​events -Iinc -o random.so -DMODULE=1
-root@raspi2:/​home/​pi/​pilight#​ gcc -fPIC -shared libs/​pilight/​protocols/​newdatetime.c -Ilibs/​pilight/​protocols -Iinc -o newdatetime.so -DMODULE=1</​code>​+root@raspi2:/​home/​pi/​pilight#​ gcc -fPIC -shared libs/​pilight/​protocols/​newdatetime.c -Ilibs/​pilight/​protocols -Iinc -o newdatetime.so -DMODULE=1 
 +root@raspi2:/​home/​pi/​pilight#​ gcc -fPIC -shared libs/​pilight/​events/​actions/​switch-rnd.c -Ilibs/​pilight/​events -Iinc -o switch-rnd.so -DMODULE=1</​code>​
  
 Next copy all the .so files you have just created to the appropriate subfolders of /​usr/​local/​lib/​pilight:​ Next copy all the .so files you have just created to the appropriate subfolders of /​usr/​local/​lib/​pilight:​
  
 <​code>​root@raspi2:/​home/​pi/​pilight#​ cp plustime.so minustime.so random.so /​usr/​local/​lib/​pilight/​operators/​ <​code>​root@raspi2:/​home/​pi/​pilight#​ cp plustime.so minustime.so random.so /​usr/​local/​lib/​pilight/​operators/​
-root@raspi2:/​home/​pi/​pilight#​ cp newdatetime.so /​usr/​local/​lib/​pilight/​protocols/</​code>​+root@raspi2:/​home/​pi/​pilight#​ cp newdatetime.so /​usr/​local/​lib/​pilight/​protocols
 +root@raspi2:/​home/​pi/​pilight#​ cp switch-rnd.so /​usr/​local/​lib/​pilight/​actions/</​code>​
  
 ==== Configuration ==== ==== Configuration ====
time_math_tutorial.1427710603.txt.gz · Last modified: 2015/11/27 21:08 (external edit)