How to trigger Alexa routines from Home Assistant

Can Alexa skills be exposed into HA?
For example I have skylink alarm that is connected to Alexa…would like it to communicate back to HA

I have a similar issue - my binary_sensor is of device_class ‘opening’ and it is shown in the Alexa app. I can see the status change in the Alexa app as well, so it looks like the communication from HA to Alexa works. However, the routines that I created never trigger.The trigger looks like this: when ‘First Amazon Plug opens’. The routine works fine if I trigger it manually. I have another routine with a trigger when ‘First Amazon Plug closes’. That works fine as well.
Is this just a matter of waiting for the routines to be enabled? Or is something else going on?

Have you enabled proactive events in the skill setup?

1 Like

I am using Amazon Alexa Smart Home Skill - Home Assistant (home-assistant.io) which is basically a lambda function running on AWS. Have not seen proactive events as an option, but I will take a look.

On that page you refered, see https://www.home-assistant.io/integrations/alexa.smart_home/#proactive-events

1 Like

yeah, I see it now. I had to enable it, did not have it enabled previously. Did not know it was a thing :slight_smile: Thanks. It works!!

Hi,

So I was able to get this kind of working but am stumped at whats wrong.

I setup an inputboolean switch on lovelace, I have a binary door sensor setup to check the state of the input boolean. Alexa is seeing the status of the sensor as open or closed when I toggle the switch. I have a routine in Alexa to turn a smart plug on/off depending if the state is open or closed. But the routine in Alexa is not triggering the powerbar outlet to turn on/off for some reason.

I have a smart power bar that I cant integrate natively into HA but has an Alexa skill.

EDIT: realized I didn’t have the Alexa report states turned on, in the cloud settings.

Thanks.

does anyone have any extra information on this? i do use haaska… but i removed it all to try this as i’m looking to trigger routines via HA. however, after deleting and starting over multiple times… i’m stuck on unable to link my HA with alexa… any tips?

Update: i have not fixed it yet, but i think i may have figured out the issue is probably because of the beginning of the directions which states “The Alexa Smart Home API requires your Home Assistant instance to be accessible from the internet via HTTPS on port 443 using an SSL/TLS certificate.” I have not set my forwarding to this port which is probably the issue. if someone could inform me of this that’d be great…

Update 2: after reading the documentation further i found that it was the port number that i had to correct in order to link my account.

Can anyone explain what exactly “expose” the sensor to Alexa means?

I have my Echos connected to HA already. It’s syncing my scenes created in HA but that’s it.

I created a binary sensor that detects whether a boolean switch is on:

binary_sensor:
  - platform: template
    sensors:
      door:
        friendly_name: "sensor - trigger for alexa"
        value_template: '{{ is_state("input_boolean.trigger_for_alexa","on") }}'

I was hoping to use that to trigger an Alexa routine but my Echo is not discovering the sensor. I’m knew to HA so maybe I just don’t know how to “expose” things to Alexa properly. I’ve restarted HA and clicked sync entities to Amazon several times.

Any ideas?


Well I figured out what expose means. If any other noobs like me happen across this, you have to open “manage entities” under home assistant cloud to see what’s exposed and what isn’t. As soon as I did that I got a notification on my phone that Alexa discovered a new device.

It shows up in the list of all devices but it doesn’t show up as an option for routine triggers though which is frustrating.

Have you enabled proactive reporting?

1 Like

I did, didn’t make a difference. But I just found out I can trigger routines directly with Alexa Media Player so I’m giving up on the virtual binary sensor for now anyway. Thanks for trying to help!

Another way to trigger an Alexa routine from anything that can do an http request:
https://www.virtualsmarthome.xyz/url_routine_trigger/

Contact sensors and motion sensors aren’t supported in all regions: List of Alexa Interfaces and Supported Languages | Alexa Skills Kit

1 Like

It works perfectly for me.

How did you do that? I would love to know! :slight_smile:

There is a very simple work around for this, I am doing a article on smart home tech for a site from a newbies perspective, ( I am a month into it and just have to wait for a few more items to turn up to get finished up, were I explain how to have simple connection on devices only supported by alexa and even have automations setup with it.

its a dirty way but works, my robot vac for example only works with alexa but I have a home assistant routine to turn it on and send it back if need be.

Once article is live ill post the details here (without linking to article).

1 Like

Followed the process to make a template binary_sensor available to Aleza. In the Alexa app, it does appear in the list of known devices:

However, it does not appear in the list of devices available as a trigger in an Alexa routine. My feeling is that it has been given a type of Other by Alexa and so state values cannot be used in Alexa.

How do I make sure that the Discovery keeps the binary_sensor type?

Took me a while to get his figured out - I finally got it working though! I wanted a virtual toggle switch to trigger a routine in Alexa. Here’s how I did it:

  1. Create a toggle helper. Take note of the entity ID (input_boolean.entity_name)
  2. Enter the following into config.yaml, giving it a name and using your toggle helper entity ID:
template:
  binary_sensor:
    - name: Sensor Name
      device_class: door
      state: >
          {% if is_state('input_boolean.entity_name', 'off') %}
            off
          {% elif is_state('input_boolean.entity_name', 'on') %}
            on
          {% endif %}
  1. Go to Configuration > Settings > Server Controls and restart your yaml template entities.

  2. If you add these two entities to an entity row on a dashboard, you will see that when you toggle the helper on and off, your “door” sensor will also toggle open and closed.

  3. Expose the sensor to Alexa. Because of the insane number of entities being added to home assistant for each phone, tablet, or whatever that were all being added to Alexa as well… my Manage Entities for Alexa in Home Assistant Cloud is set to hide everything. I have to go in and find the new entity in the Not Exposed Entity List and switch it to Exposed. Once that is done, Alexa immediately discovers it. In Alexa, you can view the sensor entity just like in the picture above, but instead of Type: Other, it will say Type: Contact sensor. Routines can only be triggered by certain types of binary sensors, and a door contact sensor is one of them.

With that done, you can now set up an Alexa routine using your sensor switching states as a trigger.

In Home Assistant, I toggle the helper entity ON in a script, which automatically flips the sensor to OPEN, which triggers the Alexa routine. My script also toggles the helper OFF, flipping the sensor to CLOSED, which does nothing in Alexa, but it is now ready for then next time the routine needs to be run.

If you want, you can also expose the helper entity to Alexa, then trigger the routine by telling Alexa to turn on the helper entity.

2 Likes

Found this thread because I’m trying to do the same exact thing. My code is the same as yours, but the sensor is never showing up in Alexa as a trigger for routines. Do you use the Nabu Casa Alexa component (I do)? Or something else?

I’ve enabled/disabled a sensor that Alexa sees and that trigger becomes unavailable from Alexa as expected. So I know that entities are being sent to Alexa.

Yes, I’m using Naba Casa.

In Alexa, when I go to my list of devices, this is how it appears in the list. Trigger_K1 is my binary sensor created with the yaml code. Trigger_K2 is still the helper entity - I haven’t dealt with making that binary sensor yet. You can see that Alexa gave the binary sensor a different icon (even though the helper icon is the one that looks like the trigger icon in routines).

Going into Trigger_K1 settings, you can see that it’s entity ID in HA shows it as a binary_sensor, and that the type is a Contact sensor. Before adding “device_class: door” in yaml, its type was labeled Other in Alexa and it did not show up as an option for a routine trigger. I’m pretty sure it had the other icon, too.

Finally, this is in Alexa routines - my options after selecting Smart Home as my routine trigger - Trigger_K1 is there. I did have to force quit the Alexa app on my phone and reopen it before it showed up, but I wasn’t sure if it would’ve shown up anyway if I was more patient. Give that a try, though.

1 Like