[Not working] Automation to turn off a smart plug if no motion detected for 5 minutes

Tags: #<Tag:0x00007f73915a17a0> #<Tag:0x00007f73915a15e8> #<Tag:0x00007f73915a12f0> #<Tag:0x00007f73915a1098>

Hello,

I’ve just started with automation and I’m not able to get this to work -
Switch off a smart plug if no motion is detected for 5 minutes. If the switch is turned on manually, the automation should work again (Meaning if there’s no motion for 5 minutes, switch off the smart plug)

Devices:
Smart Plug - Tuya
Motion Sensor - Aqara Motion Sensor
ZHA

Trigger:
platform: device
type: turned_on
device_id: 41952b506d8c400e82a3f65b100378f4
entity_id: switch.bf57555ad780d86beb4h8c
domain: switch

Condition:
type: is_not_occupied
condition: device
device_id: c202635d1d9544629fa7e2e8afbb565a
entity_id: binary_sensor.lumi_lumi_sensor_motion_aq2_fc011b03_occupancy
domain: binary_sensor
for:
  hours: 0
  minutes: 5
  seconds: 0

Action:
type: turn_off
device_id: 41952b506d8c400e82a3f65b100378f4
entity_id: switch.bf57555ad780d86beb4h8c
domain: switch

I’ve tried to make it work but HA does not execute it. When I manually execute the automation, the switch turns off.

First off all, your indentation is not correct, but that could be the cutting and pasting.

But most important: your logic is not correct. The trigger should be : no motion detected for 5 minutes.
The condition (but not really needed) : the plug is on
Why not really needed : it does not hurt to switch off a plug which is not on.

1 Like

Hey @francisp

Thank you for taking the time to respond. I really appreciate it.
I use the UI to configure the automation, so I basically just copied it here.

I changed it as you suggested, it still won’t trigger. Changed value to 30 secs for testing.

Keep in mind: this automation will only trigger if your motion sensor detected motion, it changed its state to no motion detected, and then 30 seconds passed. If you start in a situation where the motion sensor is in the state ‘no motion detected’, you can wait a lifetime (or until the motion sensor detects motion, and then again no motion) before that automation will trigger.