Slightly more complex scene automation with presence sensor in living room

Hi all,

Is my first post and had been playing around with HA for a few weeks.

I came from a VBA background so I know a bit of programming, so I had tried the whole day figuring out how to do the following automation as I am still very new to the library (apologies in advance).

Current Set up:

  1. SNZB-06P presence sensor running with Zigbee2MQTT
  2. I had created a few scenes which turns on various lights in the living room
  3. I had used emulated hue so Alexa can execute the saved scenes via voice command - this feature adds to the complexity of my question; more on that shortly.

What I like to do (I will leave the off part later on as I think I know how to do it)

Triggers

  1. From 5PM to 6AM (this might be wrong, but I need some form of a trigger when someone is already in the room)
    OR
  2. Turn on scene A when the room’s occupancy has just been detected (someone just came into the room)

Conditions

  1. when no scenes are currently switched on - so it doesn’t change to scene A when I already have scene D on
  2. if the room is occupied
  3. Applicable only from 5PM to 6AM

Action:

  1. turn on scene A

My issues:

  1. Is there a way to retrieve the occupancy status via’s sensor’s attribute? like what we can see on the logbook?
  2. I know scenes are stateless, so I know Helpers is a great way to add them as part of condition IF a scene is already on.
    I can imbed this Helper in other automations to switch the Helper’s value to true so it can be part of the condition when it only execute if it’s false (reset to false when things gets turn off).
    However, if any of the scenes were executed by Alexa it will always be false (since I can’t change an Entity’s value via scene. Is there a way on the configuration.yaml file where I can change the helpers value to true? Or can I use automations instead of scenes on the configuration.yaml file so when Alexa calls the command, it will change the helper’s value to true?

I might be going this the wrong way, so I appreciate if anyone can point me to the right direction. I watched a lot of YT and read a lot of posts already so I am just a bit stuck and I am sure is something simple and I might be over thinking things or just not the most logical. Thank you!

Scenes can change the state in an input_boolean. I just tested it a few seconds ago.

A different idea would be a custom binary_sensor for each room or whatever you base your scenes on. Looking at the context of each entities state, there may be a way to figure out whether they were set by a scene or not using this information:

1 Like

thank you, I will have a look at scenes right now!

I haven’t tested it, but I added another automation which acts as a helper automation, where if the presence sensor sense a motion, it will turn a Boolean value to true and set it to false when no motion is detected (caveat to time out),