How to turn light automation off via Alexa without NabuCasa

What I am trying to accomplish. I have a PIR by the door of my bedroom, and an mmWave sensor on the light fixture. I want to be able to turn the lights on and off automagically after sunset, until sunrise.

The goal is for me to be able to leave the room, and have lights go off right away, then when I return to the room lights go back on, up until I want to go to sleep or watch tv. My go to is Alexa, “turn off the light”.

Alexa does turn off the light, but the automation will turn lights back on shortly after when it detects presence in the room.

I have to add something to my automation to check if lights were turned off by automation, then turn them back on when presence detected, but if lights were turned off “manually” via Alexa, HA app, etc., then lights should remain off even if movement and presence detected.

I set up a boolean input, and my automation turns input to “on” when it turns the light off. I also set an automation to run at 8am to set the boolean back to “on”. What I can’t seem to figure out is how to set the boolean to “off” when I manually turn the lights off.

Look at matterbridge

It allows you to use the Matter protocol to control Home Assistant locally to Alexa

with your suggestion, I would basically be using Alexa to turn the automation/script off, then I would turn off the light?

I now see how the title of my post is very misleading. What I was trying to say is that I have the Alexa integration that doesn’t use NabuCasa. So when I use Alexa to turn on/off a device not sure how it registers it on the log, as it is not a specific users UI turning it off.

Is Alexa turning the light off directly? Can you get it to run an automation? If so, could you create a input_boolean helper to use as a condition prior to the sensor turning the lights on. The idea is the “Alexa automation” will turn the light off and set the boolean to true i.e on and the sensor automation will have a condition that the boolean helper must be false otherwise it won’t turn the light on.

Sorry for the confusion btw

Edit:
Have you used the logbook to check what happens after you ask Alexa to do something?

Nothing to be sorry about, I appreciate any and all input.

I’ve set up all my smart switches via tasmota. Alexa finds these switches on her own. Basically I can turn off Home Assistant, and I can continue to control all my lights (well most) via Alexa.

I sometimes use the HA app on my phone. My wife and her daughter have the same app but they NEVER use it. On the logbook when I turn a light on/off via my HA app it shows the action and my name next to the action. When I use Alexa to turn off the light , it shows the action in the logbook but doesn’t put a name of who did the action. If I use the touch button attached same thing logbook shows the action but with on user next to it.

My guess is that Alexa is talking to the tasmota directly, so when touch button is pressed or Alexa triggers a change, the tasmota updates HA via mqtt. So HA doesn’t really know if Alexa turned off the light or if someone pressed the button.

I do have a helper boolean set up. Automation turns it “on” when lights are turned “off” by the automation. What I am looking for is a way to turn boolean helper “off” when light turned off via Alexa or touch sensor on the wall.

:slight_smile:

You want to add to the existing automation another trigger to turn the helper boolean on when the change is not made by a person i.e. Alexa. (not sure if this is possible in HA)

I also use Tasmota with a couple of Sonoff devices. I wonder if you’ve got Matter enabled in Tasmota and that’s how Alexa is discovering them? I haven’t updated my devices for a while so I don’t know.

I would still consider using Matterbridge instead of the possible Tasmota Matter implementation as Matterbridge interacts with HA directly via its APIs. If only to test if what you want to achieve is possible via Matterbridge and Alexa.

I do plan to learn more about matter, but seems not a one day read. Trying to keep things as simple as possible.

I set up my relays (lights) as Hue Bridge in tasmota. With that Alexa is able to discover them with no HA or even any mqtt setup. Not sure exactly how the tasmota comunicates with Alexa, but I am pretty sure the only way HA talks to Tasmota is via the mqtt server.

I was thinking maybe I could set up a rule on tasmota, to send an mqtt command to turn off the helper boolean, but I end up back in square one. I could set up the mqtt to run when touch button is pressed, but I wouldn’t be able to tell apart when Alexa sends command or when the command comes via mqtt from HA.

So I think I figured something out using two boolean helpers.

1st boolean helper gets turned on when the automation turned “off” the light because of no motion.

2nd boolean turns on/true when the automation to turn off light gets triggered.

This is the flow:

At 8am I run an automation that sets “AutoOff” to on/true.

After sunset, if motion is detected automation checks to see if “AutoOff” is “on” then it turns on the light. (AutoOff means automation turned light off, hence ok for automation to turn light back on)

Once no motion/presence is detected, the “turn off” automation starts. It first sets the 2nd boolean (automation ran) to “on”. It then turns the light off, and finally it sets “autooff” to “on”

Then the magic happens with the last automation that gets triggered EACH time the light is turned off. When light is turned off it checks status of the 2nd boolean “automation ran”. If 2nd boolean is “on”, it just turns the boolean back to “off”. If second boolean is “off” it means light wasn’t turned off by automation, so I set “autoff” to “off”.

With “autoff” boolean set to off, the “turn on light” automation won’t work. Then at 8am next morning, the automation will set the “autooff” back to “on” so the light automations can start again after sunset.

Actually put a bit more thought to it, and changed the 8am automation to run at sunset instead.

At night at some point I will turn the lights off, so the “auto off” will be set to off preventing light automations to run. If I reset “auto off” to “on” at 8am, if during the day I turn on the light then off, “auto off” would be set to off, preventing the light automations to run at night.

By resetting at sunset instead of 8am, “auto off” remains off. I can turn lights on and off manually, and at sunset light automation will start again, until I manually turn off the light.