A way of doing IF statements on Alexa?

Hi all,

My electric gate - it only has a push button - it doesn’t know the state, it’s just a toggle.

For years - we’ve just had a “MOVE THE GATE” command for alexa, but i’ve now added a z-wave sensor so we know if the gate is open or closed.

It still just runs my toggle gate script, but now it knows if the gate is open or closed.

I would like to think of a way to get alexa to reply “Gate is already closed” if the “Close Gate” routine is run

Alexa routines do not have any IF ELSE logic, so can anyone think of how I could do this??

Thank you!

You should be able to use something like this in your automation to have it announce to a 1 or more devices.

  target: media_player.Alexa_Device
  message: The gate is already closed.
  data:
    type: announce
    method: speak
action: notify.alexa_media
1 Like

I’ve looked into it after your message - and there doesn’t seem to be a reliable way to know which device was used to ask the request…

So if I say “Open the gate” to the kitchen echo.

Home assistant doesn’t know which Alexa device ran the script (or scene in Alexa)

There’s no way to only reply to the kitchen echo.

It’s so ridiculous that Alexa routines have basically not advanced in the last 5 years.

Yeah, unfortunately the core Alexa Devices integration doesn’t allow it at this time, but the custom Alexa Media Player integration can. While it’s been pretty reliable for me for the last couple months, historically this feature is one that Amazon has removed or changed frequently in the API used by these integrations. So, I don’t know that I would recommend switching integrations just for a feature that may or may not be reliable.

I’m pretty sure that the Alexa Devices integration and the Alexa Media Player integration both use the same API. So if the AMP integration breaks then so will the AD integration.

the benefit of using the AMP integration is that it will potentially get fixed sooner than the AD integration since the latter is tied to the HA release cycle and the former isn’t. It gets updated as soon as the devs can figure out a fix.