Created
February 18, 2021 03:17
-
-
Save dannyrandall/163261f017b4aa58ade0e700036e19d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ruleset wovyn_base { | |
meta { | |
name "Wovyn Base" | |
author "Daniel Randall" | |
use module twilio | |
with | |
accountSID = meta:rulesetConfig{"accountSID"} | |
authToken = meta:rulesetConfig{"authToken"} | |
configure using | |
} | |
global { | |
temperature_threshold = 100 | |
notification_from = meta:rulesetConfig{"notification_from"} | |
notification_to = meta:rulesetConfig{"notification_to"} | |
} | |
rule process_heartbeat { | |
select when wovyn heartbeat where event:attrs{"genericThing"} | |
send_directive("temperatureF", event:attrs{"genericThing"}{["data", "temperature", 0, "temperatureF"]}) | |
fired { | |
raise wovyn event "new_temperature_reading" attributes { | |
"timestamp": time:now(), | |
"temperature": event:attrs{"genericThing"}{["data", "temperature", 0, "temperatureF"]} | |
} | |
} | |
} | |
rule find_high_temps { | |
select when wovyn new_temperature_reading where event:attrs{"temperature"} > temperature_threshold | |
fired { | |
raise wovyn event "threshold_violation" attributes event:attrs | |
} | |
} | |
rule threshold_notification { | |
select when wovyn threshold_violation | |
twilio:sendSMS(notification_from, | |
notification_to, | |
"Detected threshold violation at " + event:attrs{"timestamp"} + ". Temperature: " + event:attrs{"temperature"}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment