Motion detect sensor being "unavailable" blocks blueprint automation

I have an automation that turns on my attic light when motion is detected by my Ikea zigbee motion sensor. But the sensor goes from “Clear” to “Unavailable” after some hours. And this causes the blueprint to not trigger. The motion sensor will change from “Unavailable” to “Detected” just fine, but it will not trigger the automation.

What would be the best way of handling this? Drop the blueprint and create a new automation that triggers even if the motion sensor goes from “Unavailable” to “Detected”? Or can I do some magic so the motion sensor doesn’t go to “Unavailable”?

Here’s my automation:

alias: Loftet - Slå på taklys ved bevegelse
description: ""
use_blueprint:
  path: homeassistant/motion_light.yaml
  input:
    motion_entity: binary_sensor.loft_bevegelsessensor
    light_target:
      entity_id:
        - light.cleverio_lb230_2
        - light.cleverio_lb230
    no_motion_wait: 300

This is the included blueprint from Home Assistant and several people have improved on it.
You can search the Blueprint Exchange for something that works better, or take control of that one and edit it as an automation, probably adding not_to: and/or not_from: key in the trigger.

They want the opposite. The do want it to trigger when going unavailable → on

For which this is probably the best option:

And you do it by not specifying a from: option for the state trigger. Only a to: 'on' option.

triggers:
  - trigger: state
    entity_id: binary_sensor.loft_bevegelsessensor
    to: "on"

You might even be able to edit the blueprint to do this.

Though this is possible too:

You would have to create a template binary sensor for each motion sensor.

template:
  - binary_sensor:
      - name: Better Loft Motion 
        device_class: motion
        state: >
          {{ is_state("binary_sensor.loft_bevegelsessensor", "on") }}

This will go to the Clear state when anything other than Detected.

2 Likes

I remembered why I started using the blueprint in the first place: To simplify the automations I had earlier, using separate automations for “on” and "off, and a timer to control when to trigger the “off” automation. :blush:

I ended up now just copying the motion light blueprint and removing the “from” property from the trigger as you suggested. Worked like a charm!

Thanks for the help!

@ohj Personally, I would fix the root cause of the sensor going unavailable. Luckily, it’s a pretty simple fix if you understand what’s going on.

ZHA’s default setting for marking devices as Unavailable is set to 21600 seconds (6 hours) for battery devices. Basically, if a battery device doesn’t “check in” or send a message to ZHA, it will be marked as unavailable.

Looking at your Activity screenshot above, your sensor is going unavailable pretty much exactly at the 6 hour mark (give or take a few seconds). Looks like the Ikea sensor doesn’t report as frequently as ZHA expects.

To fix this, go to Settings > Integrations > ZHA > Configure (cog icon) & scroll down to the “Consider battery-powered devices unavailable after” field.
Change that 21600s value to something much higher. As a baseline example, that setting in Z2M is set to 25h, so I’d set the value to 86400-90000.
Remember to click “Update Configuration” for the setting to actually apply!

2 Likes

That’s a very good point. I didn’t consider that this started being a problem after I went from DeCONZ to ZHA. I believe DeCONZ also has a 24 hour period before considering a battery powered device offline.

Thanks for the tip!

1 Like