For this project I started out with the idea of having the lights turn on and off as I walked around my apartment. The idea was to only have lights on in the room that I was occupying to save electricity costs and the obvious “wow” factor.
Here is an explanation of how it all works.
Motion Sensor Selection:
For this project the key element is finding motion sensors that can quickly return to an “off” or “idle” state to ensure they can be ready to respond to motion again as the occupant moves from room to room. Ideally this value is as low as possible hopefully sub 2 seconds depending on the size of the room. The reason behind this is that if I were to walk from my living room into the bedroom and back into the living room quickly I want to ensure that Home Assistant receives a “on” or “motion triggered” event each time I cross the door way.
To this end I ended up going with the Fibaro Multi Sensor. It has configurable blind an active times that can be set as low a 0.5 seconds so they’re ideal for triggering frequently when transitioning between rooms.
Motion Sensor Placement:
Second was the placement of the motion sensors themselves, because in order to ensure that the sensors were not constantly being triggered and unprepared to trigger on when movement between rooms would occur. I found that the ideal placement was where the motion sensors could see the doorways, but not be triggered by movement in idea areas.
For example, if I am sitting on the couch and move around the motion sensor will not be triggered. The advantage to this setup is that motion triggering is focused around an event when movement between rooms will likely occur so false positives such as the uncertainty of what will happen within those 2 seconds of blind time is minimized and can be accommodated for in the home assistant automation.
A second benefit is that the motion sensors themselves can also maintain battery life for longer even with events being triggered substantially more often.
Home Assistant Configuration:
################################################################
## Packages / Motion Lights
################################################################
# @todo Handle non-realistic transitions gracefully
################################################
## Customize
################################################
homeassistant:
customize:
packages.motion_lights: &customize
package: 'motion_lights'
binary_sensor.aeotec_zw100_multisensor_6_sensor_3_0:
<<: *customize
friendly_name: Closet Motion
binary_sensor.fibaro_system_fgms001zw5_motion_sensor_sensor_4_0:
<<: *customize
friendly_name: Bathroom Motion
binary_sensor.fibaro_system_fgms001zw5_motion_sensor_sensor_5_0:
<<: *customize
friendly_name: Bedroom Motion
binary_sensor.fibaro_system_fgms001zw5_motion_sensor_sensor_6_0:
<<: *customize
friendly_name: Livingroom Motion
binary_sensor.fibaro_system_fgms001zw5_motion_sensor_sensor_7_0:
<<: *customize
friendly_name: Kitchen Motion
input_select.last_motion_triggered:
<<: *customize
friendly_name: 'Last Motion Triggered In'
group.livingroom_motion_off:
<<: *customize
hidden: true
group.closet_motion_off:
<<: *customize
hidden: true
group.bedroom_motion_off:
<<: *customize
hidden: true
group.bathroom_motion_off:
<<: *customize
hidden: true
group.kitchen_motion_off:
<<: *customize
hidden: true
group.livingroom_motion_on:
<<: *customize
hidden: true
group.closet_motion_on:
<<: *customize
hidden: true
group.bedroom_motion_on:
<<: *customize
hidden: true
group.bathroom_motion_on:
<<: *customize
hidden: true
group.kitchen_motion_on:
<<: *customize
hidden: true
input_boolean.dummy:
<<: *customize
hidden: true
################################################
## Groups
################################################
group:
livingroom_motion_on:
entities:
- group.livingroom_lights
bedroom_motion_on:
entities:
- light.bedroom_lamp
bathroom_motion_on:
entities:
- group.bathroom_lights
closet_motion_on:
entities:
- light.closet_light
kitchen_motion_on:
entities:
- group.kitchen_lights
kitchen_motion_off:
entities:
- group.livingroom_lights
- group.bedroom_lights
- group.bathroom_lights
- light.closet_light
livingroom_motion_off:
entities:
- group.kitchen_lights
- group.bedroom_lights
- group.bathroom_lights
- light.closet_light
bathroom_motion_off:
entities:
- group.livingroom_lights
- group.bedroom_lights
- group.kitchen_lights
- light.closet_light
bedroom_motion_off:
entities:
- group.livingroom_lights
- group.bathroom_lights
- group.kitchen_lights
- light.closet_light
closet_motion_off:
entities:
- group.livingroom_lights
- group.bathroom_lights
- group.kitchen_lights
################################################
## Input Boolean
################################################
input_boolean:
dummy:
name: dummy input for automations
################################################
## Input Select
################################################
input_select:
last_motion_triggered:
initial: Livingroom
options:
- Livingroom
- Kitchen
- Bedroom
- Bathroom
- Closet
################################################
## Automation
################################################
automation:
- alias : Update last_motion_triggered from motion sensor last triggered.
trigger:
platform: state
entity_id:
- binary_sensor.aeotec_zw100_multisensor_6_sensor_3_0
- binary_sensor.fibaro_system_fgms001zw5_motion_sensor_sensor_4_0
- binary_sensor.fibaro_system_fgms001zw5_motion_sensor_sensor_5_0
- binary_sensor.fibaro_system_fgms001zw5_motion_sensor_sensor_6_0
- binary_sensor.fibaro_system_fgms001zw5_motion_sensor_sensor_7_0
to: 'on'
action:
- service: input_select.select_option
data_template:
entity_id: input_select.last_motion_triggered
option: "{{ trigger.to_state.attributes.friendly_name | replace(' Motion', '') }}"
- alias : Adjust lights based on last_motion_triggered selection.
trigger:
platform: state
entity_id: input_select.last_motion_triggered
action:
- service: light.turn_on
data_template:
entity_id: "group.{{ trigger.to_state.state | lower }}_motion_on"
- service: light.turn_off
data_template:
entity_id: >
{% if (as_timestamp(now()) - as_timestamp(trigger.from_state.last_updated)) | int > 1 %}
group.{{ trigger.to_state.state | lower }}_motion_off
{% else %}
input_boolean.dummy
{% endif %}
transition: 3
The code above is the home assistant automation that I am using to control the lights. There are two major groups. One that controls the lights that will be turned off when I enter a specific room and one that will turn the lights on when I enter a specific room. Secondly there is an input_select that shares the same naming scheme as the room so that the automation can concatenate the necessary commands to perform the action. Lastly there is a timestamp check that ensures that lights will not be turned off if a transition occurs to quickly, since the system cannot be sure in which direction the motion occurred.
Eventually I would like to simplify the timeframe code using statistics sensors to make the transition time is dynamic and more robust.
Conclusion:
Overall I am very happy with how this is working and you can see a demonstration here: https://www.youtube.com/watch?v=kRRXve7HTpE
If you have any questions please let me know!