Keep the light on with Ikea Tradfri motion sensor

Hey,

I would like to make a simple automation and keep the lights on as long there is a movement in the bathroom. Nevertheless the light turns off after 1 minute and then I need to wave and wait for around 30 seconds until the light turns on again.
I am using Raspberry Pi 3 + Deconz + Home Assistant in a docker container. For sensors I am using Ikea motion sensor & light bulb. My automation code is:

- id: '1578393462491'
  alias: Turn the light on when motion is detected & it's dark
  description: ''
  trigger:
  - entity_id: binary_sensor.tradfri_motion_sensor
    platform: state
    to: 'on'
  action:
  - device_id: 8059b3a0a5ea4c42aa6134173d14aaca
    domain: light
    entity_id: light.ikea_dimmable_light_bad
    type: turn_on
- id: '1579034320307'
  alias: Turn off the light in bathroom after 2 mins
  description: ''
  trigger:
  - entity_id: binary_sensor.tradfri_motion_sensor
    platform: state
    to: 'off'
    for:
      minutes: 1
  action:
  - device_id: 8059b3a0a5ea4c42aa6134173d14aaca
    domain: light
    entity_id: light.ikea_dimmable_light_bad
    type: turn_off

Hi there and welcome to the Forum. You are not the first to have the “problem”. Maybe this will help you …

https://community.home-assistant.io/t/motion-detection-sensor-advice/150630

Hi Volker,

hmm not really, I still don’t know how to adjust the code so that my motion sensor checks let say every 15 seconds if there is some motion in order to let the lights on. And than go down with the brightness after 30 seconds and turn of the light after 1 minute without any movement.

You cannot set the motion sensor to check for motion in less than 1 minute.
It checks every minute for motion. If detects motion at exacly 60th second, it will not turn off the light.
You can extend the detection time after 60s if you add 30s or more in your automation before turning off the light. If it detects motion in that additional time of 30s, it will trigger the automation and extend the 1min time with 30s again.

Here is my automation:

- id: '1562755519522'
  alias: Kitchen - Light on when Motion detected
  trigger:
  - entity_id: binary_sensor.kitchen_motion_sensor
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
  - data:
      entity_id: light.kitchen_lightstrip
    service: light.turn_on
- id: '1562755519502'
  alias: Kitchen - Light off when no Motion detected
  trigger:
  - entity_id: binary_sensor.kitchen_motion_sensor
    for: 0:00:30
    from: 'on'
    platform: state
    to: 'off'
  condition: []
  action:
  - data:
      entity_id: light.kitchen_lightstrip
    service: light.turn_off

Motion sensors are built to big detect motion movements, eg. a person walking. They cannot detect a person sitting on the toilet and only fingers moving or fidgeting while seated.

With that in mind, you need to consider typically how long you might be in the room stationary.

For example, for my living room auto ambient lights, I’ve chosen 15 minutes timeout with override if TV is on. Similarly, for study (where I sit infront of computer to tweak HA), I’ve chosen 10 minutes and sometimes still find not long enough.
For toilet, I think 10 minutes is more suitable than 1-2 minutes.

I had more or less the same code as you, but it didn’t worked in my case.
I solved it now with this code:

- id: '1578393462491'
  alias: Turn the light on when motion is detected & it's dark
  description: ''
  trigger:
  - entity_id: binary_sensor.tradfri_motion_sensor
    platform: state
    to: 'on'
  action:
  - service: timer.cancel
    entity_id: timer.timer_lamp
  - entity_id: light.bad_2
    service: light.turn_on
- id: '1579034320307'
  alias: Turn off the light in bathroom after 2 mins
  description: ''
  trigger:
  - platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.timer_lamp
  action:
  - entity_id: light.bad_2
    service: light.turn_off
- id: '1579123986302'
  alias: Bathroom light timer
  description: ''
  trigger:
  - entity_id: binary_sensor.tradfri_motion_sensor
    platform: state
    to: 'off'
  condition: []
  action:
  - entity_id: timer.timer_lamp
    service: timer.start

What I would like to include is that the light goes down to 50% when no motion is detected and than to 0% or to 100% again if there was new motion detected.

1 Like

Hi Guys,
I have a small follow up question.

With the normal tradfri hub integration state of the motion sensors is just the battery life…

I would need to use ZHA with a zigbee dongle to get more info (like the state being on/off) right?

I would need to use ZHA with a zigbee dongle to get more info (like the state being on/off) right?

Yes. I am using the CC2531 usb stick for zigbee devices.