diff --git a/dashboards/views/06_varme.yaml b/dashboards/views/06_varme.yaml index d61642c..e875433 100644 --- a/dashboards/views/06_varme.yaml +++ b/dashboards/views/06_varme.yaml @@ -389,6 +389,13 @@ sections: action: call-service service: script.varme_recalculate + - type: button + name: Gem temperaturer som standard + icon: mdi:content-save + tap_action: + action: perform-action + perform_action: script.varme_save_defaults + # Ventilposition - type: grid cards: diff --git a/include/scripts/varme_styring.yaml b/include/scripts/varme_styring.yaml index 4ad37cd..0023cfd 100644 --- a/include/scripts/varme_styring.yaml +++ b/include/scripts/varme_styring.yaml @@ -223,3 +223,18 @@ varme_recalculate: data: hvac_mode: heat temperature: "{{ ferie_temp }}" + + +varme_save_defaults: + alias: Gem varme-standardværdier + icon: mdi:content-save + sequence: + - action: shell_command.varme_save_defaults + response_variable: result + - action: persistent_notification.create + data: + title: Varme-standardværdier gemt + message: > + {{ result.stdout if result.returncode == 0 + else 'Fejl: ' ~ result.stderr }} + notification_id: varme_save_defaults diff --git a/include/shell_commands/varme.yaml b/include/shell_commands/varme.yaml new file mode 100644 index 0000000..e916b73 --- /dev/null +++ b/include/shell_commands/varme.yaml @@ -0,0 +1 @@ +varme_save_defaults: "/usr/local/bin/docker exec homeassistant python3 /config/python_scripts/save_varme_defaults.py" diff --git a/python_scripts/save_varme_defaults.py b/python_scripts/save_varme_defaults.py new file mode 100644 index 0000000..7176332 --- /dev/null +++ b/python_scripts/save_varme_defaults.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python3 +""" +Gem nuværende varme-indstillinger som nye 'initial' standardværdier i YAML-filen. +Køres inde i homeassistant Docker-containeren. +""" +import re +import json +import urllib.request + +YAML_FILE = "/config/include/input/number/varme.yaml" +SECRETS_FILE = "/config/secrets.yaml" +HA_URL = "http://localhost:8123" + +ENTITIES = [ + "varme_komfort_andreas", + "varme_komfort_daniel", + "varme_komfort_sovevaerelse", + "varme_komfort_kontor", + "varme_komfort_gang", + "varme_komfort_forgang", + "varme_komfort_lille_bad", + "varme_komfort_badevarelse", + "varme_komfort_stue", + "varme_nat_saenkning", + "varme_vaek_saenkning", + "varme_ferie_temp", +] + + +def get_token(): + with open(SECRETS_FILE) as f: + for line in f: + if line.startswith("ha_token:"): + return line.split(":", 1)[1].strip() + raise ValueError("ha_token ikke fundet i secrets.yaml") + + +def get_states(token): + req = urllib.request.Request( + f"{HA_URL}/api/states", + headers={"Authorization": f"Bearer {token}"}, + ) + with urllib.request.urlopen(req) as resp: + return {d["entity_id"]: d["state"] for d in json.loads(resp.read())} + + +def format_value(state_str): + val = float(state_str) + return str(int(val)) if val == int(val) else str(val) + + +def update_initial(content, entity_name, new_value): + """Erstat initial-værdien for en given entity i YAML-indholdet.""" + pattern = rf"(^{re.escape(entity_name)}:\n(?: [^\n]*\n)*? initial: )\S+" + new_content, count = re.subn( + pattern, rf"\g<1>{new_value}", content, flags=re.MULTILINE, count=1 + ) + if count == 0: + print(f" ADVARSEL: {entity_name} ikke fundet i YAML") + return new_content + + +def main(): + token = get_token() + states = get_states(token) + + with open(YAML_FILE) as f: + content = f.read() + + saved = [] + for name in ENTITIES: + entity_id = f"input_number.{name}" + state = states.get(entity_id) + if state in (None, "unavailable", "unknown"): + print(f" SPRING OVER {entity_id}: {state}") + continue + val_str = format_value(state) + content = update_initial(content, name, val_str) + saved.append(f"{entity_id} = {val_str}") + + with open(YAML_FILE, "w") as f: + f.write(content) + + print(f"Gemt {len(saved)} standardværdier -> {YAML_FILE}") + for line in saved: + print(f" {line}") + + +if __name__ == "__main__": + main() diff --git a/www/snapshots/indkorsel/2026-05-16_11-51-43.jpg b/www/snapshots/indkorsel/2026-05-16_11-51-43.jpg new file mode 100644 index 0000000..be0452a Binary files /dev/null and b/www/snapshots/indkorsel/2026-05-16_11-51-43.jpg differ diff --git a/www/snapshots/indkorsel/2026-05-16_11-57-27.jpg b/www/snapshots/indkorsel/2026-05-16_11-57-27.jpg new file mode 100644 index 0000000..64e1a7e Binary files /dev/null and b/www/snapshots/indkorsel/2026-05-16_11-57-27.jpg differ diff --git a/www/snapshots/indkorsel/2026-05-16_11-58-21.jpg b/www/snapshots/indkorsel/2026-05-16_11-58-21.jpg new file mode 100644 index 0000000..e6e3a97 Binary files /dev/null and b/www/snapshots/indkorsel/2026-05-16_11-58-21.jpg differ diff --git a/www/snapshots/indkorsel/latest.jpg b/www/snapshots/indkorsel/latest.jpg index bd890e6..002de15 100644 Binary files a/www/snapshots/indkorsel/latest.jpg and b/www/snapshots/indkorsel/latest.jpg differ