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:
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):
Create an emulated_hue input_boolean entity which is exposed to Alexa. Add these in HA’s configuration.yaml:
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
Download and set up Alexa Media Player via HACS
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.
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.
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.
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.
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:
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.
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).
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…
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.
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
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.