Menu

Rules_section

Anthony Damago

Rules section

This page defines syntax and possible scenarios within Rules section of a linknx [Configuration] file.

A rule is composed of:

  • one condition which has at least one defined trigger,
  • an (optional) action list to be executed when the condition is evaluated as true (type="if-true"),
  • and another optional action list to be executed when the condition is evaluated as false (type="if-false"),
  • and another optional action list to be executed when the condition is evaluated as true and id was false before (i.e. the condition had just changed from false to true) (type="on-false"),
  • and another optional action list to be executed in case when the condition was false before and had just become true (type="on-true").

        <rule id="xxxx">
            <condition type="...." trigger="true">
                .....
            </condition>
            <actionlist>
                <action ..... />
                .....
            </actionlist>
            <actionlist type="on-false">
                <action ..... />
            </actionlist>
            <actionlist type="if-true">
                <action ..... />
            </actionlist>
            <actionlist type="if-false">
                <action ..... />
            </actionlist>
        </rule>
    

The rule will be evaluated whenever one of its "trigger" conditions defined within the rule's condition changes it's state. Than the rule itself is evaluated and linknx decieds which actionlist should be executed.

The following condition's types are available (see [Condition's_Syntax] section):

  • object: true if the object has the specified value (<Description> section of rule definition is purely for informative purposes

First sample rule:

        <rule id="cur_time_date">
            <condition type="timer" trigger="true">
                <every>3600</every>
            </condition>
            <actionlist>
                <action type="set-value" id="cur_time" value="now" />
                <action type="set-value" id="cur_date" value="now" />
            </actionlist>
        </rule>

This rule will trigger and evaluate to true every 3600 seconds. The configured actions will then send current time/date on the KNX bus.

Now we can have a look at a more complex timer condition:

        <rule id="heating_morning">
            <condition type="and">
                <condition type="object" id="heating_auto" value="on" />
                <condition type="or">
                    <condition type="timer" trigger="true">
                        <at hour="6" min="30" exception="no" wdays="12345" />
                        <until hour="8" min="0" />
                    </condition>
                    <condition type="timer" trigger="true">
                        <at hour="8" min="0" wdays="67" />
                        <until hour="12" min="0" />
                    </condition>
                    <condition type="timer" trigger="true">
                        <at hour="8" min="0" exception="yes" />
                        <until hour="12" min="0" />
                    </condition>
                </condition>
            </condition>
            <actionlist>
                <action type="set-value" id="heating_kitchen" value="comfort" />
                <action type="set-value" id="heating_living" value="standby" />
                <action type="set-value" id="heating_bathroom" value="on" />
                <action type="set-value" id="heating_bedroom1" value="comfort" />
                <action type="set-value" id="heating_bedroom2" value="comfort" />
            </actionlist>
            <actionlist type="on-false">
                <action type="set-value" id="heating_kitchen" value="frost" />
                <action type="set-value" id="heating_living" value="frost" />
                <action type="set-value" id="heating_bathroom" value="off" />
                <action type="set-value" id="heating_bedroom1" value="frost" />
                <action type="set-value" id="heating_bedroom2" value="frost" />
            </actionlist>
        </rule>

This rule will only execute its action lists at specific times, but if heating_auto object is "on".
First action list will be executed:

  • At 6:30 am every week day that is not flagged as an exception day in "services" section
  • At 8:00 am every weekend day or day flagged as an exception day

Second action list will be executed:

  • At 8:00 am every week day that is not flagged as an exception day in "services" section
  • At 12:00 am every weekend day or day flagged as an exception day

Note that the object condition on "heating_auto" has no trigger flag. This means that if "heating_auto" is turned on at 7:00 am a week day, the action list will not be executed at that time because the rule is not evaluated on change of "heating_auto"'s value.

Next example: tell linknx to evaluate the rule during startup:

        <rule id="calculate_any_light_status" init="eval">
          <condition type="or">
             <condition type="object" id="light1" value="on" trigger="true"/>
             <condition type="object" id="light2" value="on" trigger="true"/>
             <condition type="object" id="light3" value="on" trigger="true"/>
          </condition>
          <actionlist>
             <action type="set-value" id="some_light_on" value="on" />
          </actionlist>
          <actionlist type="on-false">
             <action type="set-value" id="some_light_on" value="off" />
          </actionlist>
        </rule>

The same can be forced to true or false during startup:

          <rule id="calculate_any_light_status" init="true">

          <rule id="calculate_any_light_status" init="false">

Last example, this time with a "dim-up" action:

        <rule id="wakeup_alarm">
            <condition type="and">
                <condition type="object" id="absence" value="off" />
                <condition type="object" id="wakeup_active" value="on" />
                <condition type="timer" trigger="true">
                    <at hour="6" min="30" exception="no" wdays="12345" />
                </condition>
            </condition>
            <actionlist>
                <action type="dim-up" id="dim_value_bedroom2"
                    start="0" stop="240" duration="1800" />
            </actionlist>
        </rule>

This rule will start dimming the bedroom light progressively from 0 to 94% (=240/255) during half an hour (=1800 sec). It will only execute at 6:30 am every week day that is not flagged as an exception day, if it is activated (wakeup_active on) and if we are at home (absence off).

Rules on linknx startup

Please note, that some rules will be evaluated and triggered when linknx starts up and reads the configuration file, and some will not be triggered. This can be to some extent controlled by the init=true or init=false attribute. The detailed [Linknx_rules_on_startup] page contains detailed discussion of this topic.


Related

Wiki: Condition's_Syntax
Wiki: Configuration
Wiki: Linknx_rules_on_startup
Wiki: Main_Page

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.