Last active
October 31, 2024 22:10
-
-
Save MattJeanes/c46220fc3d3c779d92f46b12946aca37 to your computer and use it in GitHub Desktop.
Home Assistant automation for ZHA joined Hue motion sensors to replicate the Hue app functionality
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
blueprint: | |
name: ZHA Hue Motion Sensor | |
description: Replicate Hue Motion Sensor functionality with ZHA | |
domain: automation | |
input: | |
occupancy_id: | |
name: Occupancy Sensor | |
description: Hue Motion Sensor Occupancy | |
selector: | |
entity: | |
filter: | |
domain: binary_sensor | |
device_class: occupancy | |
light_id: | |
name: Light | |
description: Light to control | |
selector: | |
entity: | |
domain: light | |
day_scene: | |
name: Day Scene | |
description: Scene to set when motion is detected during the day | |
selector: | |
entity: | |
domain: scene | |
night_scene: | |
name: Night Scene | |
description: Scene to set when motion is detected during the night | |
selector: | |
entity: | |
domain: scene | |
day_time: | |
name: Day Time | |
description: Time to consider as day | |
default: "07:00:00" | |
selector: | |
time: | |
night_time: | |
name: Night Time | |
description: Time to consider as night | |
default: "23:00:00" | |
selector: | |
time: | |
illuminance_id: | |
name: Illuminance Sensor | |
description: Illuminance Sensor to check before turning on the light | |
selector: | |
entity: | |
domain: sensor | |
integration: zha | |
device_class: illuminance | |
illuminance_helper_id: | |
name: Illuminance Helper | |
description: Input number helper to store the illuminance value to avoid issues with illuminance updating while the light is on | |
selector: | |
entity: | |
domain: input_number | |
illuminance_threshold: | |
name: Illuminance Threshold | |
description: Illuminance threshold to be less than before turning on the light | |
default: 50 | |
selector: | |
number: | |
min: 0 | |
max: 1000 | |
step: 1 | |
unit_of_measurement: lx | |
condition: | |
name: Condition | |
description: Condition to check before turning on/off the light | |
default: [] | |
selector: | |
condition: {} | |
dim_duration: | |
name: Dim Duration | |
description: How long to wait before dimming the light | |
default: | |
hours: 0 | |
minutes: 0 | |
seconds: 30 | |
selector: | |
duration: | |
off_duration: | |
name: Off Duration | |
description: How long to wait before turning off the light | |
default: | |
hours: 0 | |
minutes: 1 | |
seconds: 0 | |
selector: | |
duration: | |
triggers: | |
- trigger: state | |
entity_id: !input occupancy_id | |
to: "off" | |
for: !input dim_duration | |
id: not_occupied_dim | |
- trigger: state | |
entity_id: !input occupancy_id | |
to: "off" | |
for: !input off_duration | |
id: not_occupied_off | |
- trigger: state | |
entity_id: !input occupancy_id | |
to: "on" | |
id: occupied | |
- trigger: state | |
entity_id: !input illuminance_id | |
id: illuminance | |
conditions: !input condition | |
actions: | |
- choose: | |
- conditions: | |
- condition: trigger | |
id: | |
- not_occupied_dim | |
sequence: | |
- if: | |
- condition: state | |
entity_id: !input light_id | |
state: "on" | |
then: | |
- variables: | |
light_id: !input light_id | |
- action: light.turn_on | |
metadata: {} | |
data: | |
brightness: > | |
{{ state_attr(light_id,'brightness') / 2 }} | |
target: | |
entity_id: !input light_id | |
- conditions: | |
- condition: trigger | |
id: | |
- not_occupied_off | |
sequence: | |
- action: light.turn_off | |
target: | |
entity_id: !input light_id | |
- conditions: | |
- condition: trigger | |
id: | |
- occupied | |
sequence: | |
- if: | |
- condition: numeric_state | |
entity_id: !input illuminance_helper_id | |
below: !input illuminance_threshold | |
then: | |
- choose: | |
- conditions: | |
- condition: time | |
after: !input day_time | |
before: !input night_time | |
sequence: | |
- action: scene.turn_on | |
target: | |
entity_id: !input day_scene | |
- conditions: | |
- condition: time | |
after: !input night_time | |
before: !input day_time | |
sequence: | |
- action: scene.turn_on | |
target: | |
entity_id: !input night_scene | |
- conditions: | |
- condition: trigger | |
id: | |
- illuminance | |
sequence: | |
- if: | |
- condition: state | |
entity_id: !input light_id | |
state: "off" | |
then: | |
- variables: | |
illuminance_id: !input illuminance_id | |
- action: input_number.set_value | |
metadata: {} | |
data: | |
value: > | |
{{ states(illuminance_id) }} | |
target: | |
entity_id: !input illuminance_helper_id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment