What is this?
Home Assistant is dense. It’s got a gui, but the gui needs at least several million dollars of software development to be usable, imho.
It uses yml (Yaml) files for configuration and it’s mostly plain-language and easy to piece together what an automation is doing. It only comes with two example Automations, but many more can be found online.
One of the example automations is motion_light.yml however it does not work with smart switches like the S31. Why? Because the device class is switch, not light. When I first saw this I thought oh no it’s another one of those things that is way too opinionated
Fortunately, it was trivial to modify the automation to work with switches instead of lights (note the source url is the unmodified source):
blueprint:
name: Motion-activated Light
description: Turn on a light when motion is detected.
domain: automation
source_url: https://github.com/home-assistant/core/blob/dev/homeassistant/components/automation/blueprints/motion_light.yaml
input:
motion_entity:
name: Motion Sensor
selector:
entity:
domain: binary_sensor
device_class: motion
switch_target:
name: Light
selector:
target:
entity:
domain: switch
no_motion_wait:
name: Wait time
description: Time to leave the light on after last motion is detected.
default: 120
selector:
number:
min: 0
max: 3600
unit_of_measurement: seconds
# If motion is detected within the delay,
# we restart the script.
mode: restart
max_exceeded: silent
trigger:
platform: state
entity_id: !input motion_entity
from: "off"
to: "on"
action:
- service: switch.turn_on
target: !input switch_target
- wait_for_trigger:
platform: state
entity_id: !input motion_entity
from: "on"
to: "off"
- delay: !input no_motion_wait
- service: switch.turn_off
target: !input switch_target
With tbe basic GUI automation editor, it’s tricky to setup something like:
When you see motion, turn on the light but after you don’t see motion for X minutes, turn off the light. The UI here actually does do some clever stuff – the YML file lets you specify to show the user a selector with 0 to 3600 seconds so they can drag a slider to whatever makes sense (rather than edit the yaml).
The problem here is it’s setup for smart lights, like Phillips Hue. In our case, this LED strip for under-cabinet lighting is controlled by a smart plug, a switch, not a light. It’s a switch with al light plugged into it. IMHO there isn’t a lot of difference there, but I saw no way via the gui to “cast” the device class from switch to light for that particular switch, so here’s the modified recipe.
With this automation, the gui makes sense, and lets you pick the appropriate devices. For motion, I have integration of Home Assistant into the DSC1864 alarm panel.
Check out the video on using an alarm panel & alarm sensors as part of your home automation solution. It works well.
Hope that helps someone else, and the explanation helps you grok the overall system better.
The ‘cookbook’ is good further reading, but surprising they don’t cover this sort of thing on the light automation page: