From 61641beec9fa7e43db7d0556d41e7f224eca453d Mon Sep 17 00:00:00 2001 From: Tony Stork Date: Sat, 18 Mar 2023 20:56:14 -0400 Subject: [PATCH] Improve presence and lighting control in the basement --- packages/lighting_and_scenes.yaml | 37 ++++++++++++++++++------------- packages/presence.yaml | 14 ++++++++++++ packages/sysmon.yaml | 22 +++++++++++++++++- 3 files changed, 57 insertions(+), 16 deletions(-) diff --git a/packages/lighting_and_scenes.yaml b/packages/lighting_and_scenes.yaml index 324223c..152541b 100644 --- a/packages/lighting_and_scenes.yaml +++ b/packages/lighting_and_scenes.yaml @@ -546,8 +546,8 @@ automation: # The delay is to prevent the boolean from re-running the automation if the lights were turned on manually - id: 47645bcf-a6ed-4c34-8ece-8daed4b10d9a - alias: Basement Door Handling - description: Turns on lights in basement when door is opened, if not already on + alias: Basement Lights Handling + description: Handles the presence-related automation of lights in the basement mode: restart trigger: - platform: state @@ -566,12 +566,15 @@ automation: entity_id: timer.basement_studio_door_timer id: timer-finished - platform: state - entity_id: - - binary_sensor.tony_desktop_on - - binary_sensor.kallen_desktop_on + entity_id: binary_sensor.basement_unoccupied + from: 'on' + to: 'off' + id: basement-occupied + - platform: state + entity_id: binary_sensor.basement_unoccupied from: 'off' to: 'on' - id: computers-on + id: basement-unoccupied condition: - condition: state entity_id: input_boolean.studio_quiet @@ -598,14 +601,9 @@ automation: id: door-closed sequence: - if: - - condition: and - conditions: - - condition: state - entity_id: binary_sensor.tony_desktop_on - state: 'off' - - condition: state - entity_id: binary_sensor.kallen_desktop_on - state: 'off' + - condition: state + entity_id: binary_sensor.basement_unoccupied + state: 'on' then: - service: timer.start target: @@ -614,11 +612,20 @@ automation: duration: "{{ (states('input_number.basement_studio_lights_off_delay') | int ) * 60 }}" - conditions: - condition: trigger - id: computers-on + id: basement-occupied sequence: - service: timer.cancel target: entity_id: timer.basement_studio_door_timer + - conditions: + - condition: trigger + id: basement-unoccupied + sequence: + - service: timer.start + target: + entity_id: timer.basement_studio_door_timer + data: + duration: "{{ (states('input_number.basement_studio_lights_off_delay') | int ) * 60 }}" - conditions: - condition: trigger id: timer-finished diff --git a/packages/presence.yaml b/packages/presence.yaml index a0907e2..6e2163c 100644 --- a/packages/presence.yaml +++ b/packages/presence.yaml @@ -265,6 +265,20 @@ template: false {% endif %} device_class: presence + - name: "Basement Unoccupied" + unique_id: 20039c29-8b9d-436d-ba6c-8f2c2bda1db0 + state: > + {% if is_state('binary_sensor.tony_desktop_on','off') and is_state('binary_sensor.kallen_desktop_on','off') %} + true + {% elif is_state('binary_sensor.tony_desktop_idle','on') and is_state('binary_sensor.kallen_desktop_idle','on') %} + true + {% elif is_state('binary_sensor.tony_desktop_idle','on') and is_state('binary_sensor.kallen_desktop_on','off') %} + true + {% elif is_state('binary_sensor.kallen_desktop_idle','on') and is_state('binary_sensor.tony_desktop_on','off') %} + true + {% else %} + false + {% endif %} mqtt: sensor: diff --git a/packages/sysmon.yaml b/packages/sysmon.yaml index ff419ad..94e30da 100644 --- a/packages/sysmon.yaml +++ b/packages/sysmon.yaml @@ -104,7 +104,27 @@ template: state: "{{ states('sensor.basement_server_power') | int > 10 }}" device_class: power attributes: - power_usage: "{{ states('sensor.basement_server_power') }}" + power_usage: "{{ states('sensor.basement_server_power') | int }}W" + - name: Tony Desktop Idle + unique_id: f0ace986-a874-4fb0-ad29-8f3ebf95d8cc + state: "{{ states('sensor.tony_asus_system_idle_time') | int > 3600 }}" + attributes: + idle_time: "{{ states('sensor.tony_asus_system_idle_time') | int }}s" + - name: Tina Desktop Idle + unique_id: 1933c638-c94b-468e-bb7a-c1c5b36c3651 + state: "{{ states('sensor.xia_desktop_system_idle_time') | int > 3600 }}" + attributes: + idle_time: "{{ states('sensor.xia_desktop_system_idle_time') | int }}s" + - name: Kallen Desktop Idle + unique_id: 680c6ae3-2ed2-451e-858b-2aee688af461 + state: "{{ states('sensor.kallen_desktop_system_idle_time') | int > 3600 }}" + attributes: + idle_time: "{{ states('sensor.kallen_desktop_system_idle_time') | int }}s" + - name: Asus Laptop Idle + unique_id: 7d8eb80a-0a2e-48a9-84b3-33175304dd95 + state: "{{ states('sensor.asus_laptop_system_idle_time') | int > 3600 }}" + attributes: + idle_time: "{{ states('sensor.asus_laptop_system_idle_time') }}s" # - platform: influxdb # host: 192.168.1.26