Virtual switches to alexa

So I am aware its possible to create on/off actions to alexa via boolean commands and AWS and reading into it it does seem very long.

I managed to set up a button in smart things (a button/switch combo) that alexa detects as a open/close object. Then via smart things have it as a button as my vacuum is not supported by HA so this enables it to turn the vacuum on and off at specific times.

Also used this same technique to create a button so living room echo automatically connects to Bluetooth receiver if I push it (handy if you want to get super loud)

Surely there must be a way we can get just a virtual switch/button in HA which would eliminate the need for the smartthings in between.?

Sorry if this is covered already as only other route I could find was the boolean way via aws

1 Like

Richi, your post is a little hard to follow. What I think you are asking is “How can I send button commands from Home Assistant (HA) to Alexa without using a custom AWS skill or SmartThings?”.

There are a few methods to do this. In my opinion, the one that is a good combination of ease-of-use and capability is the Alexa Media Player (AMP) custom integration available in HACS. You can use AMP to trigger built-in sequences, skills, custom routines, or to send the equivalent of a verbal command to Alexa.

Applying this to your situation: Since you want to be able to “turn the vacuum on and off at specific times” you could create a pair of scripts as follows, making sure to substitute in the entity_id of your echo device and whatever phrase you would say to Alexa to start and stop the vacuum.

### scripts.yaml

amp_turn_on_vacuum
  alias: AMP turn on Vacuum
  sequence:
    - service: media_player.play_media
      target:
        entity_id: media_player.living_room_echo
      data:
        media_content_id: Turn on the vacuum
        media_content_type: custom
  mode: single

amp_turn_off_vacuum
  alias: AMP turn on Vacuum
  sequence:
    - service: media_player.play_media
      target:
        entity_id: media_player.living_room_echo
      data:
        media_content_id: Turn off the vacuum
        media_content_type: custom
  mode: single

You could then use those scripts in automations and/or have a button card in HA with actions as follows:

type: button
icon: mdi:robot-vacuum
tap_action:
  action: call-service
  service: script.amp_turn_on_vacuum
  service_data: {}
  target: {}
hold_action:
  action: call-service
  service: script.amp_turn_off_vacuum
  service_data: {}
  target: {}
name: Vacuum Control

You can use the same procedure to handle connecting and/or disconnecting your bluetooth receiver, you would just change the “media_content_id:” in the script(s).

1 Like

Thank you for this you are correct and guessed my confusing someone scatty question.

I will try this as I just had found the boolean way with aws from previous searching. I did do it in the end but via smart things and I wanted to bypass that.

The custom skills, like Haaska or the Amazon Alexa Custom Skill, are really for when you are trying to go the opposite direction… use voice commands with Alexa to access information from or trigger actions in Home Assistant. There are other ways to do that as well such as Emulated Hue, Node-Red with alexa-cake-baked pallette, or with a Home Assistant Cloud subscription from Nabu Casa.

Each method has its own advantages and disadvantages…

the way I had set it up , I basically created a virtual combo switch in smart things (so it was a switch and a contact sensor combined as 1 item) so Alexa picked up the contact sensor via smart things skill as she does not seem to like virtual switches if you wanted to add to a routine etc. then using the switch in home assistant for the automation or button, it kind of simplified it a little as the doing anything with the switch in home assistant changed the contact sensor state for alexa.

its why I asked I thought despite being a simple route it seemed to work out of the box, but it made me wonder is there a way to bypass it all that was all, so ill test your code when I am back home again… thanks again.

You might want to checkout node red and use Alexa Smart Home palette.

The palette can create any virtual device you want in Alexa, and then you can tie those to your home assistant devices through node red. So you can create a sensor in Alexa that opens or closes based on the state of whatever entity you want in Home Assistant.

Looks like you can make a dual switch/contact sensor device as well

Update- just read the other posts- if you just want to trigger a routine in Alexa the Alexa Media Player option by the first poster would be more direct though.

thanks guys for these suggestions I will defo have a play around and work out which works best for me.