forked from walthowd/ha-alexa-tts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
alexa_wrapper.sh
70 lines (64 loc) · 2 KB
/
alexa_wrapper.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
#
# Amazon Alexa TTS Home Assistant Wrapper
#
# 2018-06-18: v0.1 initial release
#
# This script is intended to allow the Alexa Remote Control script
# from Alex Lotzimmer to be used as a command line notify platform
# in Home Assistant.
#
# Usage:
# ./alexa_wrapper.sh -d "My Dot Name"
#
# Home Assistant will pass the message to the script via STDIN. The
# Alexa Remote control script requires that spaces be replaced with
# underscores.
#
# Installation:
# Place alexa_wrapper.sh and alexa_remote_control.sh in your Home Assistant
# config directory. In a shell type echo $PATH and replace the below PATH
# variable with your values.
#
# Edit alexa_remote_control.sh with your credentials and
# your location. Test that you can pull a list of devices with
# ./alexa_remote_control.sh -a
#
# Add a command line notify component for each Alexa device
# to Home Assistant as follows:
#
# notify:
# - platform: command_line
# name: 'My Dot Name'
# command: "/home/homeassistant/.homeassistant/alexa_wrapper -d 'My Dot Name'"
#
# You should then be able to call notify.my_dot_name from automations
#
PATH=/usr/local/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Frameworks/Python.framework/Versions/3.6/bin
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ALEXA_REMOTE="$DIR/alexa_remote_control.sh"
usage()
{
echo "$0 -d <device>|ALL"
}
case "$1" in
-d)
if [ "${2#-}" != "${2}" -o -z "$2" ] ; then
echo "ERROR: missing argument for ${1}"
usage
exit 1
fi
DEVICE=$2
shift
;;
*)
echo "ERROR: unknown option ${1}"
usage
exit 1
;;
esac
shift
read message
formatted=${message// /_}
$ALEXA_REMOTE -d "$DEVICE" -e speak:$formatted >> /dev/null
exit 0