Difference between revisions of "Rules"

From wiki.netio-products.com
Jump to navigation Jump to search
(Available forms of conditions)
(18 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Rules allow to trigger follow-up actions based on fulfillment of specified conditions (defined by PAB or Watchdog). The actions can change output states (turn OFF, turn ON, toggle, etc.) or trigger an alarm in Cloud. There can be more conditions for one action and based on definition must apply both (AND) or at least one of them (OR). Also, multiple actions can be defined for a set of conditions. Additionally , evaluation of actions can be filtered by conditions set in <code>filters</code> variable. If the precondition in filter is not met, conditions do not get evaluated.
+
Each Rule define the follow-up actions based on current DI / [https://wiki.netio-products.com/index.php?title=PAB '''PAB''']/ [https://wiki.netio-products.com/index.php?title=Watchdog '''WatchDog'''] function state. There can be several Rules executed based on one PAB function (switch output if Current > 1000 mA + Send Alert to NETIO Cloud IF Current > 500 mA). One Rule can be executed based on combination of several PAB / WatchDog states.  
When all the conditions specified in <code>conditions</code> are met (and the preconditions in <code>filters</code> as well), all actions defined in <code>actions</code> will be executed.
 
  
== Structure ==
+
== CONDITION ==
 
+
Rule conditions define when the action part of each Rule is executed. There can be multiple conditions for one Rule.
{| class="wikitable"
+
In order to execute the action, all conditions have to be valid (AND operator) / at least one of the conditions have to be valid (OR operator).
|-
 
! Variable
 
! Value
 
! Description
 
|-
 
| conditions
 
| Eg: `"PAB/PAB1_1/IN": true`
 
| Field for defining conditions, relationship between conditions according to <code>operator</code> (AND/OR)
 
|-
 
| operator
 
| AND/OR
 
| Optional. Specifies relationship between conditions. <code>AND</code> = all conditions must apply at the same time. <code>OR</code> = at least one condition must apply. If missing, defaults to <code>OR</code>
 
|-
 
| filters
 
| Eg: <code>"SCHEDULE/MY_SCHEDULE/ACTIVE": true<code/>
 
| Filter definition, relationship always <code>AND</code>
 
|-
 
| actions
 
| Eg: <code>"CLOUD/OUTPUT/1/ALARM": "${COND_RESULT}"</code>
 
| Actions definition
 
|}
 
 
 
Condition names are based on user-specified names and their types.
 
For PABs, the name has structure: '''PAB/pab_name/pab_output_value''' (TRUE/FALSE or int)
 
For Watchdogs, the name has structure: '''WDT/watchdog_name/FAIL'''
 
  
 
=== Available forms of conditions ===
 
=== Available forms of conditions ===
Line 35: Line 9:
 
* <code>"PAB/PAB_ZONE_1/ZONE": 1</code> = <code>PAB_ZONE_1</code> is in zone 1
 
* <code>"PAB/PAB_ZONE_1/ZONE": 1</code> = <code>PAB_ZONE_1</code> is in zone 1
 
* <code>"WDT/WATCHDOG_1/FAIL": true</code> = <code>WATCHDOG_1</code> is in ERROR state
 
* <code>"WDT/WATCHDOG_1/FAIL": true</code> = <code>WATCHDOG_1</code> is in ERROR state
 +
* <code>"INPUTS/1/STATE": "on"</code> = DI1 is currently ON (1)
 +
* <code>"INPUTS/1/STATE": "off"</code> = DI1 is currently OFF (0)
 +
 +
== FILTER (mask)==
 +
The filter field specifies when the Rule is active. It acts as a mask If filter in certain time is not true, the action wont be executed even when conditions are fulfilled. Multiple filters can be set for one rule. For the rule to be active all filters must be true.
 +
 +
Above that the FILTER can be applied (scheduler, DI (Digital Input) or DO (Output) state).
  
 
=== Available forms of filters ===
 
=== Available forms of filters ===
 
* <code>"SCHEDULE/TestSchedule/ACTIVE": true</code> = <code>TestSchedule</code> is active
 
* <code>"SCHEDULE/TestSchedule/ACTIVE": true</code> = <code>TestSchedule</code> is active
 
* <code>"OUTPUTS/1/STATE":"on"</code> = Output 1 is ON
 
* <code>"OUTPUTS/1/STATE":"on"</code> = Output 1 is ON
 +
 +
 +
== ACTION ==
 +
ACTIONS part in the Rule contains list of several actions when condition(s) + filter(s) are valid.
 +
 +
The actions can change output states (turn OFF, turn ON, toggle, etc.) or trigger an Alarm state in NETIO Cloud.
 +
There is one Alarm state reserved per each one output in the NETIO Cloud premium (only).
 +
You can verify your configuration and check sending of the Output Alarm in the Device Log.
  
 
=== Available forms of actions ===
 
=== Available forms of actions ===
Line 47: Line 36:
 
''Note: The variable <code>${COND_RESULT}</code> contains output value of the given condition. It takes values 0 (condition not met) or 1 (condition met). It can be used for dynamic switching the alarm in Cloud ON/OFF depending on current state of the PAB.''
 
''Note: The variable <code>${COND_RESULT}</code> contains output value of the given condition. It takes values 0 (condition not met) or 1 (condition met). It can be used for dynamic switching the alarm in Cloud ON/OFF depending on current state of the PAB.''
  
=== ACTIONS - how to control outputs ===
+
 
 +
=== Standard output actions per each output ===
 
* 0 = TURN OFF
 
* 0 = TURN OFF
 
* 1 = TURN ON
 
* 1 = TURN ON
Line 55: Line 45:
 
* 5 = NOTHING (placeholder, DO NOT USE)
 
* 5 = NOTHING (placeholder, DO NOT USE)
  
== Rules examples ==
 
=== Watchdog monitoring ===
 
Monitor the address defined in WATCHDOG_1. If the Watchdog fails, restart device at output 1 (action 2 = SHORT OFF)
 
<nowiki>
 
{
 
  "conditions": {
 
    "WDT/WATCHDOG_1/FAIL": true
 
  },
 
  "actions": {
 
    "OUTPUTS/1/ACTION": 2
 
  }
 
}</nowiki>
 
  
----
 
  
=== Watchdog monitoring with filter ===
+
== Structure ==
Monitor the address defined in WATCHDOG_1. If output 4 is ON (condition in filters) and the Watchdog reports a failure, restart device on output 4.
 
<nowiki>
 
{
 
  "conditions": {
 
    "WDT/WATCHDOG_1/FAIL": true
 
  },
 
  "filters": {
 
    "OUTPUTS/4/STATE": "on"
 
  },
 
  "actions": {
 
    "OUTPUTS/4/ACTION": 2
 
  }
 
}</nowiki>
 
  
----
+
{| class="wikitable"
 
+
|-
=== PAB - zones ===
+
! Variable
If PAB_ZONE_1 is in zone 1 and the TestSchedule is active at the same time, turn ON output 4 (action 1 = ON)
+
! Value
<nowiki>
+
! Description
{
+
|-
  "conditions": {
+
| conditions
    "PAB/PAB_ZONE_1/ZONE": 1
+
| Eg: `"PAB/PAB1_1/IN": true`
  },
+
| Conditions definition. Relationship between conditions is defined by <code>operator</code> (AND/OR)
  "filters": {
+
|-
    "SCHEDULE/TestSchedule/ACTIVE": true
+
| operator
  },
+
| AND/OR
  "actions": {
+
| Optional. Specifies relationship between conditions. <code>AND</code> = all conditions must apply at the same time. <code>OR</code> = at least one condition must apply. If missing, defaults to <code>OR</code>
    "OUTPUTS/4/ACTION": 1
+
|-
  }
+
| filters
}</nowiki>
+
| Eg: <code>"SCHEDULE/MY_SCHEDULE/ACTIVE": true<code/>
 
+
| Filter definition. For multiple filter conditions, the relationship between them is always <code>AND</code>
---- 
+
|-
 
+
| actions
=== PAB - range ===
+
| Eg: <code>"CLOUD/OUTPUT/1/ALARM": "${COND_RESULT}"</code>
If PAB1_1 or PAB1_2 are <code>true</code>, trigger an alarm in Cloud at output 1
+
| Actions definition. All actions defined here will be triggered when conditions (and filters) are met
<nowiki>
+
|}
{
 
  "conditions": {
 
    "operator": "OR",
 
    "PAB/PAB1_1/IN": true,
 
    "PAB/PAB1_2/IN": true
 
  },
 
  "actions": {
 
    "CLOUD/OUTPUT/1/ALARM": "${COND_RESULT}"
 
  }
 
}</nowiki>
 
 
 
== Complete examples of conditions and rules settings ==
 
=== Example for RANGE-type PAB ===
 
Níže popsané nastavení má za úkol kontrolovat zařízení připojené na prvním výstupu. U zařízení se očekává, že má v pracovních hodinách určitý odběr (load) v rozsahu 100 až 500W. Pokud bude odběr příliš nízký nebo vysoký (tzn. mimo zadaný interval) po dobu delší než 10s, je pravděpodobné, že se zařízení nachází v nežádaném stavu a je potřeba restart, který stav napraví.
 
 
 
The setting described below is intended to monitor a device connected to first output. The device is expected to have a certain load between 100W and 500W during working hours. If the consumption is too low or too high (i.e. outside the specified interval) for more than 10s, it is likely that the device works incorrectly and restart is needed to correct its state.
 
 
 
'''PAB definition'''
 
 
 
PAB name: '''Watch_out1_load'''
 
<nowiki>
 
{
 
  "type": "RANGE",
 
  "source": "OUTPUTS/1/LOAD",
 
  "lowerBound": 100,
 
  "upperBound": 500,
 
  "timeHysteresis": 10
 
}</nowiki>
 
 
 
'''Rules definition'''
 
 
 
''Note: We use the Schedules functionality in the filter to define working hours of the week. The device monitoring will only work at time set in the Schedule.
 
 
 
Schedule name: '''Working_hours'''
 
 
 
<nowiki>
 
{
 
  "conditions": {
 
    "PAB/Watch_out1_load/IN": 0
 
  },
 
  "filters": {
 
    "SCHEDULE/Working_hours/ACTIVE": true
 
  },
 
  "actions": {
 
    "OUTPUTS/1/ACTION": 2
 
  }
 
}</nowiki>
 
 
 
=== Example for RANGE-type PAB (multiple action for one condition) ===
 
Defined condition checks a device connected to output 4. The device is expected to have a maximum load of 600W. If the load is too high, we want to immediately turn off the device and send an alarm to Cloud.
 
 
 
'''PAB definition'''
 
 
 
PAB name: '''Watch_out4_load'''
 
 
 
<nowiki>
 
{
 
  "type": "RANGE",
 
  "source": "OUTPUTS/4/LOAD",
 
  "lowerBound": 0,
 
  "upperBound": 600
 
}</nowiki>
 
 
 
 
 
'''Action definition'''
 
<nowiki>
 
{
 
  "conditions": {
 
    "PAB/Watch_out4_load/IN": 0
 
  }
 
  "actions": {
 
    "OUTPUTS/4/ACTION": 0,
 
    "CLOUD/OUTPUT/1/ALARM": "${COND_RESULT}"
 
  }
 
}</nowiki>
 
 
 
=== Example for ZONE-type PAB ===
 
In this condition, the value of current at the output 2 is monitored. It is then classified to respective zone according to measured value. Depending on the zone in which is classified, different actions can be triggered:
 
* If the value of current is in zone 0, restart device on output 1
 
* If the value of current is in zone 2, turn ON alarm in Cloud
 
 
 
'''PAB definition'''
 
 
 
PAB name: '''Watch_out2_current'''
 
<nowiki>
 
{
 
  "type": "ZONES",
 
  "source": "OUTPUTS/2/CURRENT",
 
  "thresholds": [
 
    50,
 
    150,
 
  ],
 
  "timeHysteresis": 10
 
}</nowiki>
 
**Definice Rules**
 
Must be defined in two separate Rules because they contain different conditions
 
 
 
* Pokud se PAB nachází v zóně 0 (0-49mA), restartuj zařízení na výstupu 1 
 
* Název pravidla: **Zone_restart** 
 
```
 
{
 
  "conditions": {
 
    "PAB/Watch_out2_current/ZONE": 0
 
  },
 
  "actions": {
 
    "OUTPUTS/1/ACTION": 2
 
  }
 
}
 
```
 
* Pokud se PAB nachází v zóně 2 (150+ mA), pošli Cloudu alarm s číslem zóny 
 
* **Zone_alarm** 
 
```
 
{
 
  "conditions": {
 
    "PAB/Watch_out2_current/ZONE": 2
 
  },
 
  "actions": {
 
    "CLOUD/OUTPUT/1/ALARM": "${COND_RESULT}"
 
  }
 
}
 
``` 
 
--- 
 
 
 
### Příklad pro použití Watchdogu 
 
Watchdog sleduje zadanou IP adresu. Ping se posílá každých 60s a čeká 5s na odpověď zařízení. Pokud se ping nepodaří 2x po sobě, vrátí Watchdog hodnotu **false** a restartuje zařízení. Po restartu zařízení počká 120s a začíná znovu sledovat. Tento cyklus opakuje znovu celkem 3x a pokud se ani jednou zařízení neohlásí, zůstává Watchdog v chybovém a znovu již zařízení nerestartuje.
 
 
 
**Definice Watchdogu** 
 
Název Watchdogu:
 
**Watch_101_180** 
 
```
 
{
 
  "target": "192.168.101.180",
 
  "pingInterval": 60,
 
  "timeout": 5,
 
  "maxTimeouts": 2,
 
  "timeToReboot": 120,
 
  "maxRestarts": 3
 
}
 
```
 
**Definice Rules** 
 
Název pravidla:
 
**Watch_101_180_restart** 
 
```
 
{
 
  "conditions": {
 
    "WDT/Watch_101_180/FAIL": true
 
  },
 
  "actions": {
 
    "OUTPUTS/1/ACTION": 2
 
  }
 
}
 
```
 
  
## Otázky
+
Condition names are based on user-specified names and their types:
* Tlačítko SHOW VARIABLES (zobrazí všechny použitelné proměnné) - zatím není
+
* For PABs, the name has structure: <code>PAB/pab_name/pab_output_value</code> (TRUE/FALSE or int)
* Podpora operátoru zatím není (default je OR)
+
* For WatchDogs, the name has structure: <code>WDT/watchdog_name/FAIL</code>
* Více alarmů k Outputu - jak funguje?
 

Revision as of 13:25, 18 November 2021

Each Rule define the follow-up actions based on current DI / PAB/ WatchDog function state. There can be several Rules executed based on one PAB function (switch output if Current > 1000 mA + Send Alert to NETIO Cloud IF Current > 500 mA). One Rule can be executed based on combination of several PAB / WatchDog states.

CONDITION

Rule conditions define when the action part of each Rule is executed. There can be multiple conditions for one Rule. In order to execute the action, all conditions have to be valid (AND operator) / at least one of the conditions have to be valid (OR operator).

Available forms of conditions

  • "PAB/PAB1_1/IN": true = PAB1_1 is in specified interval
  • "PAB/PAB_ZONE_1/ZONE": 1 = PAB_ZONE_1 is in zone 1
  • "WDT/WATCHDOG_1/FAIL": true = WATCHDOG_1 is in ERROR state
  • "INPUTS/1/STATE": "on" = DI1 is currently ON (1)
  • "INPUTS/1/STATE": "off" = DI1 is currently OFF (0)

FILTER (mask)

The filter field specifies when the Rule is active. It acts as a mask If filter in certain time is not true, the action wont be executed even when conditions are fulfilled. Multiple filters can be set for one rule. For the rule to be active all filters must be true.

Above that the FILTER can be applied (scheduler, DI (Digital Input) or DO (Output) state).

Available forms of filters

  • "SCHEDULE/TestSchedule/ACTIVE": true = TestSchedule is active
  • "OUTPUTS/1/STATE":"on" = Output 1 is ON


ACTION

ACTIONS part in the Rule contains list of several actions when condition(s) + filter(s) are valid.

The actions can change output states (turn OFF, turn ON, toggle, etc.) or trigger an Alarm state in NETIO Cloud. There is one Alarm state reserved per each one output in the NETIO Cloud premium (only). You can verify your configuration and check sending of the Output Alarm in the Device Log.

Available forms of actions

  • "OUTPUTS/1/ACTION": 0 = Turn OFF Output 1
  • "OUTPUTS/6/ACTION": 2 = Short OFF Output 6
  • "CLOUD/OUTPUT/1/ALARM": "${COND_RESULT}" = Set condition output value to the alarm (Turns the alarm ON or OFF based on condition evaluation)

Note: The variable ${COND_RESULT} contains output value of the given condition. It takes values 0 (condition not met) or 1 (condition met). It can be used for dynamic switching the alarm in Cloud ON/OFF depending on current state of the PAB.


Standard output actions per each output

  • 0 = TURN OFF
  • 1 = TURN ON
  • 2 = SHORT OFF
  • 3 = SHORT ON
  • 4 = TOGGLE - Changes the status from ON to OFF and vice versa
  • 5 = NOTHING (placeholder, DO NOT USE)


Structure

Variable Value Description
conditions Eg: `"PAB/PAB1_1/IN": true` Conditions definition. Relationship between conditions is defined by operator (AND/OR)
operator AND/OR Optional. Specifies relationship between conditions. AND = all conditions must apply at the same time. OR = at least one condition must apply. If missing, defaults to OR
filters Eg: "SCHEDULE/MY_SCHEDULE/ACTIVE": true Filter definition. For multiple filter conditions, the relationship between them is always AND
actions Eg: "CLOUD/OUTPUT/1/ALARM": "${COND_RESULT}" Actions definition. All actions defined here will be triggered when conditions (and filters) are met

Condition names are based on user-specified names and their types:

  • For PABs, the name has structure: PAB/pab_name/pab_output_value (TRUE/FALSE or int)
  • For WatchDogs, the name has structure: WDT/watchdog_name/FAIL