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:
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"
- 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
-
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.
Cheers!