Add dishwasher night scheduling automation

This commit is contained in:
2026-04-06 09:10:57 +02:00
parent 175bf99c7a
commit 3aa824e581
2 changed files with 116 additions and 0 deletions
+112
View File
@@ -0,0 +1,112 @@
- id: dishwasher_plan_cheapest_night_run
alias: Opvaskemaskine - plan billigste natkørsel
mode: single
trigger:
- platform: state
entity_id: sensor.energi_data_service
- platform: time
at: "13:10:00"
variables:
best_start_ts: >
{% set raw = (state_attr('sensor.energi_data_service', 'raw_today') or []) + (state_attr('sensor.energi_data_service', 'raw_tomorrow') or []) %}
{% set ns = namespace(prices=[], candidates=[]) %}
{% set fallback_ts = as_timestamp(today_at('23:50')) | int %}
{% for item in raw %}
{% set dt_source = item.start if item.start is defined else item.hour if item.hour is defined else item.time if item.time is defined else none %}
{% if dt_source %}
{% if item.price is defined %}
{% set price = item.price | float(999) %}
{% elif item.value is defined %}
{% set price = item.value | float(999) %}
{% else %}
{% set price = 999 %}
{% endif %}
{% set ns.prices = ns.prices + [{'ts': as_timestamp(as_datetime(dt_source)) | int, 'price': price}] %}
{% endif %}
{% endfor %}
{% set tomorrow_midnight = (as_timestamp(today_at('00:00')) | int) + 86400 %}
{% set candidate_starts = [
as_timestamp(today_at('21:00')) | int,
as_timestamp(today_at('22:00')) | int,
as_timestamp(today_at('23:00')) | int,
tomorrow_midnight,
tomorrow_midnight + 3600,
tomorrow_midnight + 7200
] %}
{% for base in candidate_starts %}
{% set total = namespace(value=0, missing=false) %}
{% for offset in range(4) %}
{% set target = base + (offset * 3600) %}
{% set match = ns.prices | selectattr('ts', 'eq', target) | list | first %}
{% if match %}
{% set total.value = total.value + (match.price | float(999)) %}
{% else %}
{% set total.missing = true %}
{% endif %}
{% endfor %}
{% if not total.missing %}
{% set ns.candidates = ns.candidates + [{'ts': base, 'total': total.value}] %}
{% endif %}
{% endfor %}
{% set sorted = ns.candidates | sort(attribute='total') %}
{{ (sorted | first).ts if (sorted | count) > 0 else fallback_ts }}
action:
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.dishwasher_next_start
data:
timestamp: "{{ best_start_ts | int }}"
- id: dishwasher_start_planned_night_run
alias: Opvaskemaskine - start planlagt natkørsel
mode: single
trigger:
- platform: time
at: input_datetime.dishwasher_next_start
condition:
- condition: template
value_template: "{{ is_state('sensor.dishwasher_status_2', 'Off') }}"
action:
- choose:
- conditions:
- condition: state
entity_id: binary_sensor.dishwasher_fjernbetjening
state: "on"
sequence:
- service: button.press
target:
entity_id: button.dishwasher_start
default:
- service: notify.mobile_app_clausiphone15
data:
title: "Opvaskemaskine venter på remote control"
message: "Planlagt natkørsel kunne ikke startes, fordi fjernbetjening ikke er slået til."
- id: dishwasher_remote_control_hourly_reminder
alias: Opvaskemaskine - påmindelse om remote control
mode: single
trigger:
- platform: time_pattern
minutes: "0"
condition:
- condition: template
value_template: "{{ now().hour >= 16 and now().hour <= 21 }}"
- condition: state
entity_id: binary_sensor.dishwasher_fjernbetjening
state: "off"
- condition: template
value_template: "{{ is_state('sensor.dishwasher_status_2', 'Off') }}"
action:
- service: notify.mobile_app_clausiphone15
data:
title: "Slå fjernbetjening til på opvaskemaskinen"
message: "Opvaskemaskinen er planlagt til natkørsel, men remote control er ikke slået til endnu."