Disable sensor on low battery

Hi,

I use Ikea Tradfri motion sensors. They’re great, except that when the battery gets very low on them (<30%) they tend to randomly fire motion events even when there isn’t any motion!

I have an automation which detects low battery level on these and alerts me via a message, which is great, but really I’d like to set the sensor to some kind of “disabled” state so that it doesn’t trigger my alarm script.

The sensors are connected via deconz, not sure if that helps or gives other options.

So on this I came up with an idea, but I’m struggling to get it to work.

My idea is to create a binary template sensor which checks for movement AND if the battery is at a good level. This is what I have so far:

Blockquote
binary_sensor:
platform: template
sensors:
hallway_motion_alarm:
friendly_name: “Hallway Alarm Motion”
value_template: >-
{is_state(‘binary_sensor.motion_sensor__hallway’, ‘on’)
and is_state_attr(‘binary_sensor.motion_sensor__hallway’, ‘battery_level’|float > 40)}
on
{else}
off
{endif}
Blockquote

But it doesn’t work.

The reason I’m trying to do this with a template sensor rather than conditional automations is because I’d like to re-use an existing alarm script which someone else has written - in any case it would be really useful to be able to do this for other uses!

Any help appreciated

Hi,
Just a thought: how do you handle the “motion detected” event? Do you have an automation for it? If so, can you add condition into the automation to check battery % >30 (not sure if there is a condition_template though, not an expert yet:(( )

Kostya

Doing it this way is an option, but means building my own alarm system from the manual component or from scratch.

I’d rather use this: https://github.com/gazoscalvertos/Hass-Custom-Alarm

which pretty much does everything I need of it, and is already written (lazy, I know!)

That custom component doesn’t use automations to drive detection, at least that I can see.

Another reason is that I think i’d end up needing an automation per sensor, which I’m trying to avoid.

Another point is that I’d like to learn more about how to use template sensors as well, as I can see lots of other uses for them :slight_smile:

So I’ve tried to split the problem up and the bit that isn’t working is def the battery level if statement.

binary_sensor:
platform: template
sensors:
  hallway_motion_alarm:
    friendly_name: "Hallway Alarm Motion"
    value_template: >-
      {{is_state('binary_sensor.motion_sensor__hallway', 'battery_level'|float > 40)}}
        on
      {else}
        off
      {endif}

This just gives the status of “unknown” in the template sensor