====== Automationen – Code: Sicherheit ======
[[ha:raderbroich:installation:automationen|← zurück zur Automationen-Übersicht]]
Stand: **25.09.2026**. YAML wie in HA unter ⋮ → „In YAML bearbeiten“.
===== Sicherheit: Alarm automatisch bei Abwesenheit =====
id: "1790256086196"
alias: "Sicherheit: Alarm automatisch bei Abwesenheit"
description: >-
Verlässt der Letzte (Norbert oder Ute) die Zone Home (Raderbroich) für mindestens 2 Minuten,
wird die Alarmanlage scharf geschaltet. Kommt einer zurück, wird sie wieder unscharf geschaltet –
aber nur, wenn sie scharf bzw. ausgelöst ist (ein manuell gesetzter Hüllenschutz bleibt unberührt).
Geschaltet wird über script.alarm_schalten_scharf_hulle_unscharf, damit Dashboard,
Fehlermeldungen und Telegram wie gewohnt funktionieren.
triggers:
- trigger: state
entity_id:
- person.norbert
- person.ute
from: home
not_to:
- unavailable
- unknown
for: "00:02:00"
id: verlassen
- trigger: state
entity_id:
- person.norbert
- person.ute
to: home
not_from:
- unavailable
- unknown
id: zurueck
conditions: []
actions:
- choose:
- alias: Letzter ist weg -> Scharf
conditions:
- condition: trigger
id: verlassen
- condition: not
conditions:
- condition: state
entity_id: person.norbert
state: home
- condition: not
conditions:
- condition: state
entity_id: person.ute
state: home
- condition: state
entity_id: alarm_control_panel.hmip_raderbroich_hmip_alarm_control_panel
state:
- disarmed
- armed_home
- armed_night
sequence:
- action: script.telegram_universal_versand
continue_on_error: true
data:
message: "🚗 *Raderbroich*: Niemand mehr zu Hause – Alarmanlage wird automatisch *scharf* geschaltet."
- action: script.alarm_schalten_scharf_hulle_unscharf
data:
ziel: Scharf
- alias: Einer ist zurück -> Unscharf
conditions:
- condition: trigger
id: zurueck
- condition: state
entity_id: alarm_control_panel.hmip_raderbroich_hmip_alarm_control_panel
state:
- armed_away
- triggered
- arming
- pending
sequence:
- action: script.telegram_universal_versand
continue_on_error: true
data:
message: "🏠 *Raderbroich*: {{ trigger.to_state.name }} ist zurück – Alarmanlage wird automatisch *unscharf* geschaltet."
- action: script.alarm_schalten_scharf_hulle_unscharf
data:
ziel: Unscharf
mode: queued
max: 5
===== Sicherheit: Alarm per Telegram-Button bestätigen =====
id: "1790236193432"
alias: "Sicherheit: Alarm per Telegram-Button bestätigen"
description: Reagiert auf den Button '✅ Alarm bestätigen' in Telegram und stoppt die Videoschleife.
triggers:
- trigger: event
event_type: telegram_callback
event_data:
data: /alarm_ack
conditions: []
actions:
- action: input_boolean.turn_on
target:
entity_id: input_boolean.alarm_video_bestatigt
- action: telegram_bot.answer_callback_query
continue_on_error: true
data:
callback_query_id: "{{ trigger.event.data.id }}"
message: Alarm bestätigt – Videos gestoppt
show_alert: false
mode: queued
===== Sicherheit: Alarm-Videoschleife per Telegram =====
id: "1790236192749"
alias: "Sicherheit: Alarm-Videoschleife per Telegram"
description: >-
Bei ausgelöstem Alarm alle X s ein X-s-Video aufnehmen (X = input_number.alarm_videolange)
und per Telegram senden, bis per Telegram-Button bestätigt oder unscharf geschaltet wird.
Sicherheitslimit: input_number.alarm_video_gesamtdauer (Minuten);
Anzahl = Gesamtdauer*60 / X, aufgerundet.
triggers:
- trigger: state
entity_id: alarm_control_panel.hmip_raderbroich_hmip_alarm_control_panel
to: triggered
conditions: []
actions:
- variables:
laenge: "{{ states('input_number.alarm_videolange') | int(10) }}"
max_videos: "{{ (((states('input_number.alarm_video_gesamtdauer') | int(10)) * 60 / (states('input_number.alarm_videolange') | int(10))) | round(0, 'ceil')) | int }}"
gesamt_min: "{{ states('input_number.alarm_video_gesamtdauer') | int(10) }}"
- action: input_boolean.turn_off
target:
entity_id: input_boolean.alarm_video_bestatigt
- repeat:
sequence:
- variables:
datei: "/media/alarm_videos/alarm_{{ now().strftime('%Y%m%d_%H%M%S') }}.mp4"
- action: camera.record
continue_on_error: true
target:
entity_id: camera.ko_wohnzimmer_standardauflosung
data:
duration: "{{ laenge }}"
filename: "{{ datei }}"
- action: script.turn_on
target:
entity_id: script.alarm_video_senden
data:
variables:
datei: "{{ datei }}"
laenge: "{{ laenge }}"
nummer: "{{ repeat.index }}"
- wait_for_trigger:
- trigger: state
entity_id: input_boolean.alarm_video_bestatigt
to: "on"
- trigger: state
entity_id: alarm_control_panel.hmip_raderbroich_hmip_alarm_control_panel
from: triggered
timeout:
seconds: "{{ laenge }}"
continue_on_timeout: true
until:
- condition: or
conditions:
- condition: state
entity_id: input_boolean.alarm_video_bestatigt
state: "on"
- condition: not
conditions:
- condition: state
entity_id: alarm_control_panel.hmip_raderbroich_hmip_alarm_control_panel
state: triggered
- condition: template
value_template: "{{ repeat.index >= max_videos }}"
- action: telegram_bot.send_message
continue_on_error: true
data:
entity_id: notify.norbert_bruchmann
message: >-
📹 Alarm-Videoschleife beendet ({% if is_state('input_boolean.alarm_video_bestatigt','on') %}bestätigt{% elif not is_state('alarm_control_panel.hmip_raderbroich_hmip_alarm_control_panel','triggered') %}Alarmanlage nicht mehr ausgelöst{% else %}Gesamtdauer von {{ gesamt_min }} min erreicht – {{ max_videos }} Videos à {{ laenge }} s{% endif %}).
- action: telegram_bot.send_message
continue_on_error: true
data:
entity_id: notify.ute_heister
message: >-
📹 Alarm-Videoschleife beendet ({% if is_state('input_boolean.alarm_video_bestatigt','on') %}bestätigt{% elif not is_state('alarm_control_panel.hmip_raderbroich_hmip_alarm_control_panel','triggered') %}Alarmanlage nicht mehr ausgelöst{% else %}Gesamtdauer von {{ gesamt_min }} min erreicht – {{ max_videos }} Videos à {{ laenge }} s{% endif %}).
mode: single
===== Sicherheit: Alarmstatus via Telegram und iOS senden =====
id: "1790148278373"
alias: "Sicherheit: Alarmstatus via Telegram und iOS senden"
description: |
Ruft das Telegram-Skript auf und sendet bei wichtigen Ereignissen Push-Nachrichten an das iPhone.
triggers:
- trigger: state
entity_id: input_select.alarmstatus
id: trigger_status
- trigger: state
entity_id: input_text.alarm_letzter_fehler
id: trigger_fehler
- trigger: state
entity_id: alarm_control_panel.hmip_raderbroich_hmip_alarm_control_panel
to: triggered
id: trigger_alarm_ausgelöst
conditions: []
actions:
- choose:
- conditions:
- condition: trigger
id: trigger_alarm_ausgelöst
sequence:
- action: script.telegram_universal_versand
data:
message: |-
🚨 *ALARM AUSGELÖST!* 🚨
Die Alarmanlage hat einen Einbruch oder Alarm detektiert!
parse_mode: markdown
- action: notify.mobile_app_iphone_von_norbert
data:
title: 🚨 ALARM AUSGELÖST!
message: Die Alarmanlage hat einen Alarm detektiert!
data:
push:
sound:
name: default
critical: 1
volume: 1
- action: notify.mobile_app_iphone_13_ute
data:
title: 🚨 ALARM AUSGELÖST!
message: Die Alarmanlage hat einen Alarm detektiert!
data:
push:
sound:
name: default
critical: 1
volume: 1
- conditions:
- condition: trigger
id: trigger_status
- condition: state
entity_id: input_boolean.system_startphase
state: "off"
sequence:
- action: script.telegram_universal_versand
data:
message: |-
🔒 *Alarmanlage Status*
Der Status hat sich geändert auf: *{{ trigger.to_state.state }}*.
parse_mode: markdown
- conditions:
- condition: trigger
id: trigger_fehler
- condition: state
entity_id: input_boolean.system_startphase
state: "off"
- condition: not
conditions:
- condition: state
entity_id: input_text.alarm_letzter_fehler
state:
- ""
- " "
- unknown
- unavailable
sequence:
- action: script.telegram_universal_versand
data:
message: |-
⚠️ *Alarm-Fehler*
{{ trigger.to_state.state }}
- action: script.test_push_nachricht_an_alle_handys
data:
title: ⚠️ Alarm-Fehler
message: "{{ trigger.to_state.state }}"
sound: default
critical: 1
mode: single
===== Sicherheit: Alarmstatus Watchdog =====
id: "1790150599952"
alias: "Sicherheit: Alarmstatus Watchdog"
description: >-
Prüft alle 5 Minuten, ob Dashboard und Homematic übereinstimmen, und korrigiert bei Abweichung.
Greift nicht ein, während ein Schaltvorgang läuft.
triggers:
- trigger: time_pattern
minutes: /5
conditions: []
actions:
- variables:
hmip_state: "{{ states('alarm_control_panel.hmip_raderbroich_hmip_alarm_control_panel') }}"
korrekt_text: |-
{% set state_map = {
'armed_away': 'Scharf',
'armed': 'Scharf',
'armed_home': 'Hüllenschutz',
'armed_night': 'Hüllenschutz',
'disarmed': 'Unscharf',
'triggered': 'Ausgelöst'
} %} {{ state_map.get(hmip_state, none) }}
- if:
- condition: template
value_template: >-
{{ korrekt_text is not none and korrekt_text != states('input_select.alarmstatus')
and is_state('input_boolean.alarm_vorgang_laeuft', 'off') }}
then:
- action: input_select.select_option
target:
entity_id: input_select.alarmstatus
data:
option: "{{ korrekt_text }}"
mode: single
===== Sicherheit: Alarmstatus von Homematic übernehmen =====
id: "1790141662417"
alias: "Sicherheit: Alarmstatus von Homematic übernehmen"
description: >-
Übernimmt externe Änderungen von Homematic (App, Keypad, Wandtaster) in input_select.alarmstatus.
Der umgekehrte Weg (Dashboard -> Homematic) läuft über script.alarm_schalten,
nicht mehr über diese Automation.
triggers:
- trigger: state
entity_id: alarm_control_panel.hmip_raderbroich_hmip_alarm_control_panel
conditions:
- condition: template
value_template: "{{ trigger.to_state.state not in ['pending', 'arming', 'disarming'] }}"
actions:
- variables:
new_state_text: |-
{% set current = trigger.to_state.state %} {% set state_map = {
'armed_away': 'Scharf',
'armed': 'Scharf',
'armed_home': 'Hüllenschutz',
'armed_night': 'Hüllenschutz',
'disarmed': 'Unscharf',
'triggered': 'Ausgelöst'
} %} {{ state_map.get(current, states('input_select.alarmstatus')) }}
- action: input_select.select_option
target:
entity_id: input_select.alarmstatus
data:
option: "{{ new_state_text }}"
mode: queued
max: 10
===== Sicherheit: Telegram-Benachrichtigung bei Alarmstatus (deaktiviert) =====
id: "1790145871219"
alias: "Sicherheit: Telegram-Benachrichtigung bei Alarmstatus"
description: Sendet Statusänderungen der Alarmanlage über den Telegram-Bot an die feste ID.
triggers:
- trigger: state
entity_id: input_select.alarmstatus
conditions:
- condition: state
entity_id: input_boolean.alarm_vorgang_laeuft
state: "off"
- condition: template
value_template: "{{ trigger.to_state.state != 'Schalten' and trigger.from_state.state != trigger.to_state.state }}"
- condition: state
entity_id: input_boolean.system_startphase
state: "off"
actions:
- variables:
aktueller_status: "{{ trigger.to_state.state }}"
- action: telegram_bot.send_message
data:
message: "🔒 *Alarmanlage Status* Der Status hat sich geändert auf: *{{ aktueller_status }}*."
parse_mode: markdown
chat_id:
- 851603710
- 965268974
mode: single
===== Sicherheit: Kamera-Steckdose nach Alarmstatus =====
id: "1790242204185"
alias: "Sicherheit: Kamera-Steckdose nach Alarmstatus"
description: >-
Dose tv (Kamera ko-Wohnzimmer) ist nur an, wenn der Alarm Scharf oder Ausgelöst ist –
oder der Testmodus aktiv ist. Bei Unscharf/Hüllenschutz aus. Prüft zusätzlich alle 5 Minuten
und nach HA-Start. Übergangszustände (Schalten, arming, pending) werden abgewartet.
triggers:
- trigger: state
entity_id: input_select.alarmstatus
- trigger: state
entity_id: alarm_control_panel.hmip_raderbroich_hmip_alarm_control_panel
- trigger: state
entity_id: input_boolean.kamera_dose_testmodus
- trigger: state
entity_id: switch.hmip_raderbroich_dose_tv
for:
seconds: 5
- trigger: time_pattern
minutes: /5
- trigger: homeassistant
event: start
actions:
- choose:
- alias: "Soll AN: Testmodus oder Scharf/Ausgelöst"
conditions:
- condition: or
conditions:
- condition: state
entity_id: input_boolean.kamera_dose_testmodus
state: "on"
- condition: state
entity_id: alarm_control_panel.hmip_raderbroich_hmip_alarm_control_panel
state:
- armed_away
- triggered
- condition: state
entity_id: input_select.alarmstatus
state:
- Scharf
- Ausgelöst
- condition: state
entity_id: switch.hmip_raderbroich_dose_tv
state: "off"
sequence:
- action: switch.turn_on
continue_on_error: true
target:
entity_id: switch.hmip_raderbroich_dose_tv
- alias: "Soll AUS: Unscharf/Hüllenschutz und kein Test"
conditions:
- condition: state
entity_id: input_boolean.kamera_dose_testmodus
state: "off"
- condition: state
entity_id: alarm_control_panel.hmip_raderbroich_hmip_alarm_control_panel
state:
- disarmed
- armed_home
- armed_night
- condition: state
entity_id: input_select.alarmstatus
state:
- Unscharf
- Hüllenschutz
- condition: state
entity_id: switch.hmip_raderbroich_dose_tv
state: "on"
sequence:
- action: switch.turn_off
continue_on_error: true
target:
entity_id: switch.hmip_raderbroich_dose_tv
mode: queued
max: 5
===== Sicherheit: Nacht-Hüllenschutz nach Bewegungsruhe =====
id: "1790237427474"
alias: "Sicherheit: Nacht-Hüllenschutz nach Bewegungsruhe"
description: >-
22:30–06:30: Ist die Alarmanlage unscharf und 5 Minuten keine Bewegung (Melder oben + unten),
wird Hüllenschutz geschaltet. Bei der nächsten Bewegung wird ein so automatisch gesetzter
Hüllenschutz wieder aufgehoben. Manuell gesetzter Hüllenschutz bleibt unberührt.
triggers:
- trigger: state
entity_id:
- binary_sensor.hmip_raderbroich_bewegungsmelder_oben_bewegung
- binary_sensor.hmip_raderbroich_bewegungsmelder_unten_bewegung
to: "off"
for: "00:05:00"
id: ruhe
- trigger: time
at: "22:30:00"
id: ruhe
- trigger: state
entity_id:
- binary_sensor.hmip_raderbroich_bewegungsmelder_oben_bewegung
- binary_sensor.hmip_raderbroich_bewegungsmelder_unten_bewegung
from: "off"
to: "on"
id: bewegung
- trigger: state
entity_id: alarm_control_panel.hmip_raderbroich_hmip_alarm_control_panel
not_to:
- armed_home
- armed_night
- arming
- pending
- unavailable
- unknown
id: status_geaendert
actions:
- choose:
- alias: 5 Min. Ruhe in der Nacht -> Hüllenschutz
conditions:
- condition: trigger
id: ruhe
- condition: time
after: "22:30:00"
before: "06:30:00"
- condition: state
entity_id: alarm_control_panel.hmip_raderbroich_hmip_alarm_control_panel
state: disarmed
- condition: state
entity_id: input_boolean.alarm_vorgang_laeuft
state: "off"
- condition: state
entity_id:
- binary_sensor.hmip_raderbroich_bewegungsmelder_oben_bewegung
- binary_sensor.hmip_raderbroich_bewegungsmelder_unten_bewegung
state: "off"
for: "00:05:00"
sequence:
- action: script.alarm_schalten_scharf_hulle_unscharf
data:
ziel: Hüllenschutz
- if:
- condition: state
entity_id: alarm_control_panel.hmip_raderbroich_hmip_alarm_control_panel
state:
- armed_home
- armed_night
then:
- action: input_boolean.turn_on
target:
entity_id: input_boolean.hullenschutz_nacht_automatik_aktiv
- alias: Bewegung -> automatisch gesetzten Hüllenschutz aufheben
conditions:
- condition: trigger
id: bewegung
- condition: state
entity_id: input_boolean.hullenschutz_nacht_automatik_aktiv
state: "on"
- condition: state
entity_id: alarm_control_panel.hmip_raderbroich_hmip_alarm_control_panel
state:
- armed_home
- armed_night
sequence:
- action: script.alarm_schalten_scharf_hulle_unscharf
data:
ziel: Unscharf
- action: input_boolean.turn_off
target:
entity_id: input_boolean.hullenschutz_nacht_automatik_aktiv
- alias: Status anderweitig geändert -> Merker zurücksetzen
conditions:
- condition: trigger
id: status_geaendert
- condition: state
entity_id: input_boolean.hullenschutz_nacht_automatik_aktiv
state: "on"
sequence:
- action: input_boolean.turn_off
target:
entity_id: input_boolean.hullenschutz_nacht_automatik_aktiv
mode: queued
===== Sicherheit: Vorgang-Flag Timeout-Reset =====
id: "1790151900000"
alias: "Sicherheit: Vorgang-Flag Timeout-Reset"
description: >-
Setzt input_boolean.alarm_vorgang_laeuft zwangsweise zurück, falls es länger als 2 Minuten
auf "an" steht (z.B. durch einen abgebrochenen Skript-Lauf). Verhindert dauerhaft blockierte
Benachrichtigungen.
triggers:
- trigger: state
entity_id: input_boolean.alarm_vorgang_laeuft
to: "on"
for: "00:02:00"
conditions: []
actions:
- action: input_boolean.turn_off
target:
entity_id: input_boolean.alarm_vorgang_laeuft
mode: single