Rules

Moderators: Voyager, BertB, grovkillen, Stuntteam, LisaM

Locked
Message
Author
LisaM
Normal user
Posts: 513
Joined: 11 Apr 2017, 18:29

Rules

#1 Post by LisaM » 24 Jan 2018, 11:19

The Rules currently working on my almost there beta-1 release:

File: test.rule

Code: Select all

if event['Test#Temperature'] > 15 :
     gpio('d12',1)
     timerSet(1,15)   # seconds
File: boot.rule

Code: Select all

if event['system#boot']:
     gpio('d12',0)
     timerSet(1,15)   # seconds
File: timertest.rule

Code: Select all

if event['Rules#Timer'] == 1 :
     gpio('d12',0)
Rules are miniature python programs with a fixed context. The syntax must comply with the Python syntax: https://en.wikipedia.org/wiki/Python_sy ... _semantics
So far only the structure (dictionary) event is available, together with these functions gpio and timerSet.
It's mandatory that every rule starts with if <trigger> :
Every line following this line is, according to Python syntax, indented with the same number of spaces.
Since it's Python, it's also possible to use else: which should be placed at the beginning of the line.

A short explanation:
event contains the <trigger>:
  • <event>

OR
  • <event><comparison operator function><value>
Where the "comparison operator function" is any legal Python comparison function: https://www.tutorialspoint.com/python/c ... xample.htm

The <event> can be:
  • <taskname>#<valuename>
  • Rules#Timer
  • System#Boot
Where <taskname> is the name of the task in the device and <valuename> is the name of the value in that task.

The <value> can be anything, as long as it's the same type as the contents of the <valuename>

The function <gpio> has two parameters:
  • port: the gpio port like 'd13'
  • level: the gpio port level like 0 (low) or 1 (high)
The function <timerSet> (case sensitive!) has two parameters:
  • timer: the timer number which is an integer between 1 and 10
  • seconds: the number of seconds before the timer is triggered
In time all of these commands: https://www.letscontrolit.com/wiki/inde ... _Reference will be added.

All three rule files which reside in the rules directory attached.
Attachments
rules.zip
(628 Bytes) Downloaded 526 times

Locked

Who is online

Users browsing this forum: No registered users and 3 guests