{"id":457,"date":"2017-06-03T07:14:58","date_gmt":"2017-06-03T07:14:58","guid":{"rendered":"https:\/\/test.warrensoft.co.uk\/wp-test\/home-hub\/?p=457"},"modified":"2018-12-08T07:32:17","modified_gmt":"2018-12-08T07:32:17","slug":"rules-and-actions","status":"publish","type":"post","link":"https:\/\/test.warrensoft.co.uk\/wp-test\/2017\/06\/03\/rules-and-actions\/","title":{"rendered":"Rules and Actions"},"content":{"rendered":"<p>Your hub should be generating events in the queue, but they are not currently being processed. The <a href=\"http:\/\/www.warrensoft.co.uk\/home-hub\/code\/controller\/rules_engine.py\" target=\"_blank\" rel=\"noopener noreferrer\">Rules Engine<\/a> 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.<\/p>\n<p>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. \u00a0Rules are simply constructs that bind an Action to a Condition.<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-460\" src=\"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-content\/uploads\/2017\/06\/ExemplarCARStackDisabled-300x225.png\" alt=\"\" width=\"300\" height=\"225\" srcset=\"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-content\/uploads\/2017\/06\/ExemplarCARStackDisabled-300x225.png 300w, https:\/\/test.warrensoft.co.uk\/wp-test\/wp-content\/uploads\/2017\/06\/ExemplarCARStackDisabled.png 637w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>Actions use the familiar helper functions approach, but in this case they all reside in a single file <a href=\"http:\/\/www.warrensoft.co.uk\/home-hub\/code\/controller\/action_helpers.py\" target=\"_blank\" rel=\"noopener noreferrer\">action_helpers.py<\/a>\u00a0 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:<\/p>\n<blockquote>\n<p style=\"padding-left: 30px;\">set the actuator state equal to the event state<\/p>\n<\/blockquote>\n<p>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. \u00a0Actions can also send emails and\/or text messages when they operate. Each type is associated with a <a href=\"http:\/\/www.warrensoft.co.uk\/home-hub\/code\/controller\/templates\/\" target=\"_blank\" rel=\"noopener noreferrer\">template<\/a>, which has placeholders for key details about the action.<\/p>\n<p>There is one final step to complete before our action can switch the actuator relay. You may recall that our actuator was placed in <em>Hand<\/em>, so that we could remotely control it, but this will prevent the hub controller from controlling it, so you need to switch it to <em>Auto.\u00a0<\/em><\/p>\n<p>You should now notice three things:<\/p>\n<p style=\"padding-left: 30px;\">1. \u00a0Your relay should switch on when the set threshold is reached, and off when the reset threshold is reached<\/p>\n<p style=\"padding-left: 30px;\">2. In Statistics &#8211; events in the Event Queue are marked as Processed<\/p>\n<p style=\"padding-left: 30px;\">3. \u00a0In Current Values &#8211; the Actuator State is displayed in its zone<\/p>\n<p>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. \u00a0Change the condition to monitor the temperature sensor and set some suitable thresholds. You should see some more realistic activity in the Condition Graphs.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-482\" src=\"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-content\/uploads\/2017\/06\/ClosedLoopControl-300x204.png\" alt=\"\" width=\"300\" height=\"204\" srcset=\"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-content\/uploads\/2017\/06\/ClosedLoopControl-300x204.png 300w, https:\/\/test.warrensoft.co.uk\/wp-test\/wp-content\/uploads\/2017\/06\/ClosedLoopControl.png 534w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>That completes the implementation of Rules and Actions. In the next post we will configure a time-based condition.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/test.warrensoft.co.uk\/wp-test\/2017\/06\/03\/rules-and-actions\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Rules and Actions&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-457","post","type-post","status-publish","format-standard","hentry","category-hub-software"],"_links":{"self":[{"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/posts\/457","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/comments?post=457"}],"version-history":[{"count":11,"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/posts\/457\/revisions"}],"predecessor-version":[{"id":696,"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/posts\/457\/revisions\/696"}],"wp:attachment":[{"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/media?parent=457"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/categories?post=457"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/tags?post=457"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}