# Chapter 5: Rule Engine administration guide

Warning

This documentation is out of date. For more information please check Gateway Documentation at Software part of the Handbook.

# Overview

Enapter Rule Engine should be used as a convenience feature for basic non-realtime automation and not for life-sustaining or safety-critical use cases. Rules depend on working internet, Wi-Fi, and Enapter Cloud. Enapter is not responsible for any harms or losses incurred as a result of any failed automation.

# Enapter Dryer Plugin

# Activation Plugin

[d0a09d] $ configure
[d0a09d] conf # set rule-engine plugin dryer enabled true
[d0a09d] conf # save
[d0a09d] conf # commit
[d0a09d] conf # exit

# Available Actions

Action Description
start-dryer Start dryer command
stop-dryer Stop dryer command
reboot-dryer Reboot dryer command

# Expressions Available in Conditions

Expression Description Values
online Device online status boolean
has_errors Indicates whether any device errors boolean
errors.value Dryer errors list table
state.value Dryer state one of waiting_for_power, waiting_for_pressure, stopped_by_user, starting, drying_0, cooling_0, switching_0, pressurizing_0, finalizing_0, drying_1, cooling_1, switching_1, pressurizing_1, finalizing_1, leak_input, leak_dryer, error
state.seconds_in_state Number of seconds in current state integer
input_pressure Input pressure (bar) float
input_pressure_avg(10) Input pressure (bar) 10 seconds average float
output_pressure Output pressure (bar) float
output_pressure_avg(10) Output pressure (bar) 10 seconds average float
device:is_running() Whether dryer currently running or not boolean

# Example

[d0a09d] conf # set rule-engine rule 10 condition 10 dryer <DRYER_DEVICE_ID> if "not device:is_running() and output_pressure_avg(120) < 30"

# Enapter Electrolyser Plugin

# Activation Plugin

[d0a09d] $ configure
[d0a09d] conf # set rule-engine plugin electrolyser enabled true
[d0a09d] conf # save
[d0a09d] conf # commit
[d0a09d] conf # exit

# Available Actions

Action Description
start-electrolyser Start electrolyser command
stop-electrolyser Stop electrolyser command
start-electrolyser-group Start electrolysers group command
stop-electrolyser-group Stop electrolysers group command

# Expressions Available in Conditions

Expression Description Values
online Device online status boolean
state.value Electrolyser state one of none, power_on, wait_start_comm, wait_power_cond, restart_with_max_press, delay_dc_dc, hydration, ramp_up, steady, ramp_down, purge, heating, error, warning
state.seconds_in_state Number of seconds in current state integer
stack_amp Electrolyser stack amperage float
stack_amp_avg(10) Electrolyser stack amperage 10 seconds average float
stack_volt Electrolyser stack voltage float
stack_volt_avg(10) Electrolyser stack voltage 10 seconds average float
device:is_running() Whether electrolyser currently running or not boolean

# Example

[d0a09d] conf # set rule-engine rule 10 condition 10 electrolyser <EL_DEVICE_ID> if "online and device:is_running() and state.value == 'steady' or stack_amp_avg(45) > 12.5"

# Enapter Electrolyser EL 2.1 Plugin

# Activation Plugin

[d0a09d] $ configure
[d0a09d] conf # set rule-engine plugin electrolyser-v21 enabled true
[d0a09d] conf # save
[d0a09d] conf # commit
[d0a09d] conf # exit

# Available Actions

Action Description
start-electrolyser-v21 Start electrolyser command
stop-electrolyser-v21 Stop electrolyser command
reset-electrolyser-v21 Reset electrolyser command

# Expressions Available in Conditions

Expression Description Values
online Device online status boolean
has_errors Indicates whether any device errors boolean
has_warnings Indicates whether any device warnings boolean
errors.value Electrolyser errors list table
warnings.value Electrolyser warnings list table
state.value Electrolyser state one of maintenance, expert, error, fatal, idle, steady, standby, curve, blowdown
state.seconds_in_state Number of seconds in current state integer
stack_state.value Electrolyser stack state one of none, maintenance, idle, warmingup, hydration, rampup1, rampup2, steady, purge, rampdown1, rampdown2, rampdown3, curve, maxpressure, halt
stack_state.seconds_in_state Number of seconds in current stack state integer
h2_flow Electrolyser current H2 production float
h2_flow_avg(10) Electrolyser current H2 production 10 seconds average float
outlet_pressure Outer Hydrogen Pressure float
outlet_pressure_avg(10) Outer Hydrogen Pressure 10 seconds average float
inlet_pressure Inlet Hydrogen Pressure float
inlet_pressure_avg(10) Inlet Hydrogen Pressure 10 seconds average float
water_inlet_pressure Water Inlet Pressure float
water_inlet_pressure_avg(10) Water Inlet Pressure 10 seconds average float
electrolyte_temperature Electrolyte Temperature float
electrolyte_temperature_avg(10) Electrolyte Temperature 10 seconds average float
stack_current Stack Current float
stack_current_avg(10) Stack Current 10 seconds average float
device:is_running() Whether electrolyser currently running or not boolean

# Example

[d0a09d] conf # set rule-engine rule 10 condition 10 electrolyser-v21 <EL_DEVICE_ID> if "online and device:is_running() and state.value == 'steady' or stack_amp_avg(45) > 12.5"

# EL 2.1 Heartbeat

set el21-heartbeat device <device_id> command added to the Electrolyser will activate Safety Heartbeat. If the Electrolyser does not receive the heartbeat in a time (heartbeat period) — the machine will normally shut down.

Adding notify-offline command will add the check of connection to Cloud.

  • notify-offline false - Heartbeat will be sent even Gateway is disconnected from Cloud

  • notify-offline true - if no connection between gateway and cloud - Heartbeat will not be sent

  • period - period of checks, in seconds

# Example

set el21-heartbeat device <EL21_DEVICE_ID>
set el21-heartbeat notify-offline true
set el21-heartbeat period 30

# Enapter Electrolyser EL 2.1 Smart Production Rate Control

Electrolyser EL 2.1 Smart Production Rate Control enables control of the group of the EL 2.1 electrolysers as if it is one big electrolyser. The plugin automatically selects the strategy for start and stop of the electrolyser and production control in the allowed ranges.

# Activation Plugin

[d0a09d] $ configure
[d0a09d] conf # set rule-engine plugin electrolyser-v21-smart-production-control enabled true
[d0a09d] conf # save
[d0a09d] conf # commit
[d0a09d] conf # exit

# Example

Enable plugin

[d0a09d] $ configure
[d0a09d] conf # set rule-engine plugin electrolyser-v21-smart-production-control enabled true
[d0a09d] conf # set rule-engine plugin electrolyser-v21 enabled true
[d0a09d] conf # commit
[d0a09d] conf # exit

Configure Public MQTT interface

[d0a09d] $ configure
[d0a09d] conf # set mqtt public authentication username public
[d0a09d] conf # set mqtt public authentication password public
[d0a09d] conf # set variables variable els-target-production type float

Enable EL 2.1 electrolysers management and aggregate them into one group

[d0a09d] conf # set rule-engine devices electrolyser-v21 HWID1 enabled true
[d0a09d] conf # set rule-engine devices electrolyser-v21 HWID2 enabled true
[d0a09d] conf # set rule-engine devices electrolyser-v21 HWID3 enabled true

[d0a09d] conf # set rule-engine groups electrolyser-v21 ELS device HWID1
[d0a09d] conf # set rule-engine groups electrolyser-v21 ELS device HWID2
[d0a09d] conf # set rule-engine groups electrolyser-v21 ELS device HWID3

Configure plugin to control group of electrolysers ELS with variable els-target-production

[d0a09d] conf # set rule-engine electrolyser-v21-smart-production-control SMART1 electrolysers-group ELS
[d0a09d] conf # set rule-engine electrolyser-v21-smart-production-control SMART1 target-production-variable-name els-target-production

Save and apply configuration

[d0a09d] conf # save
[d0a09d] conf # commit

To change variable setpoint from command interface to 1000 NL/h use the following command in configuration mode

[d0a09d] conf # run variables set els-target-production value 1000

It is also possible to access this variable through Public MQTT interface.

# Enapter Tank Module Plugin

# Activation Plugin

[d0a09d] $ configure
[d0a09d] conf # set rule-engine plugin tank enabled true
[d0a09d] conf # save
[d0a09d] conf # commit
[d0a09d] conf # exit

# Expressions Available in Conditions

Expression Description Values
online Device online status boolean
pressure1 Pressure input #1 value float
pressure1_avg(10) Pressure input #1 10 seconds average float
pressure2 Pressure input #2 value float
pressure2_avg(10) Pressure input #2 10 seconds average float
temp1 Temperature input #1 value float
temp1_avg(10) Temperature input #1 10 seconds average float
temp2 Temperature input #2 value float
temp2_avg(10) Temperature input #2 10 seconds average float

# Example

[d0a09d] conf # set rule-engine rule 10 condition 10 tank TNK1 if "pressure1_avg(120) < 30"

# Gas Sensor Plugin

# Activation Plugin

[d0a09d] $ configure
[d0a09d] conf # set rule-engine plugin gas-sensor enabled true
[d0a09d] conf # save
[d0a09d] conf # commit
[d0a09d] conf # exit

# Expressions Available in Conditions

Expression Description Values
online Device online status boolean
ai1 Analog input #1 value float
ai1_avg(10) Analog input #1 value 10 seconds average float
ai1_avg_with_offset(10, 60) Analog input #1 value 10 seconds average with 60 seconds offset float
ai2 Analog input #2 value float
ai2_avg(10) Analog input #2 value 10 seconds average float
ai2_avg_with_offset(10, 60) Analog input #2 value 10 seconds average with 60 seconds offset float
ai3 Analog input #3 value float
ai3_avg(10) Analog input #3 value 10 seconds average float
ai3_avg_with_offset(10, 60) Analog input #3 value 10 seconds average with 60 seconds offset float
ai4 Analog input #4 value float
ai4_avg(10) Analog input #4 value 10 seconds average float
ai4_avg_with_offset(10, 60) Analog input #4 value 10 seconds average with 60 seconds offset float

# Enapter RL6 Module Plugin

# Activation Plugin

[d0a09d] $ configure
[d0a09d] conf # set rule-engine plugin enp-rl6 enabled true
[d0a09d] conf # save
[d0a09d] conf # commit
[d0a09d] conf # exit

# Expressions Available in Conditions

Expression Description Values
online Device online status boolean
r1 Relay channel #1 state boolean
r2 Relay channel #2 state boolean
r3 Relay channel #3 state boolean
r4 Relay channel #4 state boolean
r5 Relay channel #5 state boolean
r6 Relay channel #6 state boolean

# Available Actions

Action Description
enp-rl6-open Open relay channel
enp-rl6-close Close relay channel
enp-rl6-impulse Send impulse to relay channel
enp-rl6-open-all Open all channels
enp-rl6-close-all Close all channels

# Example

[d0a09d] conf # set rule-engine rule 10 condition 10 enp-rl6 <RL6_DEVICE_ID> if "r1"

# Lua Conditions

Lua conditions can be used for programming complex logic dependent of several devices.

For more convenient work on complex scripts Enapter shell support editing values in Vim (default) or Nano editor. To set preferable editor use following command:

[d0a09d] conf # set shell editor nano

or

[d0a09d] conf # set shell editor vi

To edit value use edit command in configuration mode:

[d0a09d] conf # edit rule-engine rule 10-test condition 10 lua

To exit from Vim editor use :wq<Enter>

Lua condition code block expected to return boolean value.

The most simple Lua condition will be:

return true

# Multiple Electrolysers and Single Dryer Management Example for EL2.0 and DR

[d0a09d] $ conf
[d0a09d] conf # set shell editor nano
[d0a09d] conf # set rule-engine plugin electrolyser enabled true
[d0a09d] conf # set rule-engine plugin dryer enabled true
[d0a09d] conf # set rule-engine plugin dryer-management-rule enabled "true"
[d0a09d] conf # save
[d0a09d] conf # commit
[d0a09d] conf # exit
[d0a09d] $ conf
[d0a09d] conf # set rule-engine devices electrolyser <EL_1_DEVICE_ID> enabled true
[d0a09d] conf # set rule-engine devices electrolyser <EL_1_DEVICE_ID> power 2400
[d0a09d] conf # set rule-engine devices electrolyser <EL_2_DEVICE_ID> enabled true
[d0a09d] conf # set rule-engine devices electrolyser <EL_2_DEVICE_ID> power 2400
[d0a09d] conf # set rule-engine devices dryer <DRYER_DEVICE_ID> enabled "true"
[d0a09d] conf # set rule-engine dryer-management-rule 100-dryer-management dryer <DRYER_DEVICE_ID>
[d0a09d] conf # set rule-engine dryer-management-rule 100-dryer-management electrolyser <EL_1_DEVICE_ID>
[d0a09d] conf # set rule-engine dryer-management-rule 100-dryer-management electrolyser <EL_2_DEVICE_ID>

# Multiple Electrolysers and Single Dryer with PID regulation Example for EL2.1 and DR

This is example for managing production with pressure set point at 30 bar and minimal production rate at 60%.

[d0a09d] $ conf
[d0a09d] conf # set shell editor nano
[d0a09d] conf # set rule-engine plugin dryer enabled "true"
[d0a09d] conf # set rule-engine plugin electrolyser-v21 enabled "true"
[d0a09d] conf # set rule-engine plugin electrolyser-v21-dryer-output-based-production-pid enabled "true"
[d0a09d] conf # set rule-engine plugin dryer-management-rule enabled "true"
[d0a09d] conf # save
[d0a09d] conf # commit
[d0a09d] conf # exit
[d0a09d] $ conf
[d0a09d] conf # set rule-engine devices dryer <DRYER_DEVICE_ID> enabled "true"
[d0a09d] conf # set rule-engine devices electrolyser-v21 <EL_1_DEVICE_ID> enabled "true"
[d0a09d] conf # set rule-engine devices electrolyser-v21 <EL_1_DEVICE_ID> power "2400"
[d0a09d] conf # set rule-engine devices electrolyser-v21 <EL_2_DEVICE_ID> enabled "true"
[d0a09d] conf # set rule-engine devices electrolyser-v21 <EL_2_DEVICE_ID> power "2400"
[d0a09d] conf # set rule-engine plugin electrolyser-v21-dryer-output-based-production-pid enabled "true"
[d0a09d] conf # set rule-engine dryer-management-rule 100-dryer-mgmt dryer <DRYER_DEVICE_ID>
[d0a09d] conf # set rule-engine dryer-management-rule 100-dryer-mgmt electrolyser <EL_1_DEVICE_ID>
[d0a09d] conf # set rule-engine dryer-management-rule 100-dryer-mgmt electrolyser <EL_2_DEVICE_ID>
[d0a09d] conf # set rule-engine electrolyser-v21-dryer-output-based-production-pid 500-pid d "1"
[d0a09d] conf # set rule-engine electrolyser-v21-dryer-output-based-production-pid 500-pid dryers-group "PID-DRYER"
[d0a09d] conf # set rule-engine electrolyser-v21-dryer-output-based-production-pid 500-pid electrolysers-group "PID-ELS"
[d0a09d] conf # set rule-engine electrolyser-v21-dryer-output-based-production-pid 500-pid i "0.001"
[d0a09d] conf # set rule-engine electrolyser-v21-dryer-output-based-production-pid 500-pid min "60"
[d0a09d] conf # set rule-engine electrolyser-v21-dryer-output-based-production-pid 500-pid p "2"
[d0a09d] conf # set rule-engine electrolyser-v21-dryer-output-based-production-pid 500-pid target-pressure "30"
[d0a09d] conf # set rule-engine groups dryer PID-DRYER device <DRYER_DEVICE_ID>
[d0a09d] conf # set rule-engine groups electrolyser-v21 PID-ELS device <EL_1_DEVICE_ID>
[d0a09d] conf # set rule-engine groups electrolyser-v21 PID-ELS device <EL_2_DEVICE_ID>

# 6 Steps for Time-based Electrolyser Start / Stop using Lua

This example uses os.date (opens new window) function. EL 2.1 device id 123 is dummy and for real use case you should use device available in rule engine. Please note that rule engine operates with GMT.

  1. Enter configuration mode:
[bd0745] $ configure
[bd0745] conf #
  1. Enable plugin:
[bd0745] conf # set rule-engine plugin electrolyser-v21 enabled true
[bd0745] conf #
  1. Save configuration and restart configuration
[bd0745] conf # commit
[bd0745] conf # save
[bd0745] conf # exit
[bd0745] $ configure
[bd0745] conf #
  1. Enable Electrolyser with ID 123 (use TAB for autocompletion)
[bd0745] conf # set rule-engine devices electrolyser-v21 123 enabled true
[bd0745] conf # set rule-engine devices electrolyser-v21 123 power 2400
[bd0745] conf # set rule-engine devices electrolyser-v21 123 cooldown-period 60
[bd0745] conf #
  1. Set the time based control rule. Start EL 2.1 ID 123 at 15:05 GMT.
[bd0745] conf # set rule-engine rule 10 action 1 start-electrolyser-v21 device 123
[bd0745] conf # set rule-engine rule 10 condition 1 lua "return os.date('%H:%M') == '15:05'"
[bd0745] conf #
  1. Set the time based control rule. Stop EL 2.1 ID 123 at 16:05 GMT.
[bd0745] conf # set rule-engine rule 20 action 1 stop-electrolyser-v21 device 123
[bd0745] conf # set rule-engine rule 20 condition 1 lua "return os.date('%H:%M') == '16:05'"
[bd0745] conf #