drimpart
(drimpart)
April 9, 2020, 10:07am
1
Hey!
I´m using this curl command to send TTS notifications with a variable from my Mac Computer to Home Assistant:
curl -X POST -H "Authorization: Bearer MYTOKEN" -H "Content-Type: application/json" -d "{ \"entity_id\": \"media_player.schlafzimmer\", \"message\": \"test\" }" http://192.168.178.XX:8123/api/services/tts/google_say
and that works fine! Now I want to send TTS notifications from my mac to Alexa media Player, the service calls are a bit different , here is what I have so far:
curl -X POST -H "Authorization: Bearer MYTOKEN" -H "Content-Type: application/json" -d "{ \"target\": \"media_player.schlafzimmer_dot\", \"message\": \"test\", \"data\": \"type:tts\" }" http://192.168.178.XX:8123/api/services/notify/alexa_media_schlafzimmer_dot
But this is not working, I think its "data":{"type":"tts"}
, I don´t know how to escape the second square brackets… Can anybody help?
jocnnor
(Jim O'Connor)
April 9, 2020, 2:30pm
2
I don’t see any square brackets. Probably lost due to markdown?
If you use the </> button (on the menu bar when writing a commend) around that code, it won’t remove any values from it and will keep all spacing.
drimpart
(drimpart)
April 9, 2020, 2:39pm
3
oh sorry, I already tried to convert them. According to the Alexa Media Player configuration , the TTS looks like this:
{
"message":"test",
"data":{"type":"tts"},
"target":["group.alexa", "Guest Room", "media_player.kitchen", "serialNumber"]
}
so {"type":"tts"}
is another curly bracket, and I don´t know how to escape that in the curl command
I tried:
-d "{ \"target\": \"media_player.schlafzimmer_dot\", \"message\": \"test\", \"data\": \"type:tts\" }"
but that is not working…
jocnnor
(Jim O'Connor)
April 9, 2020, 2:47pm
4
If you use single quotes, you shouldn’t have to escape any of the double quotes. So that can help a bit!
Also, I don’t think you need to escape the brackets.
And finally, you’re missing some quotes around these fields.
\"type:tts\"
should be \"type\":\"tts\"
. Or, with brackets… \"data\":{\"type\":\"tts\"}
It’s really hard to find missing quotes when they are all escaped. I only notice after using single quotes
So, give that a shot. With the single quotes…which I think works. If nothing else, adding the brackets and fixing the missing quotes should work.
curl -X POST -H 'Authorization: Bearer MYTOKEN' -H 'Content-Type: application/json' -d '{ "target":"media_player.schlafzimmer_dot", "message": "test", "data": {"type":"tts"} }' http://192.168.178.XX:8123/api/services/notify/alexa_media_schlafzimmer_dot
1 Like
drimpart
(drimpart)
April 9, 2020, 3:07pm
5
Thank you Jim, got it working with brackets:
curl
-H “Accept: application/json”
-H “Authorization: Bearer TOKEN”
-X POST
-d “{ "target": "media_player.schlafzimmer_dot", "message": "$KMVAR_sound", "data":{"type":"tts"} }”
http://192.168.178.XX:8123/api/services/notify/alexa_media_schlafzimmer_dot
so now its possible to send variables with Keyboard Maestro on Mac to Home Assistant (In case someone is looking for this
123
(Taras)
April 9, 2020, 3:18pm
6
I would appreciate it if you could clarify the following for me. Your post shows two examples and neither of them match what jocnnor suggested.
Your first example uses double-quotes to delimit the entire string whereas jocnnor’s example suggested single-quotes (to differentiate from the double quotes used within the string).
Your second example (screenshot) also uses outer double-quotes and it also escapes the meaning of every double-quote within the string, which was not suggested in jocnnor’s example.
So do both examples you posted work?
drimpart
(drimpart)
April 9, 2020, 3:25pm
7
oh sorry, I think I copied the wrong one! The Screenshot is the one that is working for me now. So I used jocnnors second suggestion:
Or, with brackets… \"data\":{\"type\":\"tts\"}
curl \
-H "Accept: application/json" \
-H "Authorization: Bearer TOKEN" \
-X POST \
-d "{ \"target\": \"media_player.schlafzimmer_dot\", \"message\": \"$KMVAR_sound\", \"data\":{\"type\":\"tts\"} }" \
http://192.168.178.XX:8123/api/services/notify/alexa_media_schlafzimmer_dot
123
(Taras)
April 9, 2020, 3:36pm
8
Can you try this and let me know if it works?
curl -X POST -H 'Authorization: Bearer MYTOKEN' -H 'Content-Type: application/json' --data-urlencode '{ "target":"media_player.schlafzimmer_dot", "message": "test", "data": {"type":"tts"} }' http://192.168.178.XX:8123/api/services/notify/alexa_media_schlafzimmer_dot
I’m curious to know if the --data-urlencode
option works for this application.
drimpart
(drimpart)
April 9, 2020, 3:41pm
9
its not working, thats what I get back:
123
(Taras)
April 9, 2020, 4:18pm
10
Thanks. In retrospect, that makes sense because Home Assistant does not perform an urldecode.