Difference between revisions of "Rules"

From wiki.netio-products.com
Jump to navigation Jump to search
(Created page with "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, to...")
 
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.
+
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.
 
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.
 
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.
  
Line 124: Line 124:
 
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.
 
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 definition'''
PAB name: '''Watch_out1_load'''
+
 
 +
PAB name: '''Watch_out1_load'''
 
  <nowiki>
 
  <nowiki>
 
{
 
{
Line 135: Line 136:
 
}</nowiki>
 
}</nowiki>
  
'''Rules definition'''
+
'''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.
 
''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'''
 
Schedule name: '''Working_hours'''
  
Line 152: Line 155:
 
}</nowiki>
 
}</nowiki>
  
=== Example for RANGE-type PAB (multiple action for one condition)
+
=== 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.
 
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 definition'''
 +
 
 
PAB name: '''Watch_out4_load'''
 
PAB name: '''Watch_out4_load'''
 
    
 
    
Line 167: Line 171:
  
  
'''Action definition'''
+
'''Action definition'''
 
  <nowiki>
 
  <nowiki>
 
{
 
{
Line 180: Line 184:
  
 
=== Example for ZONE-type PAB ===
 
=== Example for ZONE-type PAB ===
U této podmínky se sleduje se proud u druhého výstupu. Dle naměřené výše se zařadí do stanovené zóny. V závislosti na tom, v jaké zóně se zovna nachází lze vyvolávat různé akce:
 
 
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:
 
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 0, restart device on output 1
 
* If the value of current is in zone 2, turn ON alarm in Cloud
 
* If the value of current is in zone 2, turn ON alarm in Cloud
  
'''PAB definition'''
+
'''PAB definition'''
Název PAB: **Watch_out2_current**  
+
 
```
+
PAB name: '''Watch_out2_current'''
 +
  <nowiki>
 
{
 
{
 
   "type": "ZONES",
 
   "type": "ZONES",
Line 196: Line 200:
 
   ],
 
   ],
 
   "timeHysteresis": 10
 
   "timeHysteresis": 10
}
+
}</nowiki>  
 
 
```  
 
 
**Definice Rules**  
 
**Definice Rules**  
Musí být definováno ve dvou pravidlech, protože mají různé podmínky.
+
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   
 
* Pokud se PAB nachází v zóně 0 (0-49mA), restartuj zařízení na výstupu 1   

Revision as of 10:52, 20 October 2021

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 filters variable. If the precondition in filter is not met, conditions do not get evaluated. When all the conditions specified in conditions are met (and the preconditions in filters as well), all actions defined in actions will be executed.

Structure

Variable Value Description
conditions Eg: `"PAB/PAB1_1/IN": true` Field for defining conditions, relationship between conditions according to 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, relationship always AND
actions Eg: "CLOUD/OUTPUT/1/ALARM": "${COND_RESULT}" 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

  • "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

Available forms of filters

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

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.

ACTIONS - how to control outputs

  • 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)

Rules examples

Watchdog monitoring

Monitor the address defined in WATCHDOG_1. If the Watchdog fails, restart device at output 1 (action 2 = SHORT OFF)

{
  "conditions": {
    "WDT/WATCHDOG_1/FAIL": true
  },
  "actions": {
    "OUTPUTS/1/ACTION": 2
  }
}

Watchdog monitoring with filter

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.

{
  "conditions": {
    "WDT/WATCHDOG_1/FAIL": true
  },
  "filters": {
    "OUTPUTS/4/STATE": "on"
  },
  "actions": {
    "OUTPUTS/4/ACTION": 2
  }
}

PAB - zones

If PAB_ZONE_1 is in zone 1 and the TestSchedule is active at the same time, turn ON output 4 (action 1 = ON)

{
  "conditions": {
    "PAB/PAB_ZONE_1/ZONE": 1
  },
  "filters": {
    "SCHEDULE/TestSchedule/ACTIVE": true
  },
  "actions": {
    "OUTPUTS/4/ACTION": 1
  }
}

PAB - range

If PAB1_1 or PAB1_2 are true, trigger an alarm in Cloud at output 1

{
  "conditions": {
    "operator": "OR",
    "PAB/PAB1_1/IN": true,
    "PAB/PAB1_2/IN": true
  },
  "actions": {
    "CLOUD/OUTPUT/1/ALARM": "${COND_RESULT}"
  }
}

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

{
  "type": "RANGE",
  "source": "OUTPUTS/1/LOAD",
  "lowerBound": 100,
  "upperBound": 500,
  "timeHysteresis": 10
}

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

{
  "conditions": {
    "PAB/Watch_out1_load/IN": 0
  },
  "filters": {
    "SCHEDULE/Working_hours/ACTIVE": true
  },
  "actions": {
    "OUTPUTS/1/ACTION": 2
  }
}

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

{
  "type": "RANGE",
  "source": "OUTPUTS/4/LOAD",
  "lowerBound": 0,
  "upperBound": 600
}


Action definition

{
  "conditions": {
    "PAB/Watch_out4_load/IN": 0
  }
  "actions": {
    "OUTPUTS/4/ACTION": 0,
    "CLOUD/OUTPUT/1/ALARM": "${COND_RESULT}"
  }
}

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

{
  "type": "ZONES",
  "source": "OUTPUTS/2/CURRENT",
  "thresholds": [
    50,
    150,
  ],
  "timeHysteresis": 10
}  
    • 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}"
 }

} ``` ---

      1. 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
 }

} ```

    1. Otázky
  • Tlačítko SHOW VARIABLES (zobrazí všechny použitelné proměnné) - zatím není
  • Podpora operátoru zatím není (default je OR)
  • Více alarmů k Outputu - jak funguje?