Hi all. Decided to give Home Assistant a try after hearing nothing but good things about it from a friend. I had a very broad setup with OpenHab 2 that worked well enough but it always had strange stability issues and automation would sometimes be slow to fire. I use Z-wave for most everything and, after some struggles, I was able to get all of my old nodes recognized in HA and now I’m trying to write my first rule. What I want it to do seems simple enough - when one of my motion sensors detects movement, turn on the light in the same room for 15 minutes (and reset the 15 minute counter each time motion is detected). As a conditional, I only want the light to turn on if the outdoor luminance is less than 700 lux from the front yard sensor.
I set up what I think should cause the light to turn on and whittled it down to bare bones but it doesn’t appear to be working.
TRIGGER
platform: state
entity_id: sensor.living_room_multisensor_motion
to: "8"
for: "00:15:00"
Unfortunately, when I attempt to trigger this rule, nothing happens. The “to” state of 8 in the trigger seems arbitrary but that’s the value reported by that entity to HA when motion is detected. Is there a log I can watch to determine where there might be an error or is there something obviously wrong here?
Generally a motion sensor would be binary (on for motion, off for clear). A simple automation that turns a light on when there’s motion, and off after 15 minutes of no motion looks like this…
automation:
trigger:
- platform: state
entity_id: binary_sensor.1
to: 'on'
- platform: state
entity_id: binary_sensor.1
to: 'off'
for:
minutes: 15
action:
service: "light.turn_{{ trigger.to_state.state }}"
entity_id: light.1
Of course, if your motion sensor cannot be used as a binary sensor then the trigger will need to reflect the states for motion and clear correctly, and the template will need to be changed to correctly return ‘on’ for motion and ‘off’ for clear, whereas the binary sensor state would already match what you wanted it to do.
I don’t use zwave anymore, and haven’t for a long time, but I’m sure that it did expose my motion sensor as a binary sensor when I did. Can you check your states list for a binary sensor that’s been created for you for motion?
If not you’ll have to either adapt the automation (I can help if you tell me the correct states), or wait for someone who knows zwave better than me to give us a clue why you don’t have a binary sensor (and hopefully fix it).
@EKC - This seems to have gotten things working! Thank you for the pointers, especially around the ‘for’ parameter. That wasn’t at all the interpretation I had from the documentation. Definitely still have a lot to learn about how this works.
@anon43302295 - For some reason, these sensors do not report having a binary sensor in HA. IRC, they did, however, in OpenHab. I’m not sure what to make of that… does HA change what entities have or how they’re assigned based on what they are named? Like, is there some intelligence behind those assignments?
Also, Where can I check the states list? The only thing I can find is the current state in the developer tools tab.
Trigger when the motion sensor’s value is 8 and stays at 8 for at least 15 minutes.
I don’t believe that is the behaviour you want: 15 solid minutes of motion must occur before the light is turned on.
You said the sensor reports ‘8’ when motion is detected. What does it report when there is no motion? Its values are displayed in Developer Tools > States. (Keep in mind that all state values are strings so even if it reports 8 that’s a string value.)
Let’s say it reports 0 when there’s no motion. Using that information, we can modify mf_social’s example:
automation:
trigger:
- platform: state
entity_id: sensor.living_room_multisensor_motion.1
to: '8'
- platform: state
entity_id: sensor.living_room_multisensor_motion
to: '0'
for:
minutes: 15
action:
service: "light.turn_{{ trigger.to_state.state }}"
entity_id: light.linear_nortek_security_control_llc_pd300z_2_plug_in_dimmer_module_level
EDIT
I made a mistake in the service template. Use the corrected version in mf_social’s post below.