Motion lights with presence

I’m new here. I’ve been reading lots, but obviously lots more to read. Seeing lots of posts where people say “I’m new here” and proceed to ask a question that shows they’ve read nothing. I hope this doesn’t turn out to be yet another!

I’m using this automation with a Zooz ZSE70 sensor and ZEN71 switch. I’m generally happy with it. I’ve even managed to add a condition so that it only triggers after sunset/before sunrise.

My only issue with it is that the “motion off” trigger turns off the light regardless of how it was turned on. I’d also like to be able to turn the light on manually and have it stay on indefinitely.

After some reading I decided the way to achieve this was to use a template to make a copy of my switch that I could add a custom field to called, say, turned_on_by_automation. I’d then break this in to two automations - an “on” an “off”. The “on” automation would set turned_on_by_automation to True and my “off” automation would test for turned_on_by_automation=True before turning the light off and resetting it back to False.

When I tried to implement this plan it became clear I really didn’t understand templates and I was probably on the wrong path.

Is my plan workable if I can figure out how to implement it? Is there some other way I can store this turned_on_by_automation state?

1 Like

Basically it is very hard to archive this with pir sensor. This is because pir sensor just have two states - motion detected, motion clear. It is great solution for stairs but it is not so good for dinning room or kitchen.
You can use ie. timer helper in automatons to keep the light on but this only work if sensor change state from off to on while automation is running.
The only solution to this problem, imho, is to use presence detection sensor.
Then you can turn on off light based on presence add illuminance to it etc.

I’m not seeing how this would help. I turn the light on manually because I want it on, I then leave the room so my presence is no longer detected and the automation would turn the light off?? This is not what I want - I want it to stay on forever if manually turned on.

If you insist so much you can check history of your switch and see from there can you determine was switch manually turned on/off or not. Based on that you can maybe do something about it.
Or just buy presence sensor.

You have not said that a presence sensor will actually do what I want, yet you seem adamant that I should buy one - sorry, but this confuses me.

I don’t think a presence sensor is appropriate for this situation - the light is outside on my front porch and so is the motion sensor. I want the light to turn on if a car comes into my driveway, an animal runs across my porch etc.

You could explain it. I thought that you are talking about indoor situations.

I think I have this figured out. I found enkama/hass-variables and use it to set a binary sensor that I can test to determine if the light had been turned on by automation. I now have two automations and initial tests look promising. Any feedback appreciated.

alias: Front Porch Sensor Light - on
description: Turn on front porch light if motion detected
triggers:
  - entity_id: binary_sensor.node_2_motion_detection
    to: "on"
    trigger: state
conditions:
  - condition: sun
    before: sunrise
    after: sunset
  - condition: state
    entity_id: light.front_porch_light_switch
    state: "off"
actions:
  - target:
      entity_id: light.front_porch_light_switch
    action: light.turn_on
    data: {}
  - target:
      entity_id: binary_sensor.bsw01
    data:
      value: "true"
    action: variable.update_binary_sensor
mode: single

alias: Front Porch Sensor Light - off
description: >-
  Turn off front porch light if no motion detected and it was turned on by
  automation
triggers:
  - entity_id: binary_sensor.node_2_motion_detection
    to: "off"
    for:
      minutes: 2
    trigger: state
conditions:
  - condition: sun
    before: sunrise
    after: sunset
  - condition: state
    entity_id: light.front_porch_light_switch
    state: "on"
  - condition: state
    entity_id: binary_sensor.bsw01
    state: "on"
actions:
  - target:
      entity_id: light.front_porch_light_switch
    action: light.turn_off
    data: {}
  - target:
      entity_id: binary_sensor.bsw01
    data:
      value: "false"
    action: variable.update_binary_sensor
mode: single

Edit: while re-reading my post to check for typos I found my first update - I’m going to remove the “sun” condition from the “off” automation. It’s not needed and there’s a very small chance the “on” automation will be triggered 1 minute before sunrise and the light would then stay on all day.

This automation is awesome. It works even if you have a smart switch in the room.

Simple and efficient!

You don’t even need the helper used in the condition.

Since you use 2 automations, why not programmatically en-/dis-able the motion automation, when using the switch,

Probably because you will have to make template sensor that will determine did you turn light switch manually on/off. It is probably possible but not that easy to do.

It’s taken me a while to get my head around what you might be suggesting here and once I figured it out I realised that @ddaniel is replying to your suggestion and he’s right.

My whole setup, for this scenario, is one simple smart switch (Zooz ZEN71), one motion sensor (Zooz ZSE70) and one dumb exterior flood light. If I en/disable the automation when the switch is used I can’t, easily, determine if the switch was used physically, manually through the Home Assistant app or automatically through this automation. As far as I can see the same on/off state change happens in each of these situations.

I didn’t take that into consideration…it was not part of the original request.
But ofc, you are right :wink: