113 lines
3.7 KiB
YAML
113 lines
3.7 KiB
YAML
- id: stue_motion_lys
|
|
alias: Stue lys via bevaegelse
|
|
mode: restart
|
|
|
|
trigger:
|
|
- platform: state
|
|
entity_id: binary_sensor.stue_bevaegelse
|
|
to: "on"
|
|
id: motion_on
|
|
|
|
- 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: trigger
|
|
id: motion_on
|
|
- condition: template
|
|
value_template: >
|
|
{{ states('sensor.stue_belysningsstyrke') | int < lux_limit }}
|
|
sequence:
|
|
- 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: trigger
|
|
id: motion_off
|
|
- condition: template
|
|
value_template: >
|
|
{{ dagperiode != 'aften' or
|
|
is_state('media_player.samsung_s95ca_55_3', 'off') }}
|
|
sequence:
|
|
- 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: 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
|