From cf803404c6bc5cf71bfda119c361104bb550736f Mon Sep 17 00:00:00 2001 From: yohan <783b8c87@scimetis.net> Date: Mon, 5 Feb 2024 00:43:58 +0100 Subject: [PATCH] Add new script. --- read_one-wire_sensor.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100755 read_one-wire_sensor.py diff --git a/read_one-wire_sensor.py b/read_one-wire_sensor.py new file mode 100755 index 0000000..6023747 --- /dev/null +++ b/read_one-wire_sensor.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import argparse +import json +import subprocess +import sys + +parser = argparse.ArgumentParser(description='Read one-wire sensor.') +parser.add_argument('metric', type=str, + help='Metric name.') +parser.add_argument('path', type=str, + help='owfs sensor path.') + +args = parser.parse_args() + +try: + returned_output = subprocess.check_output(["/usr/bin/owread", "-s", "localhost:4304", args.path]) + try: + value = round(float(returned_output.decode("utf-8").strip().strip("'")), 1) + except ValueError: + print (now()+" "+room+": Expected temperature, got garbage: "+returned_output) + sys.exit(1) +except Exception as e: + print(e) + sys.exit(1) + +data = {} +data[args.metric] = value +print(json.dumps(data))