From 61c115be37dc22dfcc288078899af5990773f2bf Mon Sep 17 00:00:00 2001 From: Pierre Date: Fri, 17 Apr 2026 19:41:16 +0200 Subject: [PATCH] first sleep switch implementation --- apps/ad_toolbox | 2 +- apps/apps.yaml | 46 +++++++++++ apps/motiontracker.py | 186 ++++++++++++++++++++++++++++++++++++++++-- apps/smartlight.py | 141 ++++++++++++++++++++++++++++++-- apps/smartswitch.py | 138 +++++++++++++++++++++++++------ apps/yaml/apps.yaml | 21 ----- apps/yaml/lights.yaml | 23 +++++- 7 files changed, 492 insertions(+), 65 deletions(-) create mode 100644 apps/apps.yaml delete mode 100644 apps/yaml/apps.yaml diff --git a/apps/ad_toolbox b/apps/ad_toolbox index da28205..7dd39e0 160000 --- a/apps/ad_toolbox +++ b/apps/ad_toolbox @@ -1 +1 @@ -Subproject commit da282058d835ebd00e57f7e27c138918e906de4a +Subproject commit 7dd39e0ea948b8959a10403764fca7b952d29b1a diff --git a/apps/apps.yaml b/apps/apps.yaml new file mode 100644 index 0000000..9ee4010 --- /dev/null +++ b/apps/apps.yaml @@ -0,0 +1,46 @@ +debugger: + module: debugger + class: Debugger + port: 5678 + +motion_tracker: + module: motiontracker + class: MotionTracker + + priority: 5 # this need to be initialized before app using motion tracker + + mqtt_device_name: AD Motion Tracker + + max_time: 30 + + areas: + corridor: + motion_sensors: binary_sensor.corridor_motion + hallway: + motion_sensors: binary_sensor.hallway_motion + restroom: + motion_sensors: binary_sensor.restroom_motion + +sleep_switch: + + module: smartswitch + class: SmartSwitch + + entity: input_boolean.sleeping + + trace_events: zha_event + + toggle_events: + button_long_press: + event_name: zha_event + event_data: + device_ieee: '00:17:88:01:09:27:74:45' + args: + press_type: 'hold' + button: 'off' + reset_data: + device_ieee: '00:17:88:01:09:27:74:45' + args: + button: 'off' + press_type: 'long_release' + diff --git a/apps/motiontracker.py b/apps/motiontracker.py index b399d22..7608b11 100644 --- a/apps/motiontracker.py +++ b/apps/motiontracker.py @@ -4,13 +4,136 @@ from ad_toolbox.eventhandler import EventHandler from ad_toolbox.expressionparser import ParsingException import time +# ============================================================================= +# MotionTracker — Multi-area motion tracking app +# ============================================================================= +# Tracks the last time motion was detected in each configured area and exposes +# that information as HA sensor entities. Also optionally tracks door close +# events per area and can reset area data in response to custom HA events. +# +# Inherits all SmartObject YAML keys (see smartobject.py). +# +# YAML CONFIGURATION +# ------------------ +# +# max_time: # optional, default 120 +# Global cap for the "minutes since last motion" sensors. +# Overrides the MAX_TIME constant and can itself be overridden +# per area with the area-level max_time key. +# Precedence: area max_time > app max_time > MAX_TIME constant +# +# areas: +# : +# motion_sensors: +# One or more binary_sensor entities to watch. +# update_on_both_front: true # optional, default false +# When true, motion is also recorded on the falling edge +# (sensor going on→off), not only on the rising edge. +# max_time: # optional +# Per-area cap, overrides the app-level max_time. +# door_sensor: # optional +# Binary sensor for the area door. When the door closes +# (on→off), the close timestamp is stored and exposed as +# a sensor (see OUTPUT ENTITIES below). +# # Shorthand form (no extra options needed): +# : +# +# areas_excluded_from_last_area_with_movement: +# - +# - ... +# Areas that should NOT update sensor.last_area_with_movement when motion is +# detected in them (e.g. utility rooms). +# +# clear_areas_events: +#