How to Integrate Amazon Smart Plug with Home Assistant

Amazon Smart Plugs are an excellent addition to automate your home with Alexa. However, if you’re an advanced home automation user using a more robust solution like Home Assistant, you will find their limited usage to the Alexa app very frustrating!

I discovered a solution to get Amazon Smart Plugs accessible in Home Assistant using input booleans and template binary sensors. By pairing a binary sensor from Home Assistant with an Amazon Smart Plug inside of an Alexa Routine, we’re able to control the smart plug from Home Assistant!

I have a lamp by my fireplace that’s plugged into an Amazon Smart Plug that I want to control from Home Assistant:

Create Input Boolean and Template Binary Sensor

Let’s begin by creating the input boolean and the binary sensor in Home Assistant. I’ve chosen to create the input boolean using the Home Assistant UI. Navigate to Configuration -> Helpers then add a new Helper that is a Toggle:

When adding the Toggle, Home Assistant doesn’t give you the option to name the input boolean, so it will create a generic one based on the common name you enter. For my fireplace lamp, it created input_boolean.fireplace_lamp. I prefer it to be a little more descriptive so I modified it after creation to prepend alexa_ha_:

Alternatively, you can add the following code for the input boolean to configuration.yaml:

input_boolean: 
  alexa_ha_fireplace_lamp: 
    name: "Fireplace Lamp"
    icon: "mdi:lamp"

Binary sensors aren’t available in the Home Assistant UI so it must be added to configuration.yaml:

binary_sensor:
  - platform: template
    sensors:
      alexa_ha_fireplace_lamp:
          friendly_name: "Alexa HA - Fireplace Lamp"
          device_class: garage_door
          value_template: "{{ is_state('input_boolean.alexa_ha_fireplace_lamp', 'on') }}"

If you have existing binary sensors, just include everything from the device’s name down.

After adding this, save the confguration.yaml file, run Check Configuration, then if the configuration passed, restart Home Assistant.

What’s Going on Here?

If you’re not familiar with input booleans and binary sensors: an input boolean is a virtual device that has an “on” or “off” value. A binary sensor stores the state of a device and has a device class that represents that state. I’m using the binary sensor as a virtual device to track the state of the Amazon Smart Plug as it changes across Home Assistant and the Alexa App. Together it allows me to track the state of the entity and control it from the UI.

Although binary sensors can have a device class of type plug which makes more sense, I’m using garage_door instead. When I’ve tried using type plug, the binary sensor doesn’t transfer to Alexa properly and is renamed _AccessorySwitch. 🤷🏼‍♂️

Once Home Assistant restarts, the Alexa App sees the input boolean and binary sensor as devices and sends me a push notification that new devices are available. If you don’t see them after restarting Home Assistant, manually sync the entities from Configuration -> Home Assistant Cloud menu.

Sync Entities If Necessary

Rename Amazon Smart Plug in Alexa App

Since I’ve named the input boolean “Fireplace Lamp” (which is the current name of the plug), we’ll need to rename the plug to avoid any confusion for Alexa. I prepend “HA -” to the name to differentiate it enough to not trigger when saying “fireplace lamp” and to remind me of the connection to Home Assistant:

Create Routines in Alexa App

Now we need to create two routines in the Alexa App that include both the Amazon Smart Plug and the binary sensor:

Routine for Turning On The Fireplace Lamp

My completed routine is shown below. Note that the when trigger is the binary sensor opening and the action is to turn on the Amazon Smart Plug and the input boolean. This will keep our device and the Home Assistant UI in sync.

Routine for Turning Off The Fireplace Lamp

My completed routine is shown below. Now the opposite as the example above: the when trigger is the binary sensor closing and the action is to turn off the Amazon Smart Plug and the input boolean. Again, this will keep our device and the Home Assistant UI in sync.

Add Input Boolean to Lovelace UI

Now we’re ready to control the Amazon Smart Plug from Home Assistant! Add the input boolean to Lovelace UI however you’d like. For illustration, I’m adding it to a new entity card named Living Room:

All Done!

I can now turn this device on and off from Home Assistant and by using voice with Alexa. Discovering and documenting this process has been helpful for me to better understand Home Assistant better and finally control all my Amazon Smart Plugs from it! Remember, we’re only going to toggle the input boolean in Home Assistant or in the Alexa App, never the binary sensor! The Alexa App can only control a binary sensor and it also stores the state of the plug.

Feel free to leave a comment below or message me on Twitter if this has been helpful or if you have questions!

25 thoughts on “How to Integrate Amazon Smart Plug with Home Assistant

  1. Joe

    Thanks for writing these up! I’ve used this technique with smartthings with a virtual contact sensor and am now making the transition to HAAS so was happy to see this was possible here too. I created the input boolean and can see it in the Alexa app. When I toggle it in HAAS I can see the contact sensor change from open to close in the Alexa app when viewing the device. I created a routine the same but it is not controlling the plug. If I manually trigger the routine it does turn the Amazon plug on/off. It seems like the routine is not reacting to the state change of the contact sensor/input boolean. Any ideas what else to check/try?

    Reply
  2. Soul

    Thank you!
    I’ve been searching for a few weeks now trying to figure out a good solution to get my Amazon Smart Plug working with HA. Worked flawlessly!

    Reply
      1. Krell

        Can’t get this to work. Like Joe and Manel, everything works EXCEPT toggling the plug from within Home Assistant. I am NOT a noob but I can’t get it to work. Seems like the Alexa doesn’t monitor the state change of the binary sensor. Any idea why this isn’t working?

  3. Manel

    Thanks! I´m starting with HA and this tutorial help me to understand how input_boolen works, but after following your tutorial I´m able to see the state of the plug in HA and turn it on and off from Alexa, but when I press the button in HA the state of the plug does not change, I´m not able to turn off and on the plug from HA. Any idea? again I´m a HA noobie and I´m still trying to understand how things intregrate etc. Thanks for you help.

    Reply
  4. Joe

    I used to have something similar working in SmartThings with a virtual switch/virtual sensor combination device handler. That has stopped working too, so this could be an Amazon side issue not something with HA. Like HA, from the Alexa app it sees the ST virtual contact state change (open/close), but the routes are no longer triggered. I ended up loading the Alexa Media player add-in which can also be used for TTS and to trigger routines. I’ve got it working via NodeRed but you could also do this with a HA automation or script.

    Reply
  5. nathanR

    Cool! I had to change the device class “garage_door” to “door” to make Alexa happy, otherwise she complained.
    It would be cool if you could turn this into a HA Blueprint if you feel inspired…

    Reply
  6. reisertom

    I can see the input sensor as a “garage door” but I am unable to select any smart home device as a trigger in the routine. Alexa app tells me that there are no devices ?!

    Reply
    1. nrutman2017

      I had to change the binary sensor in HA from
      device_class: garage_door
      to
      device_class: door
      After that, Alexa could use it as a trigger.

      Reply
  7. Alejandro

    Hello, I’m stuck creating the routine, i click When this happens, and i get some options, im clicking Smart Home, is this correct? I’m only seeing my Echo Speaker there. I tried changing the class from garage_door to door with no success. Or im i doing something wrong?

    Reply
  8. David Clarke

    Hi
    Great tutorial, works perfectly.
    However if I turn the lamp on or off via voice then the state change does not update the entities card in Hass.
    Is this supposed to happen or am I wishful thinking?
    Thanks

    Reply
  9. Tom OD

    Really appreciated this. Works like a charm. Just started getting into Home Assistant and this was a slight annoyance as I only have the one Amazon Smart Plug that came free with an dEcho Dot a few years ago.

    Reply
  10. Mondo

    So I went through this step by step and when I try to create a routine I have no devices available to choose when trying to set it up. The “When this happens” selection for smart home doesn’t show any devices. I did update the device_class to door as recommended by a previous comment but even this didn’t show any devices under that part of the routine. Anyone else get past that part?

    Reply
  11. Rich

    Thanks to all for this thread and helpful tips.
    However, I’m confused. I have Alexa and HA working seamlessly together, with trial HA subscription. Works by default. Is the point of this thread to explain how to do that with mout the sub? Currently all controls and state changes are in sync and there is nothing for me to do…. sorry if it’s a banal question. I’m guessing you are looking to circumvent the need for an HA sub. Many thanks

    Reply

Leave a Reply to Alejandro Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s