Skip to content

Instantly share code, notes, and snippets.

@dannyrandall
Created February 18, 2021 05:27
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/4360fed94f43ba546839bc19caee2a0a to your computer and use it in GitHub Desktop.
Save dannyrandall/4360fed94f43ba546839bc19caee2a0a to your computer and use it in GitHub Desktop.
ruleset temperature_store {
meta {
name "Temperature Store"
author "Daniel Randall"
provides temperatures, threshold_violations, inrange_temperatures
shares temperatures, threshold_violations, inrange_temperatures
}
global {
temperatures = function() {
ent:temperatures
}
threshold_violations = function() {
ent:threshold_violations
}
inrange_temperatures = function() {
ent:temperatures.difference(ent:threshold_violations)
}
}
rule collect_temperatures {
select when wovyn new_temperature_reading
always {
ent:temperatures := ent:temperatures.defaultsTo([]).append(event:attrs)
}
}
rule collect_threshold_violations {
select when wovyn threshold_violation
always {
ent:threshold_violations := ent:threshold_violations.defaultsTo([]).append(event:attrs)
}
}
rule clear_temperatures {
select when sensor reading_reset
always {
clear ent:temperatures
clear ent:threshold_violations
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment