diff --git a/bundles/bootshorn/files/temperature b/bundles/bootshorn/files/temperature new file mode 100755 index 0000000..42707ca --- /dev/null +++ b/bundles/bootshorn/files/temperature @@ -0,0 +1,33 @@ +#!/usr/bin/env python3 + +import requests +import urllib3 +import datetime +import json +urllib3.disable_warnings() + +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" + +response = requests.get( + f"https://{HUE_IP}/clip/v2/resource/temperature", + headers={"hue-application-key": HUE_APP_KEY}, + verify=False, +) +response.raise_for_status() +data = response.json() + +for item in data["data"]: + if item["id"] == HUE_DEVICE_ID: + temperature = item["temperature"]["temperature"] + temperature_date_string = item["temperature"]["temperature_report"]["changed"] + temperature_date = datetime.datetime.fromisoformat(temperature_date_string).astimezone(datetime.timezone.utc) + break + +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 diff --git a/bundles/bootshorn/items.py b/bundles/bootshorn/items.py index 673b0ad..f6f2d40 100644 --- a/bundles/bootshorn/items.py +++ b/bundles/bootshorn/items.py @@ -11,10 +11,6 @@ directories = { 'owner': 'ckn', 'group': 'ckn', }, - '/opt/bootshorn/recordings': { - 'owner': 'ckn', - 'group': 'ckn', - }, '/opt/bootshorn/recordings/processed': { 'owner': 'ckn', 'group': 'ckn', @@ -31,6 +27,15 @@ files = { 'group': 'ckn', 'mode': '755', }, + '/opt/bootshorn/temperature': { + 'content_type': 'mako', + 'context': { + 'hue_app_key': repo.vault.decrypt('encrypt$gAAAAABoc2WxZCLbxl-Z4IrSC97CdOeFgBplr9Fp5ujpd0WCCCPNBUY_WquHN86z8hKLq5Y04dwq8TdJW0PMSOSgTFbGgdp_P1q0jOBLEKaW9IIT1YM88h-JYwLf9QGDV_5oEfvnBCtO'), + }, + 'owner': 'ckn', + 'group': 'ckn', + 'mode': '755', + }, '/opt/bootshorn/process': { 'owner': 'ckn', 'group': 'ckn', diff --git a/bundles/bootshorn/metadata.py b/bundles/bootshorn/metadata.py index 87db9ec..0685495 100644 --- a/bundles/bootshorn/metadata.py +++ b/bundles/bootshorn/metadata.py @@ -23,15 +23,22 @@ defaults = { }, }, 'systemd-timers': { - 'bootshorn-process': { - 'command': '/opt/bootshorn/process', + 'bootshorn-temperature': { + 'command': '/opt/bootshorn/temperature', 'when': 'minutely', 'working_dir': '/opt/bootshorn', 'user': 'ckn', 'group': 'ckn', - 'after': { - 'bootshorn-process.service', - }, }, + # 'bootshorn-process': { + # 'command': '/opt/bootshorn/process', + # 'when': 'hourly', + # 'working_dir': '/opt/bootshorn', + # 'user': 'ckn', + # 'group': 'ckn', + # 'after': { + # 'bootshorn-process.service', + # }, + # }, }, }