Rules and Actions

Your hub should be generating events in the queue, but they are not currently being processed. The Rules Engine is the module that handles this, and it should already have been installed. We just need to enable it by uncommenting lines 33 and 64 in main_sched.py and restarting the controller.

A sample Rule R1 has already been provided in the skeleton database, which is linked to Condition C1 that is generating the events. There is also a sample Action A1, but currently they are both disabled. You should enable them both now.  Rules are simply constructs that bind an Action to a Condition.

 

Actions use the familiar helper functions approach, but in this case they all reside in a single file action_helpers.py  In this example we are going to use the action_actuator Action, but future actions could be added to perform any task. The Actuator Function is set to action_actuator.1, which translates as:

set the actuator state equal to the event state

We also have other helpers: a toggle_actuator action which will flip the state of the specified actuator and stop_actuator. These will be used later when we implement Impulses.  Actions can also send emails and/or text messages when they operate. Each type is associated with a template, which has placeholders for key details about the action.

There is one final step to complete before our action can switch the actuator relay. You may recall that our actuator was placed in Hand, so that we could remotely control it, but this will prevent the hub controller from controlling it, so you need to switch it to Auto. 

You should now notice three things:

1.  Your relay should switch on when the set threshold is reached, and off when the reset threshold is reached

2. In Statistics – events in the Event Queue are marked as Processed

3.  In Current Values – the Actuator State is displayed in its zone

What you can do now with your test setup, is connect a lamp to the actuator relay to use as a heating element, and attach it to the temperature sensor.  Change the condition to monitor the temperature sensor and set some suitable thresholds. You should see some more realistic activity in the Condition Graphs.

That completes the implementation of Rules and Actions. In the next post we will configure a time-based condition.