bootshorn log temperature

This commit is contained in:
CroneKorkN 2025-07-13 09:53:24 +02:00
parent 980fdc8203
commit 75017a99df
Signed by: cronekorkn
SSH key fingerprint: SHA256:v0410ZKfuO1QHdgKBsdQNF64xmTxOF8osF1LIqwTcVw
3 changed files with 54 additions and 9 deletions

View file

@ -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")

View file

@ -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',

View file

@ -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',
# },
# },
},
}