Created
February 20, 2021 21:51
-
-
Save dannyrandall/626047281922b248f5753a3c4d25bb03 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"} | |
use module sensor_profile alias profile | |
} | |
global { | |
notification_from = meta:rulesetConfig{"notification_from"} | |
} | |
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"} > profile:temperature_threshold() | |
fired { | |
raise wovyn event "threshold_violation" attributes event:attrs | |
} | |
} | |
rule threshold_notification { | |
select when wovyn threshold_violation | |
twilio:sendSMS(notification_from, | |
profile: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