Files
python_example/actions/read_counter.py
2026-02-12 11:01:52 -06:00

32 lines
702 B
Python

#!/usr/bin/env python3
"""
Read Counter Action - Python Example Pack
Consumes a counter value (typically from the counter sensor trigger payload)
and returns a formatted message containing the counter value.
Parameters are delivered via stdin as JSON.
"""
import json
import sys
def main():
# Read parameters from stdin (JSON format)
params = json.loads(sys.stdin.readline())
counter = params.get("counter", 0)
rule_ref = params.get("rule_ref", "unknown")
result = {
"message": f"Counter value is {counter} (from rule: {rule_ref})",
"counter": counter,
"rule_ref": rule_ref,
}
print(json.dumps(result))
if __name__ == "__main__":
main()