From 0b4fc7f2f481114227140c8af861a9b1c8f2bf2f Mon Sep 17 00:00:00 2001 From: Claus Dethlefsen Date: Wed, 25 Mar 2026 21:06:57 +0100 Subject: [PATCH] fix presence --- include/automations/presence_simulation.yaml | 131 ++++++++++++------- include/automations/vacation_end.yaml | 10 +- include/automations/vacation_recovery.yaml | 12 +- include/sensors/time_date.yaml | 25 ++++ 4 files changed, 124 insertions(+), 54 deletions(-) create mode 100644 include/sensors/time_date.yaml diff --git a/include/automations/presence_simulation.yaml b/include/automations/presence_simulation.yaml index 738012e..2f7c461 100644 --- a/include/automations/presence_simulation.yaml +++ b/include/automations/presence_simulation.yaml @@ -1,44 +1,60 @@ -alias: Presence Simulation - Tidsblokke med rum -description: Simulerer tilstedeværelse i forskellige rum med musik +alias: Presence Simulation - Tidsblokke (robust) +mode: restart + trigger: - platform: time - at: "07:00:00" # Morgen + at: "07:00:00" - platform: time - at: "12:00:00" # Middag + at: "12:00:00" - platform: time - at: "18:00:00" # Aften + at: "18:00:00" + condition: - condition: state entity_id: input_boolean.presence_simulation state: "on" - - condition: time - after: "07:00:00" - before: "22:30:00" + action: + - variables: + rand_delay: "{{ range(300,1200) | random }}" # 5-20 min + rand_music: "{{ range(0,100) | random }}" + - choose: + + # 🌅 Morgen - conditions: - condition: time - after: "07:00:00" + after: "06:59:00" before: "12:00:00" sequence: - # Morgen: Bad + forgang - - service: homeassistant.turn_on + + - service: light.turn_on target: entity_id: - - binary_sensor.bad_motion_sensor_motion - - binary_sensor.forgang_sensor_motion + - light.livingroom + - light.indkoersel_2 + - light.andreas_vaerelse + - light.bedroom + - light.daniels_vaerelse + - light.forgang + - delay: - seconds: "{{ range(5,20)|random }}" - - service: homeassistant.turn_off + seconds: "{{ rand_delay }}" + + - service: light.turn_off target: entity_id: - - binary_sensor.bad_motion_sensor_motion - - binary_sensor.forgang_sensor_motion - # Musik chance + - light.livingroom + - light.indkoersel_2 + - light.andreas_vaerelse + - light.bedroom + - light.daniels_vaerelse + - light.forgang + - choose: - conditions: - condition: template - value_template: "{{ range(0,10)|random < 2 }}" # 20% chance + value_template: "{{ rand_music < 20 }}" sequence: - service: media_player.play_media target: @@ -46,35 +62,44 @@ action: data: media_content_type: music media_content_id: "spotify:playlist:37i9dQZF1EVHGWrwldPRtj" + - delay: - minutes: "{{ range(5,15)|random }}" + seconds: "{{ range(300,900) | random }}" + - service: media_player.media_stop target: entity_id: media_player.kokken + # 🌤️ Middag - conditions: - condition: time - after: "12:00:00" + after: "11:59:00" before: "18:00:00" sequence: - # Middag: Køkken + indkørsel - - service: homeassistant.turn_on + + - service: light.turn_on target: entity_id: - - binary_sensor.indkorsel_sensor_motion - - binary_sensor.hue_motion_sensor_2_motion + - light.kokken + - light.indkoersel + - delay: - seconds: "{{ range(5,20)|random }}" - - service: homeassistant.turn_off + seconds: "{{ rand_delay }}" + + - service: light.turn_off target: entity_id: - - binary_sensor.indkorsel_sensor_motion - - binary_sensor.hue_motion_sensor_2_motion - # Musik chance + - light.livingroom + - light.indkoersel_2 + - light.andreas_vaerelse + - light.bedroom + - light.daniels_vaerelse + - light.forgang + - choose: - conditions: - condition: template - value_template: "{{ range(0,10)|random < 3 }}" # 30% chance + value_template: "{{ rand_music < 30 }}" sequence: - service: media_player.play_media target: @@ -82,37 +107,49 @@ action: data: media_content_type: music media_content_id: "spotify:playlist:37i9dQZF1EVHGWrwldPRtj" + - delay: - minutes: "{{ range(5,15)|random }}" + seconds: "{{ range(300,900) | random }}" + - service: media_player.media_stop target: entity_id: media_player.kokken + # 🌙 Aften - conditions: - condition: time - after: "18:00:00" + after: "17:59:00" before: "22:30:00" sequence: - # Aften: Stue + hue sensors - - service: homeassistant.turn_on + + - service: light.turn_on target: entity_id: - - binary_sensor.stue_motion_bevaegelse - - binary_sensor.hue_motion_sensor_2_motion_2 - - binary_sensor.hue_motion_sensor_1_motion_2 + - light.livingroom + - light.indkoersel_2 + - light.andreas_vaerelse + - light.bedroom + - light.daniels_vaerelse + - light.forgang + + - delay: - seconds: "{{ range(5,20)|random }}" - - service: homeassistant.turn_off + seconds: "{{ rand_delay }}" + + - service: light.turn_off target: entity_id: - - binary_sensor.stue_motion_bevaegelse - - binary_sensor.hue_motion_sensor_2_motion_2 - - binary_sensor.hue_motion_sensor_1_motion_2 - # Musik chance + - light.livingroom + - light.indkoersel_2 + - light.andreas_vaerelse + - light.bedroom + - light.daniels_vaerelse + - light.forgang + - choose: - conditions: - condition: template - value_template: "{{ range(0,10)|random < 5 }}" # 50% chance + value_template: "{{ rand_music < 50 }}" sequence: - service: media_player.play_media target: @@ -120,8 +157,10 @@ action: data: media_content_type: music media_content_id: "spotify:playlist:37i9dQZF1EVHGWrwldPRtj" + - delay: - minutes: "{{ range(5,15)|random }}" + seconds: "{{ range(300,1200) | random }}" + - service: media_player.media_stop target: entity_id: media_player.kokken diff --git a/include/automations/vacation_end.yaml b/include/automations/vacation_end.yaml index 69b6905..372a5eb 100644 --- a/include/automations/vacation_end.yaml +++ b/include/automations/vacation_end.yaml @@ -1,13 +1,19 @@ alias: Vacation Mode - Stop ved slutdato trigger: - - platform: time - at: input_datetime.vacation_end + - platform: time_pattern + minutes: "/1" condition: - condition: state entity_id: input_boolean.vacation_mode state: "on" + - condition: template + value_template: > + {% set dt = states('input_datetime.vacation_end') %} + {{ dt not in ['unknown','unavailable',''] and + now() >= as_datetime(dt) }} + action: - service: input_boolean.turn_off target: diff --git a/include/automations/vacation_recovery.yaml b/include/automations/vacation_recovery.yaml index 6ab2a39..37f3a9b 100644 --- a/include/automations/vacation_recovery.yaml +++ b/include/automations/vacation_recovery.yaml @@ -1,4 +1,5 @@ alias: Vacation Mode - Recovery efter restart + trigger: - platform: homeassistant event: start @@ -10,17 +11,16 @@ condition: action: - choose: - # Hvis slutdato allerede er passeret → sluk med det samme + - conditions: - condition: template - value_template: "{{ now() >= states('input_datetime.vacation_end') | as_datetime }}" + value_template: > + {% set dt = states('input_datetime.vacation_end') %} + {{ dt not in ['unknown','unavailable',''] and + now() >= as_datetime(dt) }} sequence: - service: input_boolean.turn_off target: entity_id: - input_boolean.vacation_mode - input_boolean.presence_simulation - - # Ellers → gør ingenting (time trigger tager over) - - conditions: [] - sequence: [] diff --git a/include/sensors/time_date.yaml b/include/sensors/time_date.yaml new file mode 100644 index 0000000..1934eeb --- /dev/null +++ b/include/sensors/time_date.yaml @@ -0,0 +1,25 @@ +- platform: template + sensors: + + n22_dato: + friendly_name: "Dato" + value_template: > + {{ now().strftime('%A %d %B') | replace('Monday','Mandag') + | replace('Tuesday','Tirsdag') + | replace('Wednesday','Onsdag') + | replace('Thursday','Torsdag') + | replace('Friday','Fredag') + | replace('Saturday','Lørdag') + | replace('Sunday','Søndag') }} + + n22_solopgang: + friendly_name: "Solopgang" + value_template: > + {% set t = state_attr('sun.sun','next_rising') %} + {{ as_timestamp(t) | timestamp_custom('%H:%M') if t else '-' }} + + n22_solnedgang: + friendly_name: "Solnedgang" + value_template: > + {% set t = state_attr('sun.sun','next_setting') %} + {{ as_timestamp(t) | timestamp_custom('%H:%M') if t else '-' }}