Automation: ‘turn_off’ action not triggering from motion sensor off state

Hi everyone,

I’m having trouble with a YAML automation that’s supposed to turn off the lights one minute after my motion sensor goes to the ‘off’ state, but the ‘turn_off’ service isn’t triggering reliably.

Here’s my setup:

  • I use a binary_sensor.motion_11_occupancy for triggering.
  • My automation works for turning on the light when motion is detected, but the turn_off part does not activate after the motion sensor goes ‘off’ for one minute.
  • My trigger is set with a for: condition to delay, and actions use templating based on trigger.id.

Here is the automation:

trigger:
  - platform: state
    entity_id: binary_sensor.motion_11_occupancy
    to: "on"
    id: "on"
  - platform: state
    entity_id: binary_sensor.motion_11_occupancy
    to: "off"
    for:
      hours: 0
      minutes: 1
      seconds: 0
    id: "off"

action:
  - service: "light.turn_{{ trigger.id }}"
    target:
      area_id: trastero
    data: {}

What could prevent the turn_off action from running after the sensor has been ‘off’ for 1 minute?
Are there common issues with for: delays, triggers, or templating in the service field that I should check?

Thanks for any insight!

Hello Daniel Rodríguez Rivero,

Well on the surface it should work, at least I don’t see the issue.
I usually address light groups or individual entities though, not areas so I could be wrong. You could also make a label for those lights instead of area and I know that works.

It is the legacy syntax, so I would update that and see if it works then.
Action to actions, service to action, trigger to triggers, platform to trigger.

Thanks for your answer

You mean that ro convert it to the new syntax I should do that mapping?

Probably not required, but I would. It’s how the UI will be writing stuff for you now. and it’s easier to get help. (I had to convert that in my head). So not required, but I would try it and see if anything changes.

Actually doing that conversion made it work.
Thank you

1 Like