sweharris / Alexa-Smart-Home-VirtualButtons

This lets you trigger Alexa routines using a HTTP API to press a "virtual button". Can be used, eg, in Home Assistant to get announcements ("Garage Door is Open", "Washing machine has finished") or anything else Alexa can do in a routine!
MIT License
35 stars 5 forks source link

Its not isue. #1

Closed harymk closed 3 years ago

harymk commented 3 years ago

How to add devices

sweharris commented 3 years ago

The "usage" documentation has a section on creating buttons: https://github.com/sweharris/Alexa-Smart-Home-VirtualButtons/blob/main/usage/README.md#createchange-button

harymk commented 3 years ago

Give me an example where am type this

sweharris commented 3 years ago

If you're using a command line with curl then the usage guide provides an example: curl -H "Authorization: $PASS" $URL -d '{comamnd_you_want}'

The install guide also shows how you can create buttons via the command line or via the AWS console: https://github.com/sweharris/Alexa-Smart-Home-VirtualButtons/blob/main/install/README.md#via-the-api-preferred

In that example it was to set one of the "special" buttons, but you can do the same thing for normal buttons; just pick a number under 100 and it'll just work.

harymk commented 3 years ago

C:\Users\Home>curl -H "Authorization: pass" url/default/Smart_Home_Virtual_Buttons -d {"command":"setname","param1":"10", "param2":"Garage Door"} {"Answer:":"Bad JSON passed: invalid character 'c' looking for beginning of object key string"}curl: (3) [globbing] unmatched close brace/bracket in column 19

sweharris commented 3 years ago

I don't know about Windows, but on Linux (which I use) I would surround the JSON with ' characters.

So:

curl -H "Authorization: pass" url/default/Smart_Home_Virtual_Buttons -d '{"command":"setname","param1":"10", "param2":"Garage Door"}'

Without them the spaces in the JSON would split the paramters and so the -d flag wouldn't send the whole string.

harymk commented 3 years ago

Which commant this. Put,post, request

sweharris commented 3 years ago

It's a POST; the -d on curl automatically sets that.

harymk commented 3 years ago

curl -H "Authorization: pass" curl/default/Smart_Home_Virtual_Buttons -d "{\"command\":\"setname\", \"param1\":\"1\", \"param2\":\"Test Button 1\"}"

its worked

sweharris commented 3 years ago

OK good. Your \ quoting inside " maybe the best way to handle it in Windows, dunno. The result is the same as the Unix ' ... ' syntax.

Glad you got it working!

harymk commented 3 years ago

{\"error\":\"\",\"error_description\":\"\",\"access_token\":\"Atza|SECRET_STRING\",\"refresh_token\":\"Atzr|ANOTHER_SECRET_STRING\",\"expires_in\":3600,\"TimeSet\":1620265649}

sweharris commented 3 years ago

What command did you run that caused that error? This looks like the notification secret that's used to tell Alexa when a button has been pressed. I'm not sure what command path you used to get that response.

(I edited your message to remove secret strings)

harymk commented 3 years ago

Linked to alexa skill

harymk commented 3 years ago

100001 in db showing this

sweharris commented 3 years ago

Oh, OK. That's not a problem. That's saying there's no error; error: "", error_description: "", access_token: "secret.."... and so on.

That's a good sign. It means the linking worked correctly.

(EDIT) If you now tell your alexa app to discover new devices your test button should(!) show up

harymk commented 3 years ago

Ok. device not discovered

sweharris commented 3 years ago

Give it 5 minutes. I've noticed Alexa doesn't always populate new devices immediately!

harymk commented 3 years ago

ok

harymk commented 3 years ago

one more is this suport colour command, fan speed

sweharris commented 3 years ago

No, this emulates a door sensor; Alexa only supports "open" or "closed". Sensors (door or motion) are the only ones that can be used to trigger routines, so other devices like coloured lights or fans can't be emulated and still be used to trigger routines.

harymk commented 3 years ago

why try that too...

sweharris commented 3 years ago

By mistake when I was writing this code I did emulate a smart switch. It showed up in the devices, but didn't show up in the triggers for a routine. I dug deeper into the Alexa documentation and found it was only sensors (door, motion) that can be used as a smart home trigger for routines. Since this program's goal was to allow for routines to be triggered I had to emulate a sensor.

harymk commented 3 years ago

ok