fix presence

This commit is contained in:
2026-03-25 21:06:57 +01:00
parent bef3fc5b4c
commit 0b4fc7f2f4
4 changed files with 124 additions and 54 deletions
+85 -46
View File
@@ -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
+8 -2
View File
@@ -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:
+6 -6
View File
@@ -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: []
+25
View File
@@ -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 '-' }}