diff --git a/bundles/bootshorn/files/temperature b/bundles/bootshorn/files/temperature index 42707ca..9d73780 100755 --- a/bundles/bootshorn/files/temperature +++ b/bundles/bootshorn/files/temperature @@ -3,13 +3,15 @@ import requests import urllib3 import datetime -import json +import csv urllib3.disable_warnings() +import os + HUE_IP = "10.0.0.134" # replace with your bridge IP HUE_APP_KEY = "${hue_app_key}" # local only HUE_DEVICE_ID = "31f58786-3242-4e88-b9ce-23f44ba27bbe" -TEMPERATURE_LOGFILE = "/opt/bootshorn/temperature.log" +TEMPERATURE_LOG_DIR = "/opt/bootshorn/temperatures" response = requests.get( f"https://{HUE_IP}/clip/v2/resource/temperature", @@ -28,6 +30,9 @@ for item in data["data"]: print(f"@{temperature_date}: {temperature}°C") -with open(TEMPERATURE_LOGFILE, "a+") as logfile: - json.dump([temperature_date.isoformat(), temperature], logfile) - logfile.write("\n") \ No newline at end of file +filename = temperature_date.strftime("%Y-%m-%d_00-00-00.000000%z") + ".log" +logpath = os.path.join(TEMPERATURE_LOG_DIR, filename) + +with open(logpath, "a+", newline="") as logfile: + writer = csv.writer(logfile) + writer.writerow([temperature_date.strftime('%Y-%m-%d_%H-%M-%S.%f%z'), temperature]) \ No newline at end of file diff --git a/bundles/bootshorn/items.py b/bundles/bootshorn/items.py index f6f2d40..b4082eb 100644 --- a/bundles/bootshorn/items.py +++ b/bundles/bootshorn/items.py @@ -11,6 +11,10 @@ directories = { 'owner': 'ckn', 'group': 'ckn', }, + '/opt/bootshorn/temperatures': { + 'owner': 'ckn', + 'group': 'ckn', + }, '/opt/bootshorn/recordings/processed': { 'owner': 'ckn', 'group': 'ckn', diff --git a/bundles/bootshorn/metadata.py b/bundles/bootshorn/metadata.py index 89feb0c..1dd1eee 100644 --- a/bundles/bootshorn/metadata.py +++ b/bundles/bootshorn/metadata.py @@ -25,7 +25,7 @@ defaults = { 'systemd-timers': { 'bootshorn-temperature': { 'command': '/opt/bootshorn/temperature', - 'when': '*:0/15', + 'when': '*:0/5', 'working_dir': '/opt/bootshorn', 'user': 'ckn', 'group': 'ckn',