How to control Amazon smart plugs from Home Assistant (via emulated_hue and alexa media player)

Hi all,

New to HA… I have a bunch of amazon smart plugs that I want to control from Home Assistant app. I am using the emulated_hue approach, and have created an input_boolean/binary_sensor device that was properly discovered by Alexa app and working like a virtual light switch.

However, I need to use this “light switch” to trigger the actual on/off of the actual amazon smart plug. But when I go to create a Routine in Alexa app, the device does not appear under “Smart Home” at the “When this happens” step. I have tried different “device_class” in my configuration.yaml setup, but none of them worked.

In fact, in the Alexa app, I can’t seem to trigger the routine on any smart plugs (other than my Ring doorbell).

Am I missing something obvious here?

Has anyone recently used emulated_hue to control Amazon smart plug successfully?

Below is my emulated_hue and input_boolean sections in the configuration.yaml:

emulated_hue:
  host_ip: 192.168.X.XXX
  listen_port: 80
  expose_by_default: true
  exposed_domains:
    - light
    - switch
    - input_boolean

input_boolean:
  alexa_ha_lr_light:
    name: "LR light"

binary_sensor:
    platform: template
    sensors:
      alexa_ha_lr_light:
          friendly_name: "Alexa HA - LR Light"
          device_class: garage_door
          value_template: "{{ is_state('input_boolean.alexa_ha_lr_light', 'on') }}"

I am running HA in docker on a raspberry pi 3b+.

Thank you so much!

4 Likes

Well, thanks to various posts from this community, I finally figured out how to control Amazon smart plugs from Home Assistant (without going through nabu casa). I’m using the Alexa Media Player (downloaded from HACS) to trigger the routines in Alexa, in conjunction with emulated_hue to maintain the states between Alexa and HA.

Here’s my setup (in hopes that it’ll help some newbie like me with the same predicament):

  1. Create an emulated_hue input_boolean entity which is exposed to Alexa. Add these in HA’s configuration.yaml:
emulated_hue:
  host_ip: 192.168.X.XX
  listen_port: 80
  expose_by_default: false
  exposed_domains:
    - input_boolean
  entities:
    input_boolean.alexa_ha_lr_light:
      hidden: false

input_boolean:
  alexa_ha_lr_light:
    name: "LR light"
  • Restart HA.
  1. Then in Alexa app, add the above “LR light” (Living Room light) as a device:
  • Devices → “+” (add sign) → Add Device → Other → Discover Devices
  • it should say “1 light found and connected”
  • In HA Dashboard, Edit Dashboard → Add Card → search by entity “LR light”, and add the suggested card
  • whenever I toggle HA’s “LR light”, Alexa’s “LR light” will also toggle, and vice versa
  1. Download and set up Alexa Media Player via HACS

  2. In HA, create a pair of automations so that whenever the input_boolean “LR light” is toggled on/off, it will send a “voice” command to Alexa. I used the HA GUI/visual editor to set the automation for turning the light on as follows:

  • Name: HA to Alexa LR light ON
  • Mode: Single
  • Trigger Type: State
  • Entity: LR light
  • To: on
  • Action type: Play media
  • Select media player: (your echo dot device set up in step 3)
  • Media content ID: HA is awesome LR light ON
  • Media content type: routine

(The phrase “HA is awesome LR light ON” can be changed to whatever you want but it needs to be consistent with the routine programmed in Alexa app.)

The corresponding automations.yaml (for ON) looks like this:

- id: 'XXXXXXXXXXXXX'
  alias: HA to Alexa LR light ON
  description: ''
  trigger:
  - platform: state
    entity_id:
    - input_boolean.alexa_ha_lr_light
    to: 'on'
  condition: []
  action:
  - service: media_player.play_media
    target:
      entity_id: media_player.(echo-dot-device-name)
    data:
      media_content_id: HA is awesome LR light ON
      media_content_type: routine
    metadata: {}
  mode: single
  • Duplicate the above automation, but this time change ON to OFF.
  1. In Alexa app, create a pair of routines to respond to the above “voice commands” and trigger the actual amazon smart plug:
  • Routines → “+”
  • Enter routine name: HA Alexa LR light ON (…or whatever you fancy)
  • When this happens: select “Voice” → enter “HA is awesome LR light ON” (this must be the same phrase as programmed in the HA automations above)
  • Add action: Smart Home → All Devices → Plug for LR light (this is the actual physical amazon smart plug device, assuming it is already added to Alexa) → select “On”
  • Save

– Then do another routine, but this time for the OFF trigger.

That should do it. So when HA toggles the input_boolean “LR light”, Alexa also “sees” the same state via emulated_hue. At the same time, HA’s automation triggers the Alexa Media Player to send a “voice” command to Alexa which in turn triggers the actual device (amazon smart plug in this case) to turn on/off. And vice versa - when Alexa app toggles the “LR light” device (don’t toggle the actual plug), HA sees the same state and triggers the automation to then trigger Alexa to turn on/off the actual device. The caveat is that when the plug is turned on/off via the physical button on the plug, then its state is not sync’d to “LR light”, but that’s a caveat I think I can live with.

Cheers!

6 Likes

Just saw that in my Alexa app (version 2.2.469668.0, Dec 1, 2022), I can trigger routines based on the Amazon smart devices (but still cannot trigger on HA devices exposed to Alexa). This means that I can set a pair of routines to trigger on the states of the actual plug to control the HA virtual switches. (In other words this is for the Alexa to HA direction. )

In Alexa app, add routine:

“When this happens”: “Plug for LR light” → Turned On
“Add action”: LR light → On

Add another routine for the “Off” states.

This means that if I turn on/off the button on the actual amazon smart plug, the state of “LR light” in Alexa will be updated via the triggered routine. And because the Alexa’s “LR light” is an “emulated_hue” lightbulb (that HA exposes to Alexa), its state will in turn be reflected in HA’s “LR light” state.

2 Likes

I have 2.2.490414.0 but still don’t have the capability to use all Alexa devices but only some (very few for instance) and none smart plugs.

Could be related to region (Italy) with different settings??

I’m not really sure about the availability of the smart devices as triggers in the Alexa routines – could be regional… They were not available to me in the US until recent version of the app.

Hassiopi this worked amazingly for me - thanks! I can also confirm I don’t yet see the ability to use smart devices as triggers of routines…

One quick question that maybe is obvious - are you able to modify Home Assistant to actually treat the input boolean as a device? Or specifically as a light? It would be great if it looked like a light with the proper icon etc. in my dashboard.

Glad it is working for you!

I’m not sure exactly what you mean by Home Assistant treating the input boolean as a device / light…

If you are asking about adding it to the dashboard, on your HA main dashboard interface, go to “Edit Dashboard” (click 3 dots at upper right corner), → “+ ADD CARD” (bottom right), → search “BY ENTITY”, type “LR light” (this should automatically list everything with “LR light”) → select the checkbox next to the “input_boolean.alexa_ha_lr_light”, → “CONTINUE” → “ADD TO DASHBOARD”.

If you referring to the icon on the dashboard, you can change icon with the extra line below when setting up the input_boolean in the HA configuration.yaml:

input_boolean:
  alexa_ha_lr_light:
    name: "LR light"
    icon: "mdi:lightbulb"

Alternatively, you can also go to edit dashboard and choose the icon for the LR light entity from added card.

FYI: I found this blog post highlighting another way to do this. I think it would be slightly faster / more reliable because it’s not issuing voice commands to Alexa via a routine.

1 Like

Yes, that’s the blog post that I found and got started with. However, that blog post assumes subscription to the Home Assistant Cloud “Nabu Casa” (see the first comment posted in the blog). Without the subscription, the emulated_hue devices exposed to Alexa do not show up as triggers when I try to set up the routines in Alexa. The “voice commands” method mentioned in this thread is a way to work around this issue (without any need to subscribe to HA cloud service).

2 Likes

Just saw these

Love to see if I can get these on HA

worked like a charm…you ROCK DUDE!!! Thank you so much!

For what it is worth, I created another set of Alexa automations to reverse sync the physical plug state back to HA’s boolean.

Using your example, I have:

  • Routine name “Alexa HA LR Light ON”
  • When: Smart Home/Plug for LR light (physical) → Turned On
  • Action: LR light (HA version) → Power On

And

  • Routine name “Alexa HA LR Light OFF”
  • When: Smart Home/Plug for LR light (physical) → Turned Off
  • Action: LR light (HA version) → Power Off

This basically synchronize the button back to HA.

Seems to work for me.

1 Like

Did you get this working? Because I followed precisely and while triggering the Alexa routines updates HA, HA changes to the boolean do not trigger the routines…

Yeah, works fine for me. Are you sure you have the correct entities exposed to Alexa?

I’m sure it’s probably something that I’m doing, but can’t for the life of me figure out. I’m running my HA in a docker container on my pi and I can’t get Alexa to discover the entity.


emulated_hue:
  host_ip: 172.17.0.4
  listen_port: 80
  expose_by_default: false
  exposed_domains:
    - input_boolean
  entities:
    input_boolean.alexa_ha_lr_light:
      hidden: false

input_boolean:
  alexa_ha_lr_light:
    name: "LR light"

I’ve tried using the Pi’s IP address, changing expose_by_default to true, and nothing seems to work. Hopefully someone with more expertise than me can help?

Edit to add Alexa app details on iOS Version 2.2.5756230.0

Did you do it with Alexa Media Player?

I can´t use Alexa Media Player. Is there another way to do that?

Is this your whole house ip scheme? If Alexa is on a different ip scheme you won’t be able to communicate.

Try bridging your docker homeassistant to your pi’s ip address if you haven’t already this fixed a ton of issues for me

My IP scheme is 10.x.x.x I’ve tried using the host IP of the Pi, the docker IP and a random address within my subnet. I can get the helper to show within HA, but it doesn’t show within the Alexa App when trying to add it as a device.

I’ve tried with my container in bridged and host modes for the network without success.

HA detected the DLNA devices and my hue bridge out of the box. It’s just the emulated hue not being picked up that’s causing me issues now.