#Light group appears to inadvertently override motion sensors?

1 messages Β· Page 1 of 1 (latest)

sharp stream
#

Hi there. This is my first week using Home Assistant so please be gentle with me. If I am posting in the wrong place or in the wrong format, apologies. I am sure there is an obvious answer to this, but I've been Googling for an hour and I'm about ready to give up and throw my Home Assistant Green off the balcony!!

I have some ThirdReality PIR sensors set up. Each is rigged with two automations: one to turn on the lights in a room once it starts detecting motion, and another to turn off the same lights once it stops detecting motion (with a delay in some cases). For rooms with one light, the action targets the light entity, and for rooms with multiple lights I have created light groups, so the light group is the target entity. The lights themselves are a mix of LIFX and Hue - I have a Sonoff Zigbee hub running the Hue bulbs.

The motion sensor/light automations have all worked perfectly up to now - lights come on when I enter a room, and turn off when I leave it.

So the problem is this:

I have also created a light group called "All The Lights", to toggle everything on or off at once. The problem is that if I toggle the "All the Lights" group to "On", the motion sensors don't turn the lights off afterwards in areas where there is no motion. I think by manually activating the lights, I'm accidentally creating a situation where the "lights off" automations never trigger, because there is no motion to "stop detecting".

So how do I fix this? All automations seem to require a trigger rather than a condition - that is, there is no option to say "If motion isn't currently being detected", only "If motion STOPS being detected". Have I set up my automation in a daft way? Am I misunderstanding how motion sensors work? How do I get this set up so that if I turn on all the lights, the system will just turn off anything in an empty room after the usual delay period has expired?

gaunt mangoBOT
#

To format your text as code, enter three backticks on the first line, press Enter for a new line, paste your code, press Enter again for another new line, and lastly three more backticks.
```yaml
example: here
```
Don't forget you can edit your post rather than repeatedly posting the same thing.

boreal dagger
#

But from the image the automation seems simple and I see no reason why the motion stop will not turn off the Hallway light. Automations have no memory if you donΒ΄t give them any.

But you say "because there is no motion to "stop detecting"". How so? Why would you think there is no motion detection (or stopping) when the light is on? I think if you can explain that, we can explain the PEBCAK πŸ˜„

white herald
#

I think you kind of pointed it out in your last line... you're missing a trigger.

if I turn on all the lights, the system will just turn off anything in an empty room after the usual delay period has expired
Since this scenario doesn't involve motion, a trigger may be that the lights have been on for X minutes. You could have a condition to confirm there's no motion and turn off the lights.

sharp stream
#

@white herald what I want is effectively"if the lights are on for any reason but no motion has been detected for [delay], turn off the lights." At that point I can add override conditions, but I want the above to be the default behaviour."

So I think what you're saying is just set the "off" automation to be "when lights have been on for [delay], and motion detector is not detecting motion, turn off the lights" and leave the motion detector to handle keeping them on if someone actually IS in the room?

Which would look something like "10 minutes after hallway lights come on" for the trigger?

#

Appreciate both of you responding so quickly and helpfully btw ☺️

#

@boreal dagger I very much expect the error to be between my ears and not between my devices 🀣

white herald
#

Close... I think you want two triggers for your turn off behavior. Since the lights may be on for longer than [delay] if there's motion. You'll want one for the case in which there's no motion (i.e. lights on for [delay]) AND one for motion -> no motion.

One additional hint that may (or may not) be helpful. Depending on the overall delay you're looking for (and capabilities of your motion sensor), you may find it useful to template out a new binary_sensor for motion using delay_off (https://www.home-assistant.io/integrations/template/#delay_off). Using that, you can have a separate sensor based on your occupancy sensor, but you can control how long your motion sensor is reporting off, before the template sensor turns to off.

sharp stream
#

Thank you, I'll have a look at that tomorrow (it's nearly midnight here!) I knew Home Assistant would be complicated but I wasn't expecting it to get this messy over a simple motion sensor and light automation!!

boreal dagger
#

Hehe, yeah. It is indeed an error of not explaining (mainly to yourself) what and automation needs to do. An automation isn't doing anything implicit, so if you want something to happen, you have to define when. If you don't know when you want it to happen nobody will, including HA πŸ˜„

So in this case, apparently you want a couple of things things:

  • When motion (=trigger), turn on the light (action)
  • When no motion for x time (trigger), turn off the light (action)
  • When light left on for y time (trigger), and there is no motion (condition), turn off the light (action)

Note the last will only be useful when you have not entered the room at all. Because if you would enter the room during the y time and leave, the second line will already fire.

sharp stream
#

@boreal dagger It's Condition 3 that I'm struggling with.

#

This doesn't do anything at all

#

This is the "on" automation for reference

#

What I really want is "If the motion sensor has been clear for at least 5 seconds, turn off the lights" without needing to check whether or not they are on or how long they have been on for. They should ONLY be on WHILE the motion sensor is detecting motion

#

(unless another condition is true e.g. someone has used the manual light switch or a helper override))

#

But I can't see a way to set up a WHILE loop for an automation

#

Because you need a specific state change trigger

#

Is this something you can do in YAML? Or am I just trying to do something that's logically impossible?

boreal dagger
boreal dagger
sharp stream
#

I've got to the bottom of the issue now - it's the delay on the sensor that was the problem (it takes more than 30 seconds to clear) so the automation was checking the status of the sensor before it reset to "Clear"

boreal dagger
#

The check for lights on for 5 sec is already a weird trigger imho πŸ™‚

sharp stream
#

At least I think that's what it was? Either way, I extended the time to 1 minute instead of 5 seconds and now it works

boreal dagger
#

Why would you want the light on for 5 seconds?

sharp stream
#

That worked fine with a straightfoward on/off automation, but the light didn't tun off if anything OTHER than the automation triggered it

#

So the version I have now does what I want, which is: If the light has come on for ANY REASON, but nobody is in the room after a few seconds, turn it off again.

#

Downside is, due to the long refresh time of the sensor I have to wait a full minute. But I can live with that. The important part is that other automations or actions won't override the light going off unless I specifically add the override into the "lights off" conditions

#

I think if I knew anything at all about how to write commands into YAML I could probably make a more elegant solution. But per my original post I am less than a week into this, and I kinda hoped I would be able to get the hallway lights working smoothly without needing to get too far under the hood... (famous last words!!)

sharp stream
boreal dagger
boreal dagger
boreal dagger
sharp stream
# boreal dagger Yeah, but it's still a PEBCAK, is something else turned it on, when should it tu...

So as one example, the bathroom has no window and is off the hallway. So the trigger for the bathroom light is "if the motion sensor in the hallway detects motion" - that way, the light is on when you enter the bathroom. But the trigger for the bathroom light to turn OFF needs to be "if the light is ON and the bathroom motion sensor hasn't detected motion for X second, or the humidity is above 75%, which it is when someone is showering, or whatever else.

#

So the bathroom light will ALWAYS turn on if someone is in the hallway, but should turn OFF again if nobody actually goes into the bathroom. But because the motion sensor's state never changes in that time, I can't use the change in state to turn the light off - I need to use "light has been on for X seconds AND motion is not currently being detected"

sharp stream
# boreal dagger nope, not as long as the real trouble is discribing what you want to happen when...

And yes, to an extent the "All the Lights" button is an override/fallback; in fact the long-term plan is to add in a condition where if it's toggled on then the motion sensors won't turn any lights off. But I want to be the one who dictates that heirarchy, I don't want automations AUTOMATICALLY overriding others when I didn't tell them to. Fundamentally I want a default state of "the light in this room is off UNLESS certain conditions are met"

#

Not "Once the light is turned on, it stays on unless something changes"

#

@boreal dagger never mind, thought I'd fixed it but I hadn't - now if the light is on for LONGER than 30 seconds to begin with, it won't turn off at all because it's missed the trigger

boreal dagger
#

For the off, if you only do that when motion is off for x it will not always turn it off. Aka, you probably also what to turn it off when it's on for Y but there is no motion. And X and Y are different times. Y need to be big enough so you can reach the bathroom at all

#

And just to be sure, you have seperate sensors for the bathroom and the hall?

boreal dagger
#

But all in all I think you're on the right track. So just make the 3 automations πŸ™‚

sharp stream
boreal dagger
#

Can you please make the three automations and post the yaml?

boreal dagger
#

you can just make them in the UI and copy the yaml

boreal dagger
sharp stream
#

'''alias: Hallway Lights Off
description: ""
triggers:

  • trigger: state
    entity_id:
    • light.hallway_lights
      from: "off"
      to: "on"
      for:
      hours: 0
      minutes: 1
      seconds: 0
      conditions:
  • condition: state
    entity_id: binary_sensor.hallway_motion_sensor
    state: "off"
    actions:
  • action: light.turn_off
    target:
    entity_id: light.hallway_lights
    data:
    transition: 1
    mode: single'''
boreal dagger
#

again:

gaunt mangoBOT
#

To format your text as code, enter three backticks on the first line, press Enter for a new line, paste your code, press Enter again for another new line, and lastly three more backticks.
```yaml
example: here
```
Don't forget you can edit your post rather than repeatedly posting the same thing.

sharp stream
#

Bear with me, what I thought was a backtick was not one

boreal dagger
#

Otherwise the yaml is just not readable

sharp stream
#
description: ""
triggers:
  - trigger: state
    entity_id:
      - light.hallway_lights
    from: "off"
    to: "on"
    for:
      hours: 0
      minutes: 1
      seconds: 0
conditions:
  - condition: state
    entity_id: binary_sensor.hallway_motion_sensor
    state: "off"
actions:
  - action: light.turn_off
    target:
      entity_id: light.hallway_lights
    data:
      transition: 1
mode: single```
boreal dagger
#

Okay, this is for the hallway, but you whre talking about tha bathroom...

sharp stream
#

Have been using the hallway as the test case. I can send you the bathroom version if you want

boreal dagger
#

Because this will perfectly work. If you turn on the light and nobody has been in the hallway, it will turn off. If you have a second automation that will turn it off when someone is in the hall you are ready

#

but in the end you need 2 scenario's to turn off the light

#

not a single

sharp stream
boreal dagger
#

πŸ˜„

#

But I'll need to run to a meeting so will respond a bit less πŸ˜‡

sharp stream
#

Yep, got it. The piece I was missing is that there is no way to do the "turn off" automation all in one, because you need a condition for one that relies on the state change for the other

#

So I can't have "When the motion detector stops detecting motion OR the light has been on for 1 minute" because there isn't a way to ONLY apply the condition of "sensor showing clear" JUST to the second "When", and applying it to the first creates a self-referential loop

#

I think?

#

God I'm slow - REALLY appreciate your frankly saint-like patience

sharp stream
#

Anyway it's working now, thank you so much!!!!!

boreal dagger
#

Almost all you can combine. But it's a bit more complex. So for a newbie I go with seperate automations. Can you post the yaml of all automations? Then I can show how I would combine them.

sharp stream
#
description: ""
triggers:
  - type: motion
    device_id: 6e6f798b50b2ae368e5bcaded2a2e578
    entity_id: 50ba53d458e8600d676d9869f1a4c5ae
    domain: binary_sensor
    trigger: device
conditions: []
actions:
  - action: light.turn_on
    target:
      entity_id: light.hallway_lights
    data:
      color_temp_kelvin: 5946
      brightness_pct: 100
      transition: 1
mode: single```
#
description: ""
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.hallway_motion_sensor
    from: "on"
    to: "off"
conditions: []
actions:
  - action: light.turn_off
    target:
      entity_id: light.hallway_lights
    data:
      transition: 1
mode: single```
#
description: ""
triggers:
  - trigger: state
    entity_id:
      - light.hallway_lights
    from: "off"
    to: "on"
    for:
      hours: 0
      minutes: 1
      seconds: 0
conditions:
  - condition: state
    entity_id: binary_sensor.hallway_motion_sensor
    state: "off"
actions:
  - action: light.turn_off
    target:
      entity_id: light.hallway_lights
    data:
      transition: 1
mode: single```
#

All yours

#
description: ""
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.hallway_motion_sensor
    to: "on"
conditions: []
actions:
  - action: light.turn_on
    target:
      entity_id: light.hallway_lights
    data:
      color_temp_kelvin: 5946
      brightness_pct: 100
      transition: 1
mode: single```
#

Just adjusted the "on" so it targets the entity and I don't get that alphanumeric nonsense

boreal dagger
#

Two general notes:

  • I would always use state triggers instead of device triggers. See the difference between trigger for "Hallway Lights On" and "Hallway Lights Off via Motion Detector"
  • And turning off the light always when no motion is detected is very broad. Personally I would always like an override and I would just not turn on the light to start with here.

But then to the turn off. The condition of the "Hallway Lights Off - Other" does not bite with the trigger of "Hallway Lights Off via Motion Detector". Because when the latter triggers you know the state is "off". So you can combine them to:

alias: Hallway Lights Off
description: ""
triggers:
  - trigger: state
    entity_id:
      - light.hallway_lights
    from: "off"
    to: "on"
    for:
      hours: 0
      minutes: 1
      seconds: 0
  - trigger: state
    entity_id:
      - binary_sensor.hallway_motion_sensor
    from: "on"
    to: "off"
conditions:
  - condition: state
    entity_id: binary_sensor.hallway_motion_sensor
    state: "off"
actions:
  - action: light.turn_off
    target:
      entity_id: light.hallway_lights
    data:
      transition: 1
mode: single
sharp stream
sharp stream
boreal dagger
#

Yeah, after a state trigger you know what the state is. So checking for that state is fine.

It's a bit like when your alarm goes off (=trigger), you also checking if it's time to get out of bed (=condition). You know the time the alarm went off so checking the time will not interfere with getting out of bed (=action). But if you know add another trigger, let's say a car that honks in the street. Now checking the time (condition) after you've been triggered will stop you from getting out in the middle of the night.

You can also add both turning on and off to a single automation. But having separate automations is certainly not wrong! A single automation will need extra complexity so harder for newbies. But now I like to pack all scenarios that are linked into a single automation. That way I have it all in a single place to maintain. But again, having seperate automations is easier to follow and debug most of the time because every chuck is small.