From 730d47a568ae708696b92c0bd87a231e7a04ad18 Mon Sep 17 00:00:00 2001 From: Tony Stork Date: Fri, 20 Oct 2023 12:29:09 -0400 Subject: [PATCH] Add automation for Give Me Darkness if we haven't run it, close #161 --- automations.yaml | 27 +++++++++++++++++++++++++++ scripts.yaml | 37 +++++++++++++++++++++++++++---------- 2 files changed, 54 insertions(+), 10 deletions(-) diff --git a/automations.yaml b/automations.yaml index 547ecff..a1ee332 100644 --- a/automations.yaml +++ b/automations.yaml @@ -2974,3 +2974,30 @@ adapt_brightness: '{{ is_state(''switch.adaptive_lighting_adapt_brightness_master_bedroom'',''on'') }}' mode: restart +- id: '1697819133179' + alias: Give Me Darkness + description: Automatically trigger Give Me Darkness if it has not already happened + trigger: + - platform: template + value_template: '{% from ''time.jinja'' import ct %} + + {% set ct = ct() | int %} + + {% set bedtime = states(''input_datetime.kallen_bedtime'') | int + 1800 %} + + {{ ct >= bedtime }}' + alias: When it is half an hour past K's bedtime + condition: + - condition: state + entity_id: input_boolean.give_me_darkness + state: 'off' + alias: Give Me Darkness isn't already on + - condition: state + entity_id: binary_sensor.parents_home + state: 'on' + alias: We are home + action: + - service: script.give_me_darkness + data: + auto: 1 + mode: single diff --git a/scripts.yaml b/scripts.yaml index f07d311..94d1db8 100644 --- a/scripts.yaml +++ b/scripts.yaml @@ -44,17 +44,36 @@ give_me_darkness: retain: true topic: house/time/give_me_darkness payload: 'on' - - if: - - condition: state - entity_id: input_boolean.guest_mode - state: 'off' + - alias: Security decision + if: + - condition: and + conditions: + - condition: state + entity_id: person.tony_stork + state: home + - condition: state + entity_id: person.christina_stork + state: home + - condition: state + entity_id: input_boolean.guest_mode + state: 'off' + - condition: state + entity_id: alarm_control_panel.nerdhome_alarm_panel + state: disarmed + alias: Both adults are home, guest mode off, security disarmed then: - - if: + - alias: Auto or manual trigger? + if: - condition: template - value_template: '{{ is_state(''person.tony_stork'',''home'') and is_state(''person.christina_stork'',''home'') - }}' - alias: Both adults are home + value_template: '{{ auto == 1 }}' + alias: Triggered by automation then: + - service: alarm_control_panel.alarm_arm_home + data: {} + target: + entity_id: alarm_control_panel.nerdhome_alarm_panel + alias: Arm security + else: - service: script.activate_alexa_actionable_notification data: text: Would you like me to arm @@ -62,8 +81,6 @@ give_me_darkness: event_id: actionable_notification_night_security_arm alexa_device: '{{ states(''sensor.last_alexa_entity_id'') }}' alias: Ask to arm security - alias: Ask to arm security if both adults are home - alias: If guest mode is off mode: single icon: mdi:weather-night start_youtube: