Motion Sensor & Light (plug)

Hello,

I’ve started using Home Assistant just recently, but I have to say it has been a joy all the possibilities it brings to monitoring and automation.
…Well, the same with spending more money on smart devices, because of that.

Anyway.
I’ve been checking posts everywhere, for weeks now, trying to find a solution to what would seem to me quite a simple situation; but alas. I’m not sure if it’s because of code changes, throughout the years, or just my own ineptitude. I could only find solutions (2017-2018-2019) pointing to “boolean”; but my failed attempts didn’t gave much results beyond error notifications and so on…

I put a motion sensor in front of the bedrooms, so it would trigger, On/Off(after some time), a smart plug-floor lamp at a corner of the living room, during the night.
It seemed quite a simple automation, but even before executing it I was wondering how it would differentiate the fact that no one was in the living room, during that time, and those moments where someone was there - and didn’t want the light to go Off.

At the time I thought, in my naivety masked as ingenuity, that I would only have to create a condition, connecting both automation (On/Off), so the “On” automation wouldn’t be triggered if the light (plug) was already On, and so it would also not trigger the “Off” automation after a while. But, well, you can imagine how that didn’t work out.

- id: '1610753048709'
  alias: Motion ON
  description: ''
  trigger:
  - type: motion
    platform: device
    device_id: ca6dc31cd6275a2caa117b92bc270d9a
    entity_id: binary_sensor.motion_sensor
    domain: binary_sensor
  condition:
  - condition: time
    after: '21:00'
    before: 08:00
  - condition: device
    type: is_off
    device_id: 8ba5ced6df1f42572b012e360f44091e
    entity_id: switch.lamp
    domain: switch
  action:
  - type: turn_on
    device_id: 8ba5ced6df1f42572b012e360f44091e
    entity_id: switch.lamp
    domain: switch
  mode: single
- id: '1610753339131'
  alias: Motion OFF
  description: ''
  trigger:
  - type: no_motion
    platform: device
    device_id: ca6dc31cd6275a2caa117b92bc270d9a
    entity_id: binary_sensor.motion_sensor
    domain: binary_sensor
    for:
      hours: 0
      minutes: 0
      seconds: 0
  condition:
  - condition: time
    after: 00:00
    before: 08:00
  action:
  - type: turn_off
    device_id: 8ba5ced6df1f42572b012e360f44091e
    entity_id: switch.lamp
    domain: switch
  mode: single

Hope someone can give me some help, beyond telling me - like my wife - that I should start using other lights if someone is in the living room, at night, as a solution. :roll_eyes:

I see that you have used device platform but you needed to use the state platform. Please try these and let me know.

- id: '1610753048709'
  alias: Motion ON
  description: ''
  trigger:
  - platform: state
    entity_id: binary_sensor.motion_sensor
    from: 'off'
    to: 'on'
  condition:
  - condition: time
    after: '21:00:00'
    before: '08:00:00'
  action:
  - service: switch.turn_on
    data: {}
    entity_id: switch.lamp
  mode: single
- id: '1610753339131'
  alias: Motion OFF
  description: ''
  trigger:
  - platform: state
    entity_id: binary_sensor.motion_sensor
    from: 'on'
    to: 'off'
    for:
      hours: 0
      minutes: 1
      seconds: 0
  condition:
  - condition: time
    after: '00:00:00'
    before: '08:00:00'
  action:
  - service: switch.turn_off
    data: {}
    entity_id: switch.lamp
  mode: single

Oh, nice!

It will still turn off the plug/light, after a while, if the motion sensor goes from “Clear” to “Detected”, then “Clear” again [1min after “off”]; but if no one passes in front of the motion sensor the light stays On.
Not perfect, but quite a huge improvement. Thanks a lot, sheminasalam!

I had put the condition to delay turning off the turn for 1 minutes after the motion detector senor turns off. I did it because the PIR sensor usually works in a complicated manner. It looks for heat signature but not just that it will turn on only if this heat signature moves. Which means that if we stay still in front of PIR sensor it will not detect motion. The 1 minute delay is given to ensure that there is nobody present. If this is not given, when you are not moving, the sensor will trigger off and light will be turned off instantly.

2 Likes