Compare commits

..

17 Commits

View File

@@ -6,6 +6,11 @@ blueprint:
min_version: "2024.6.0" min_version: "2024.6.0"
description: > description: >
Eine Automation zur automatischen Steuerung eines Bosch TRV Heizkörperthermostats. Eine Automation zur automatischen Steuerung eines Bosch TRV Heizkörperthermostats.
**Temperatur-Prioritätslogik:**
1. Alarm armed_away → Abwesenheitstemperatur
2. Aktiver Zeitplan → Temperatur aus Schedule
3. Fallback → Abwesenheitstemperatur
domain: automation domain: automation
author: Me author: Me
input: input:
@@ -27,7 +32,14 @@ blueprint:
device_class: temperature device_class: temperature
sensor_sync_threshold: sensor_sync_threshold:
name: Sensor-Synchronisations-Schwellenwert name: Sensor-Synchronisations-Schwellenwert
description: Minimale Temperaturdifferenz in °C, um eine Sensor-Synchronisation auszulösen (Default = 0.5°C). Temperatur wird weiterhin spätestens nach 25 Minuten synchronisiert. description: >
Minimale Temperaturdifferenz in °C, um eine Sensor-Synchronisation auszulösen (Default = 0.5°C).
**Synchronisation erfolgt bei:**
1. Differenz zwischen Sensor und TRV ≥ Schwellenwert
2. Sensor kreuzt Solltemperatur von unten (verhindert zu spätes Aufheizen)
3. Sensor kreuzt Solltemperatur von oben (verhindert Überhitzung)
4. Spätestens nach 25 Minuten ohne Änderung
default: 0.5 default: 0.5
selector: selector:
number: number:
@@ -46,7 +58,9 @@ blueprint:
- domain: input_boolean - domain: input_boolean
min_temperature: min_temperature:
name: Minimale Temperatur name: Minimale Temperatur
description: Minimale erlaubte Solltemperatur als Sicherheitsgrenze (Default = 15°C) description: >
Minimale erlaubte Solltemperatur als Sicherheitsgrenze (Default = 15°C).
Alle berechneten Temperaturen werden auf diesen Minimalwert begrenzt (Clamping).
default: 15 default: 15
selector: selector:
number: number:
@@ -57,7 +71,9 @@ blueprint:
step: 0.5 step: 0.5
max_temperature: max_temperature:
name: Maximale Temperatur name: Maximale Temperatur
description: Maximale erlaubte Solltemperatur als Sicherheitsgrenze (Default = 28°C) description: >
Maximale erlaubte Solltemperatur als Sicherheitsgrenze (Default = 23°C).
Alle berechneten Temperaturen werden auf diesen Maximalwert begrenzt (Clamping).
default: 23 default: 23
selector: selector:
number: number:
@@ -146,7 +162,12 @@ blueprint:
- domain: alarm_control_panel - domain: alarm_control_panel
away_temperature: away_temperature:
name: Abwesenheitstemperatur name: Abwesenheitstemperatur
description: Temperatur die eingestellt wird, wenn der Alarm im Abwesendmodus ist (Default = 18°C) description: >
Temperatur die verwendet wird, wenn der Alarm im Abwesendmodus ist oder kein Zeitplan aktiv ist (Default = 18°C).
**Verwendung:**
- Primär: Alarm Control Panel im Modus 'armed_away' (höchste Priorität)
- Fallback: Wenn kein aktiver Zeitplan eine Temperatur liefert
default: 18 default: 18
selector: selector:
number: number:
@@ -184,6 +205,7 @@ blueprint:
enable_day: false enable_day: false
variables: variables:
# Input-Variablen
trv: !input trv trv: !input trv
temperature_sensor: !input temperature_sensor temperature_sensor: !input temperature_sensor
sensor_sync_threshold: !input sensor_sync_threshold sensor_sync_threshold: !input sensor_sync_threshold
@@ -195,89 +217,112 @@ variables:
max_temperature: !input max_temperature max_temperature: !input max_temperature
alarm_control_panel: !input alarm_control_panel alarm_control_panel: !input alarm_control_panel
override_reset_duration: !input override_reset_duration override_reset_duration: !input override_reset_duration
is_heating_period: >
{{ heating_period_switch in [none, ''] or is_state(heating_period_switch, 'on') }} # Konstanten
temperature_change_tolerance: 0.4 # °C - Minimale Differenz für Temperaturänderung
sensor_sync_max_age: 1499 # Sekunden (25 Minuten - 1 Sekunde) - Max Alter für Sensor-Sync
random_delay_max_seconds: 30
# Zufalls-Delay für climate.set_temperature
random_delay_seconds: "{{ range(0, random_delay_max_seconds + 1) | random }}"
# Entity-Discovery
remote_temperature_entity: > remote_temperature_entity: >
{{ device_entities(device_id(trv)) | select('search', 'remote_temperature') | list | first | default('') }} {{ device_entities(device_id(trv)) | select('search', 'remote_temperature') | list | first | default('') }}
current_remote_temperature: >
{{ states(remote_temperature_entity) | float(0) if remote_temperature_entity and
states(remote_temperature_entity) not in ['unknown', 'unavailable', none] else 0 }}
remote_temperature_last_change: >
{{ states[remote_temperature_entity].last_changed if remote_temperature_entity and
states(remote_temperature_entity) not in ['unknown', 'unavailable', none] else none }}
window_detection_entity: > window_detection_entity: >
{{ device_entities(device_id(trv)) | select('search', 'window_detection') | list | first | default('') }} {{ device_entities(device_id(trv)) | select('search', 'window_detection') | list | first | default('') }}
setpoint_change_source_entity: > setpoint_change_source_entity: >
{{ device_entities(device_id(trv)) | select('search', 'setpoint_change_source') | list | first | default('') }} {{ device_entities(device_id(trv)) | select('search', 'setpoint_change_source') | list | first | default('') }}
# Entity-Validierung
remote_temperature_entity_valid: >
{{ remote_temperature_entity and states(remote_temperature_entity) not in ['unknown', 'unavailable', none] }}
window_detection_entity_valid: >
{{ window_detection_entity and window_detection_entity | length > 0 }}
setpoint_change_source_entity_valid: >
{{ setpoint_change_source_entity and states(setpoint_change_source_entity) not in ['unknown', 'unavailable', none] }}
# Basis-Berechnungen
is_heating_period: >
{{ heating_period_switch in [none, ''] or is_state(heating_period_switch, 'on') }}
current_remote_temperature: >
{{ states(remote_temperature_entity) | float(0) if remote_temperature_entity_valid else 0 }}
remote_temperature_last_change: >
{{ states[remote_temperature_entity].last_changed if remote_temperature_entity_valid else none }}
scheduled_temperature: > scheduled_temperature: >
{% set ns = namespace(current_temperature = none) %} {% set selected = states(active_scheduler_selector) %}
{% set selected_friendly_name = states(active_scheduler_selector) %} {% if selected not in [none, 'unknown', ''] %}
{% if selected_friendly_name is not none and selected_friendly_name != 'unknown' %} {% for schedule in radiator_schedules if state_attr(schedule, 'friendly_name') == selected and is_state(schedule, 'on') %}
{% for schedule in radiator_schedules %} {% set temp = state_attr(schedule, 'temp') %}
{% if state_attr(schedule, 'friendly_name') == selected_friendly_name and states(schedule) == 'on' %} {% if temp is not none and temp | is_number %}
{% set temp = state_attr(schedule, 'temp') %} {{ temp }}
{% if temp is not none and temp | is_number %} {% break %}
{% set ns.current_temperature = temp %}
{% break %}
{% endif %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% endif %} {% endif %}
{{ ns.current_temperature }}
# Temperatur-Berechnungen
# Priorität: 1. Alarm armed_away → away_temperature, 2. Aktiver Zeitplan → scheduled_temperature, 3. Fallback → away_temperature
target_temperature: > target_temperature: >
{{ scheduled_temperature if scheduled_temperature != none and not (alarm_control_panel and is_state(alarm_control_panel, 'armed_away')) else away_temperature }} {% if alarm_control_panel and is_state(alarm_control_panel, 'armed_away') %}
{{ away_temperature }}
{% elif scheduled_temperature != none %}
{{ scheduled_temperature }}
{% else %}
{{ away_temperature }}
{% endif %}
# Begrenzt target_temperature auf den Bereich [min_temperature, max_temperature] (Clamping)
safe_temperature: > safe_temperature: >
{{ [min_temperature, [max_temperature, target_temperature | float(18)] | min] | max }} {{ [min_temperature, [max_temperature, target_temperature | float(18)] | min] | max }}
# Status-Prüfungen
is_valid_temperature: > is_valid_temperature: >
{{ safe_temperature is not none and safe_temperature | is_number }} {{ safe_temperature is not none and safe_temperature | is_number }}
is_temperature_change_needed: > is_temperature_change_needed: >
{{ (safe_temperature | float(0) - state_attr(trv, 'temperature') | float(0)) | abs >= 0.4 }} {{ (safe_temperature | float(0) - state_attr(trv, 'temperature') | float(0)) | abs >= temperature_change_tolerance }}
# Synchronisation nötig wenn: 1) Differenz > Schwelle, 2) Sensor kreuzt Soll-Temp von unten, 3) Sensor kreuzt Soll-Temp von oben
is_sensor_sync_needed: > is_sensor_sync_needed: >
{% set new_sensor_temp = states(temperature_sensor) | float(0) %} {% set new_sensor_temp = states(temperature_sensor) | float(0) %}
{% set target_temp = state_attr(trv, 'temperature') | float(0) %} {% set target_temp = state_attr(trv, 'temperature') | float(0) %}
{% set diff = (new_sensor_temp - current_remote_temperature) | abs %} {% set diff = (new_sensor_temp - current_remote_temperature) | abs %}
{% if diff >= sensor_sync_threshold %} {{ diff >= sensor_sync_threshold or
true (new_sensor_temp < target_temp and current_remote_temperature >= target_temp) or
{% elif new_sensor_temp < target_temp and current_remote_temperature >= target_temp %} (new_sensor_temp > target_temp and current_remote_temperature <= target_temp) }}
true
{% elif new_sensor_temp > target_temp and current_remote_temperature <= target_temp %}
true
{% else %}
false
{% endif %}
scheduler_mismatch: > scheduler_mismatch: >
{% set selected = states(active_scheduler_selector) %} {% set selected = states(active_scheduler_selector) %}
{% if selected not in ['unknown', '', none] %} {% if selected not in ['unknown', '', none] %}
{% set found = namespace(value=false) %} {% set schedule_found = namespace(value=false) %}
{% for schedule in radiator_schedules %} {% for schedule in radiator_schedules %}
{% if state_attr(schedule, 'friendly_name') == selected %} {% if state_attr(schedule, 'friendly_name') == selected %}
{% set found.value = true %} {% set schedule_found.value = true %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{{ not found.value }} {{ not schedule_found.value }}
{% else %} {% else %}
false false
{% endif %} {% endif %}
is_manual_override: > is_manual_override: >
{{ (state_attr(trv, 'temperature') | float(0) - safe_temperature | float(0)) | abs >= 0.4 }} {{ (state_attr(trv, 'temperature') | float(0) - safe_temperature | float(0)) | abs >= temperature_change_tolerance }}
# Override Reset Berechnungen
# Konvertiert duration-Dictionary {hours, minutes, seconds} in Gesamtsekunden
override_reset_duration_seconds: > override_reset_duration_seconds: >
{{ (override_reset_duration.hours | default(0) | int) * 3600 + {{ (override_reset_duration.hours | default(0) | int) * 3600 +
(override_reset_duration.minutes | default(0) | int) * 60 + (override_reset_duration.minutes | default(0) | int) * 60 +
(override_reset_duration.seconds | default(0) | int) if override_reset_duration is mapping else 0 }} (override_reset_duration.seconds | default(0) | int) if override_reset_duration is mapping else 0 }}
override_last_change: > override_last_change: >
{{ states[setpoint_change_source_entity].last_updated if setpoint_change_source_entity and {{ states[setpoint_change_source_entity].last_updated if setpoint_change_source_entity_valid else none }}
states(setpoint_change_source_entity) not in ['unknown', 'unavailable', none] else none }} is_setpoint_manual: >
{{ setpoint_change_source_entity_valid and states(setpoint_change_source_entity) == 'manual' }}
# Early exits: 1) Keine Änderung/Timeout=0 → false, 2) Nicht manuell → false, 3) Berechne Zeitdifferenz
override_duration_exceeded: > override_duration_exceeded: >
{% if override_last_change != none and override_reset_duration_seconds > 0 and setpoint_change_source_entity and states(setpoint_change_source_entity) == 'manual' %} {% if override_last_change == none or override_reset_duration_seconds == 0 %}
{% set last_change = as_datetime(override_last_change) %}
{% if last_change != none %}
{% set elapsed = (now() - last_change).total_seconds() %}
{{ elapsed > override_reset_duration_seconds }}
{% else %}
false
{% endif %}
{% else %}
false false
{% elif not is_setpoint_manual %}
false
{% else %}
{% set last_change = as_datetime(override_last_change) %}
{{ last_change != none and (now() - last_change).total_seconds() > override_reset_duration_seconds }}
{% endif %} {% endif %}
triggers: triggers:
@@ -287,21 +332,21 @@ triggers:
from: "off" from: "off"
to: "on" to: "on"
for: !input window_delay_open for: !input window_delay_open
id: FENSTER_OPEN id: WINDOW_OPENED
- platform: state - platform: state
entity_id: entity_id:
- !input window_sensor - !input window_sensor
from: "on" from: "on"
to: "off" to: "off"
for: !input window_delay_close for: !input window_delay_close
id: FENSTER_CLOSED id: WINDOW_CLOSED
- platform: time_pattern - platform: time_pattern
# Periodische Überprüfung alle 5 Minuten (Temperatursynchronisation, Override-Check) # Periodische Überprüfung alle 5 Minuten (Temperatursynchronisation, Override-Check)
minutes: "/5" minutes: "/5"
id: PERIODIC_CHECK id: PERIODIC_CHECK
- platform: state - platform: state
entity_id: !input temperature_sensor entity_id: !input temperature_sensor
id: TEMP_CHANGED id: SENSOR_TEMPERATURE_CHANGED
- platform: state - platform: state
entity_id: !input alarm_control_panel entity_id: !input alarm_control_panel
to: "armed_away" to: "armed_away"
@@ -309,38 +354,43 @@ triggers:
- platform: state - platform: state
entity_id: !input alarm_control_panel entity_id: !input alarm_control_panel
from: "armed_away" from: "armed_away"
to: "disarmed" id: ALARM_DISARMED
id: ALARM_DISARMED_AWAY
- platform: state - platform: state
entity_id: !input heating_period_switch entity_id: !input heating_period_switch
to: "on" to: "on"
id: HEATING_PERIOD_ON id: HEATING_PERIOD_STARTED
- platform: state - platform: state
entity_id: !input heating_period_switch entity_id: !input heating_period_switch
to: "off" to: "off"
id: HEATING_PERIOD_OFF id: HEATING_PERIOD_ENDED
- platform: state - platform: state
entity_id: !input radiator_schedules entity_id: !input radiator_schedules
attribute: temp attribute: temp
id: SCHEDULE_TEMP_CHANGED id: SCHEDULE_TEMPERATURE_CHANGED
- platform: state - platform: state
entity_id: !input active_scheduler_selector entity_id: !input active_scheduler_selector
id: SCHEDULER_CHANGED id: SCHEDULE_SELECTOR_CHANGED
# Hinweis zur Wartbarkeit: climate.set_temperature wird an 4 Stellen verwendet:
# 1. Heizperiode aktiviert - Setzt Temperatur beim Einschalten der Heizung
# 2. Fenster geschlossen - Setzt Temperatur nach Fensterschließung
# 3. Override Reset - Setzt Temperatur zurück nach manuellem Override
# 4. Schedule/Alarm-Änderungen - Setzt Temperatur bei Zeitplan- oder Alarmänderungen
# Standardformat: service: climate.set_temperature | target: !input trv | data: safe_temperature
actions: actions:
- choose: - choose:
# Heizperiode Switch Aktionen # Heizperiode Switch Aktionen
- conditions: - conditions:
- condition: trigger - condition: trigger
id: id:
- HEATING_PERIOD_ON - HEATING_PERIOD_STARTED
- HEATING_PERIOD_OFF - HEATING_PERIOD_ENDED
sequence: sequence:
- choose: - choose:
- conditions: - conditions:
- condition: trigger - condition: trigger
id: id:
- HEATING_PERIOD_ON - HEATING_PERIOD_STARTED
sequence: sequence:
- service: climate.set_hvac_mode - service: climate.set_hvac_mode
target: target:
@@ -358,8 +408,10 @@ actions:
- if: - if:
- condition: template - condition: template
value_template: > value_template: >
{{ is_valid_temperature and is_temperature_change_needed }} {{ is_valid_temperature and is_temperature_change_needed and is_state(window_detection_entity, 'off') }}
then: then:
- delay:
seconds: "{{ random_delay_seconds }}"
- service: climate.set_temperature - service: climate.set_temperature
target: target:
entity_id: !input trv entity_id: !input trv
@@ -369,7 +421,7 @@ actions:
- conditions: - conditions:
- condition: trigger - condition: trigger
id: id:
- HEATING_PERIOD_OFF - HEATING_PERIOD_ENDED
sequence: sequence:
- service: switch.turn_off - service: switch.turn_off
target: target:
@@ -392,7 +444,7 @@ actions:
- conditions: - conditions:
- condition: trigger - condition: trigger
id: id:
- FENSTER_OPEN - WINDOW_OPENED
- condition: template - condition: template
value_template: > value_template: >
{{ is_state(window_detection_entity, 'off') }} {{ is_state(window_detection_entity, 'off') }}
@@ -404,7 +456,7 @@ actions:
- conditions: - conditions:
- condition: trigger - condition: trigger
id: id:
- FENSTER_CLOSED - WINDOW_CLOSED
- condition: template - condition: template
value_template: > value_template: >
{{ is_state(window_detection_entity, 'on') }} {{ is_state(window_detection_entity, 'on') }}
@@ -412,11 +464,15 @@ actions:
- service: switch.turn_off - service: switch.turn_off
target: target:
entity_id: "{{ window_detection_entity }}" entity_id: "{{ window_detection_entity }}"
- delay:
minutes: 1
- if: - if:
- condition: template - condition: template
value_template: > value_template: >
{{ is_valid_temperature and is_temperature_change_needed }} {{ is_valid_temperature and is_temperature_change_needed }}
then: then:
- delay:
seconds: "{{ random_delay_seconds }}"
- service: climate.set_temperature - service: climate.set_temperature
target: target:
entity_id: !input trv entity_id: !input trv
@@ -429,7 +485,7 @@ actions:
- conditions: - conditions:
- condition: trigger - condition: trigger
id: id:
- TEMP_CHANGED - SENSOR_TEMPERATURE_CHANGED
- condition: template - condition: template
value_template: > value_template: >
{{ temperature_sensor is defined and states(temperature_sensor) | is_number }} {{ temperature_sensor is defined and states(temperature_sensor) | is_number }}
@@ -453,7 +509,7 @@ actions:
value_template: > value_template: >
{% if remote_temperature_last_change != none %} {% if remote_temperature_last_change != none %}
{% set last_change = as_datetime(remote_temperature_last_change) %} {% set last_change = as_datetime(remote_temperature_last_change) %}
{{ last_change != none and (now() - last_change).total_seconds() > 1499 }} {{ last_change != none and (now() - last_change).total_seconds() > sensor_sync_max_age }}
{% else %} {% else %}
false false
{% endif %} {% endif %}
@@ -478,6 +534,8 @@ actions:
- condition: template - condition: template
value_template: "{{ override_duration_exceeded }}" value_template: "{{ override_duration_exceeded }}"
sequence: sequence:
- delay:
seconds: "{{ random_delay_seconds }}"
- service: climate.set_temperature - service: climate.set_temperature
target: target:
entity_id: !input trv entity_id: !input trv
@@ -491,12 +549,12 @@ actions:
- condition: trigger - condition: trigger
id: id:
- ALARM_ARMED_AWAY - ALARM_ARMED_AWAY
- ALARM_DISARMED_AWAY - ALARM_DISARMED
- SCHEDULE_TEMP_CHANGED - SCHEDULE_TEMPERATURE_CHANGED
- SCHEDULER_CHANGED - SCHEDULE_SELECTOR_CHANGED
- condition: template - condition: template
value_template: > value_template: >
{% if trigger.id == 'SCHEDULE_TEMP_CHANGED' %} {% if trigger.id == 'SCHEDULE_TEMPERATURE_CHANGED' %}
{% set selected_friendly_name = states(active_scheduler_selector) %} {% set selected_friendly_name = states(active_scheduler_selector) %}
{{ state_attr(trigger.entity_id, 'friendly_name') == selected_friendly_name }} {{ state_attr(trigger.entity_id, 'friendly_name') == selected_friendly_name }}
{% else %} {% else %}
@@ -506,8 +564,10 @@ actions:
- if: - if:
- condition: template - condition: template
value_template: > value_template: >
{{ is_valid_temperature and is_temperature_change_needed }} {{ is_valid_temperature and is_temperature_change_needed and is_state(window_detection_entity, 'off') }}
then: then:
- delay:
seconds: "{{ random_delay_seconds }}"
- service: climate.set_temperature - service: climate.set_temperature
target: target:
entity_id: !input trv entity_id: !input trv