Alexa intents, scripts & HA - tying it all together?

I’ve been trying to figure out a way to get alexa to control the operation of my garage door.

I’m so new at this that I’m really having a hard time wrapping my head around the sequence of steps to get this working.

I keep looking at examples but nothing seems to be registering with me.

These are the steps I want to have happen:

I want to tell Alexa to close my garage door - “Alexa, close the garage door”

Then I want to HA to test the condition of the garage door position switch

If the garage door is closed I want Alexa to say “the garage door is already closed” and end the script.

If it’s open I want to send the signal to the garage door control switch to activate to close the door and for Alexa to just acknowledge the command - “OK, closing the garage door” - or some such thing.

I have a lot of the bits of what I need to do figured out (I think!) but i can’t figure out how to combine them all together in a coherent script that i can run.

I have emulated_hue enabled and Alexa can already control my lights so I know Alexa works. I can operate the garage door control switch and see the state of the garage door position sensor in HA. I have already programmed an automation to turn the garage door operating switch off 2 seconds after HA detects the switch is on to simulate a momentary pushbutton.

Can anyone give me a nudge (or hopefully a big shove) in the right direction to be able to put it all together?

1 Like

You will have to write a custom intent to include the logic. See examples here.

Ok so i gave it a shot

but the response i got from the Amazon Developer Console test wasn’t what I wanted.

Here is the intent code on the ADC:

{
  "intents": [
    {
      "intent": "CloseNorthGarageDoorIntent"
    },
    {
      "intent": "OpenNorthGarageDoorIntent"
    }
  ]
}

Sample utterances:

CloseNorthGarageDoorIntent close the alley garage door
CloseNorthGarageDoorIntent lower the alley garage door

OpenNorthGarageDoorIntent open the alley garage door
OpenNorthGarageDoorIntent raise the alley garage door
OpenNorthGarageDoorIntent lift the alley garage door

Here is my Alexa code in HA:

CloseNorthGarageDoorIntent:
    action_template: >
      {%- if is_state("binary_sensor.garage_door_north_position_sensor", "on") -%}
        -service: switch.turn_on
         entity_id: switch.garage_door_north_operator_switch
        -speech:
           type: plaintext
           text: >-
           OK, closing the alley garage door
      {%- else -%}
        speech:
          type: plaintext
          text: >-
            The alley garage door is already closed.
      {%- endif %}
   
  OpenNorthGarageDoorIntent:
    action_template: >
      {%- if is_state("binary_sensor.garage_door_north_position_sensor", "off") -%}
        - service: switch.turn_on
          entity_id: switch.garage_door_north_operator_switch
        -speech:
           type: plaintext
           text: >-
             OK, opening the alley garage door
      {%- else -%}
        speech:
          type: plaintext
          text: >-
            The alley garage door is already open.
      {%- endif %}  

When I do a config check it says it’s valid.

When i test the code (with “alexa ask automation to open the alley garage door”), I get this in the service request box:

{
  "session": {
    "sessionId": "SessionId.e5c29ac1-f034-4efd-80f4-baa4515c08f9",
    "application": {
      "applicationId": "amzn1.ask.skill.d6bbaa24-1ca7-47ca-b649-c29a0c99181b"
    },
    "attributes": {},
    "user": {
      "userId": "amzn1.ask.account.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    },
    "new": false
  },
  "request": {
    "type": "IntentRequest",
    "requestId": "EdwRequestId.0616b88d-3b07-4ba1-a822-f9ef9e238d55",
    "locale": "en-US",
    "timestamp": "2017-07-30T05:45:52Z",
    "intent": {
      "name": "OpenNorthGarageDoorIntent",
      "slots": {}
    }
  },
  "version": "1.0"
}

and in the service response I get:

{
  "version": "1.0",
  "response": {
    "speechletResponse": {
      "shouldEndSession": true
    }
  },
  "sessionAttributes": {}
}

Does anybody see anything i need to fix?

I tried something else just to see if it works at all

i modified my HA intent configuration to this:

    CloseNorthGarageDoorIntent:
    #    action_template: >-
    #      {%- if is_state("binary_sensor.garage_door_north_position_sensor", "on") -%}
        action:
          service: switch.turn_on
          entity_id: switch.garage_door_north_operator_switch
        speech:
          type: plaintext
          text: OK, closing the alley garage door
    #      {%- else -%}
    #    speech:
    #      type: plaintext
    #      text: The alley garage door is already closed.
    #      {%- endif %}
           
      OpenNorthGarageDoorIntent:
    #    action_template: >-
    #      {%- if is_state("binary_sensor.garage_door_north_position_sensor", "off") -%}
        action:
          service: switch.turn_on
          entity_id: switch.garage_door_north_operator_switch
        speech:
          type: plaintext
          text: >-
            OK, opening the alley garage door
    #      {%- else -%}
    #        speech:
    #          type: plaintext
    #          text: >-
    #            The alley garage door is already open.
    #      {%- endif %}

Now the action and speech works.

but it won’t test for the state of the garage door.

I really need help with the syntax of the if-then-else statements in the action template.

I’ve tried all the different iterations of the indentations as i can think of but nothing works.

or do i need some higher level template that includes the action and speech after testing for the GD status?

Your if-loop seems incorrect. Look at my api.ai code here. It is not updated to intent_script yet, but it should give you an idea.

Thanks for your help but alas it wasn’t able to work.

The only way I could get the intent to test for the status of the garage door was to move the conditional action statements into two separate scripts. My impression is that conditional actions aren’t allowed in an intent.

For anyone who is interested this is what i ultimately did to get it to work:

In alexa.yaml:

CloseNorthGarageDoorIntent:
  speech:
    type: plaintext
    text: >-
      {%- if is_state("binary_sensor.garage_door_north_position_sensor", "on") -%}
        OK, closing the alley garage door
      {%- else -%}
        The alley garage door is already closed
      {%- endif %}
  action:
    - service: script.turn_on
      entity_id: script.close_gdn
      
OpenNorthGarageDoorIntent:
  speech:
    type: plaintext
    text: >-
      {%- if is_state("binary_sensor.garage_door_north_position_sensor", "off") -%}
        OK, opening the alley garage door
      {%- else -%}
        The alley garage door is already open
      {%- endif %} 
  action:
    - service: script.turn_on
      entity_id: script.open_gdn

Then in scripts.yaml:

 close_gdn:
   alias: can only close garage door if open
   sequence:
     - condition: state
       entity_id: binary_sensor.garage_door_north_position_sensor
       state: 'on'
     - service: switch.turn_on
       entity_id: switch.garage_door_north_operator_switch
  
  open_gdn:
    alias: can only open garage door if closed
    sequence:
      - condition: state
        entity_id: binary_sensor.garage_door_north_position_sensor
        state: 'off'
      - service: switch.turn_on
        entity_id: switch.garage_door_north_operator_switch

I could probably combine the two scripts into one with an if-then statement but this works for now. Maybe I’ll play around with that some more later.

1 Like

You don’t need two intents of scripts. I created an intent for the same purpose here. Just create a slot OpenClose on Alexa with values Open and Close and it should work.

Having said that, I would just use emulated_hue in this case. Instead of saying “Alexa, ask Home Assistant to open garage door” with the intent, I just say “Alexa, turn on garage door” with emulated_hue.

Today I deployed haaska which, along with garage doors configured as cover devices, works very naturally with no weird invocations required. You don’t get verbal feedback if it’s already closed, but the language is natural and you can group doors if you have more than one. For mine, I can say “Alexa, close the garage doors” and it will close one or both if either are open.

@arsaboo

I already thought of using emulated_hue but that would to just “un-smartly” operate the garage door in whatever condition it is in with no testing of the present state. It probably really isn’t a big deal to do it that way but I kind of like to play around and (over-) complicate things. :smile: It seems a little more natural to tell it to “close the garage door” instead of telling it to “turn on the garage door”. It does suck a little that you have to throw the extra invocation in there, tho.

I’ll also have to look at your example and play with the slots to see if I can get it to work that way.

@luma

I haven’t attempted installing haaska yet.

My garage door opener control isn’t a device that is pre-defined as a cover device. It’s just a simple zwave dry contact relay (switch) that simulates a button press on my older style garage door opener. I tried to get an official go-control zwave garage door opener to work but I could never get the “cover” component to work with all of the patches required. I eventually just gave up on that, returned it and bought a dry contact relay and a tilt sensor. Both together were quite a bit cheaper than the gocontrol and way easier to get working!

Can i ask what is the benefit of haaska? What can you do with it that you can’t otherwise?

Haaska is more capable, but is little more involved. Other than making things more natural and working outside the box (after you have installed it), I have not really found anything that I cannot accomplish with emulated_hue and intent_script. I am a big believer of keeping things simple :slight_smile:

Simple is better as long as I get it to do what I really want it to. Unfortunately, sometimes those goals are mutually exclusive. :smirk:

And looking at the example you posted above I think that is pretty much exactly what I want to do!

Thanks!

What does the “card” entry do?

In regards to my garage door - I’m also using an off-the-shelf tilt sensor coupled with a hacked-up $5 sonoff device to trigger the button for each door by way of a relay. With careful use of data_templates I now have a pair of cover devices that work as I expect in that they’ll open when told to open, close when told to close, and stay closed when told to close if they’re already closed. Total cost was ~ $25 per door.

The benefit of haaska is native smart home control language with no unnatural syntax or invocation required using the new Alexa Smart Home Skills API. While I can remember to say “turn on the garage door”, my family probably won’t because that’s not at all natural. Alexa now supports far better syntax and it doesn’t require manually invoking a specific skill (meaning, you don’t have to say “Alexa, tell Home Assistant to open the garage door”). Instead, I just say “Alexa close the garage doors” and the doors do what they’re told. This is family friendly and doesn’t require explanation or remembering any unnatural syntax. Finally, you can also query state with commands like “Alexa, is the front door locked?” and it will respond as you’d expect.

The setup of haaska is complicated largely due to out-of-date instructions, but it also doesn’t require you running any additional scripts or anything in your own Haas installation. You deploy the AWS skill and Lambda code in AWS so everything runs there. This way you don’t run into problems with hass updates and it works well with things like hass.io (so long as the API to hass doesn’t change).

edit: here is my configuration for the covers, and here is my Arduino sketch for the hacked-up Sonoff devices.

@luma

Wow! Thanks for that.

That’s basically my set up but my switch is a (more expensive) zwave switch. The tilt sensor is exactly the one I have.

I guess I now have some decisions to make on which way to go on this.

Playing around with this fun but I don’t know enough to really get the most out of it. There are too many “unknown unknowns” for me. Is there a good repository of knowledge on home assistant covering what all of the component/options/keys/possible values are? I feel that is probably the one big thing that is most lacking in this project. The documentation is OK but it just seems to scratch the surface of what is possible.

1 Like

@luma

You mention that the instructions for setting up haaska are out of date.

Do you have a link to a recent/good set of instructions?

are the instructions @ BRUH automation good?

I feel like it’s going to be a while before a canonical source of knowledge like that exists, simply due to the velocity at which this project is moving. My best recommendation would be to jump on Discord and ask the folks in #general if you have any questions - the community around this project is simply unbeatable and everyone is ready to help.

I kinda-followed the directions from the haaska github and fumbled my way through with some Google searches as I wasn’t in a position to be watching Youtube videos (not that I would be screwing around with my Hass setup while at work of course). If you’re familiar with AWS it might be a little more straightforward, but the trouble with AWS (and Azure for that matter) is that constant changes are being made to the management interface which makes creating accurate documentation difficult and time-limited. I’d say run through the BRUH video and if you run into trouble, ask here or in Discord and we can try and help you along.

One thing to note: AWS is a pay service and requires a credit card, but the pieces being deployed here will fall within the “1 million hits free” tier on Lambda so there should be no charge for normal, personal use.

@luma I am also using a Monoprice Tilt sensor with a z-wave relay and have combined them using a cover template and it works very well.

@finity Glad you found it useful

1 Like

The card entry shows the card in the Alexa app.

I had the exact same output last weekend on Alexa development site and had to make these changes with HA 50.1. You are very close to getting Alexa intents workings and I recommend getting it to work and also installing haaska. I suggest getting the example to work and then modifiy it your needs.

I use Alexa intents to say

“Alexa, tell me the location of John”
“Alexa, tell me the status of the front door”
“Alexa, tell me the status of everything on”

I use haaska for

“Alexa, open the garage”
“Alexa, open the lock”
“Alexa, turn off the fireplace”

I eventually got alexa intents to work correctly using the examples provided by @luma with my needed mods.

And now I just got Haaska working today and everything seems to be discoverable. I won’t be able to test it with voice till later when I get home.

I used the github repo files and only modified the config.json file for the IP & password, and the makefile for the “pip” install line to use pip3.

I mostly used the video from @bruhautomation with a little bit of the readme file from github thrown in. It was a little challenging figuring out the changes needed. I had to delete everything (except the logon information) and start over once but in the end, I’m pretty sure it works.

I had to go through all my stuff and hide things that didn’t make sense from haaska and then re-discover everything.

As of now i have the alexa component disabled. I might put it back if I see the need to use it for anything else. I do like the idea of not having to use the extra invocation words in haaska.

I have a write up of what I did if anyone is interested.

1 Like