Skip to content

Instantly share code, notes, and snippets.

@dannyrandall
Created February 20, 2021 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dannyrandall/626047281922b248f5753a3c4d25bb03 to your computer and use it in GitHub Desktop.
Save dannyrandall/626047281922b248f5753a3c4d25bb03 to your computer and use it in GitHub Desktop.
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