Hey guys,
I struggled a while before I got everything working so I though it would be nice to share this with you.
Lets start with the result (click to view on Vimeo):
My ultimate goal was a kind of Jarvis’ish way to wake up. I already had Sonos enables speakers in my bedroom so I knew I could use those. At first I tried to do everything via Pimatic but then I stumbled onto a lot of problems. The pimatic-sonos plugin did not have a feature in which I could send speech commands to Sonos. So I went looking and I found this plugin:https://github.com/jishi/node-sonos-http-api. When I installed it… failure… couldn’t get it to work for some reason, so I install it on a Raspberry pi with the lastest version of NodeJS and it worked. Nice!
Well onto the next problem… I’d send a command like this:
curl "http://10.0.1.64:5005/say/The%20temperture%20outsite%20is%20$temp%20%20degrees%20%20%2Cwith%20a%20$status"
But… this was not url encoded which means spaces would not change to %20 so I tried to create a plugin which would convert input to url encoded input after a few days I was like… Wait what am I doing?? I could just use a bash script and that would make things so much easier. So I stopped building the plugin and started creating a bash script.
These were the problems I went trough… I learned a lot from this experience. Don’t make the same mistake haha!
If you want to build this yourself, The final bash script looks like this:
#!/bin/sh
alarm=$( printf "%s\n" "$1" | sed 's/ /%20/g' )
quote=$( printf "%s\n" "$2" | sed 's/ /%20/g' )
author=$( printf "%s\n" "$3" | sed 's/ /%20/g' )
temp=$( printf "%s\n" "$4" | sed 's/ /%20/g' )
status=$( printf "%s\n" "$5" | sed 's/ /%20/g' )
curl "http://10.0.1.64:5005/say/Wake%2C%20up%20Tim!%20It%20is%20%20%2C$alarm%20in%20the%20morning"
sleep 10
curl "http://10.0.1.64:5005/say/The%20quote%20of%20the%20day%20is%20$quote%20%20%20%2Cby%20$author"
sleep 20
curl "http://10.0.1.64:5005/say/The%20temperture%20outsite%20is%20$temp%20%20degrees%20%20%2Cwith%20a%20$status"
sleep 15
curl "http://10.0.1.64:5005/Slaapkamer/volume/20"
sleep 1
random_num=$[ 1 + $[ RANDOM % 6 ]]
case $random_num in
1)
echo "1 - wekker"
curl "http://10.0.1.64:5005/favorite/Wekker"
;;
2)
echo "2 - party"
curl "http://10.0.1.64:5005/favorite/Party"
;;
3)
echo "3 - stream"
curl "http://10.0.1.64:5005/favorite/Stream"
;;
4)
echo "4 - Zonnig opstaan"
curl "http://10.0.1.64:5005/favorite/Zonnig%20opstaan"
;;
5)
echo "5 - wub wub"
curl "http://10.0.1.64:5005/favorite/Dubstep"
;;
6)
echo "6 - Heartfedt radio"
curl "http://10.0.1.64:5005/favorite/Heartfeldt%20by%20Sam%20Feldt"
;;
esac
echo "Okay!"
The bash script will:
- URL encode all the variables
- Send the curl commands with a small delay
- Select a random alarm playlist (must be added to favorites in Sonos)
—
This also requires some settings in pimatic, I have a $alarm variable which I change to the time I want to wake up before I go to sleep. The bash script is located in my home folder. Also note the parameters I’m sending.
if its $alarm execute "bash /home/tim/wakeup.sh \"$alarm\" \"$quote.quote\" \"$quote.author\" \"$weather.temperature\" \"$weather.status\"" and turn on Kleuren and turn on curtain
(kleuren are my hue lights and curtain is my curtain)
Allright thats it!