Stue lys: moderniser til 1 automation (mode:restart), input_number parametre for lux+timeouts

This commit is contained in:
2026-04-25 19:28:13 +02:00
parent 9cb7550f78
commit 6208f6fb49
3 changed files with 202 additions and 147 deletions
+95 -140
View File
@@ -1,157 +1,112 @@
- id: stue_motion_lys
alias: Stue lys via bevægelse
alias: Stue lys via bevaegelse
mode: restart
trigger:
- platform: state
entity_id: binary_sensor.stue_bevaegelse
to: "on"
id: motion_on
condition:
- condition: numeric_state
entity_id: sensor.stue_belysningsstyrke
below: 60
- platform: state
entity_id: binary_sensor.stue_bevaegelse
to: "off"
id: motion_off
- platform: state
entity_id: media_player.samsung_s95ca_55_3
to: "off"
id: tv_off
variables:
lux_limit: "{{ states('input_number.stue_lux_threshold') | int }}"
dagperiode: >
{% set t = now().strftime('%H%M') | int %}
{% if 600 <= t < 1600 %}morgen
{% elif 1600 <= t < 1900 %}eftermiddag
{% elif 1900 <= t %}aften
{% else %}nat{% endif %}
timeout_min: >
{% set t = now().strftime('%H%M') | int %}
{% if 600 <= t < 1600 %}
{{ states('input_number.stue_timeout_morgen') | int }}
{% elif 1600 <= t < 1900 %}
{{ states('input_number.stue_timeout_eftermiddag') | int }}
{% elif 1900 <= t %}
{{ states('input_number.stue_timeout_aften') | int }}
{% else %}
{{ states('input_number.stue_timeout_nat') | int }}
{% endif %}
action:
- choose:
# Motion on: taend lys hvis lux lavt
- conditions:
- condition: time
after: "06:00:00"
before: "16:00:00"
- condition: trigger
id: motion_on
- condition: template
value_template: >
{{ states('sensor.stue_belysningsstyrke') | int < lux_limit }}
sequence:
- service: scene.turn_on
target:
entity_id: scene.stue_bright
- choose:
- conditions:
- condition: template
value_template: "{{ dagperiode == 'morgen' }}"
sequence:
- service: scene.turn_on
target:
entity_id: scene.stue_bright
- conditions:
- condition: template
value_template: "{{ dagperiode == 'eftermiddag' }}"
sequence:
- service: scene.turn_on
target:
entity_id: scene.stue_annes_favorit
default:
- service: scene.turn_on
target:
entity_id: scene.stue_relax_minus_syd
# Motion off: vent timeout, sluk hvis stadig ingen bevaegelse
# Aften: springer over hvis TV er taendt (TV-off trigger haandterer det)
- conditions:
- condition: time
after: "16:00:00"
before: "22:00:00"
- condition: trigger
id: motion_off
- condition: template
value_template: >
{{ dagperiode != 'aften' or
is_state('media_player.samsung_s95ca_55_3', 'off') }}
sequence:
- service: scene.turn_on
- delay:
minutes: "{{ timeout_min }}"
- condition: state
entity_id: binary_sensor.stue_bevaegelse
state: "off"
- condition: template
value_template: >
{{ dagperiode != 'aften' or
is_state('media_player.samsung_s95ca_55_3', 'off') }}
- service: light.turn_off
target:
entity_id: scene.stue_annes_favorit
default:
- service: scene.turn_on
target:
entity_id: scene.stue_relax_minus_syd
entity_id: light.livingroom
- id: stue_motion_sluk_morgen
alias: Sluk stue lys efter 60 min uden bevægelse om morgenen
mode: restart
trigger:
- platform: state
entity_id: binary_sensor.stue_bevaegelse
to: "off"
condition:
- condition: time
after: "06:00:00"
before: "16:00:00"
action:
- wait_for_trigger:
- platform: state
entity_id: binary_sensor.stue_bevaegelse
to: "on"
timeout: "01:00:00"
continue_on_timeout: true
- condition: state
entity_id: binary_sensor.stue_bevaegelse
state: "off"
- service: light.turn_off
target:
entity_id: light.livingroom
- id: stue_motion_sluk_eftermiddag_aften
alias: Sluk stue lys efter 120 min uden bevægelse mellem 16 og 19
mode: restart
trigger:
- platform: state
entity_id: binary_sensor.stue_bevaegelse
to: "off"
condition:
- condition: time
after: "16:00:00"
before: "19:00:00"
action:
- wait_for_trigger:
- platform: state
entity_id: binary_sensor.stue_bevaegelse
to: "on"
timeout: "02:00:00"
continue_on_timeout: true
- condition: state
entity_id: binary_sensor.stue_bevaegelse
state: "off"
- service: light.turn_off
target:
entity_id: light.livingroom
- id: stue_motion_sluk_aften_tv
alias: Sluk stue lys efter 10 min uden bevægelse når TV er slukket mellem 19 og 00
mode: restart
trigger:
- platform: state
entity_id: binary_sensor.stue_bevaegelse
to: "off"
- platform: state
entity_id: media_player.samsung_s95ca_55_3
to: "off"
condition:
- condition: time
after: "19:00:00"
before: "00:00:00"
action:
- condition: state
entity_id: media_player.samsung_s95ca_55_3
state: "off"
- wait_for_trigger:
- platform: state
entity_id: binary_sensor.stue_bevaegelse
to: "on"
timeout: "00:10:00"
continue_on_timeout: true
- condition: state
entity_id: binary_sensor.stue_bevaegelse
state: "off"
- condition: state
entity_id: media_player.samsung_s95ca_55_3
state: "off"
- service: light.turn_off
target:
entity_id: light.livingroom
- id: stue_motion_sluk_nat
alias: Sluk stue lys efter 30 min uden bevægelse om natten
mode: restart
trigger:
- platform: state
entity_id: binary_sensor.stue_bevaegelse
to: "off"
condition:
- condition: time
after: "00:00:00"
before: "06:00:00"
action:
- wait_for_trigger:
- platform: state
entity_id: binary_sensor.stue_bevaegelse
to: "on"
timeout: "00:30:00"
continue_on_timeout: true
- condition: state
entity_id: binary_sensor.stue_bevaegelse
state: "off"
- service: light.turn_off
target:
entity_id: light.livingroom
# TV slukket om aftenen: vent 10 min, sluk hvis ingen bevaegelse
- conditions:
- condition: trigger
id: tv_off
- condition: template
value_template: "{{ dagperiode == 'aften' }}"
sequence:
- delay:
minutes: "{{ timeout_min }}"
- condition: state
entity_id: binary_sensor.stue_bevaegelse
state: "off"
- condition: state
entity_id: media_player.samsung_s95ca_55_3
state: "off"
- service: light.turn_off
target:
entity_id: light.livingroom