Created
February 18, 2021 05:27
-
-
Save dannyrandall/4360fed94f43ba546839bc19caee2a0a 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 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