Wednesday 3 July 2019

Connecting your Echo Dot to Kodi



It is possible to stream music from your Amazon echo dot to your kodi box !!!

Kodi HTPC is basically an output device but you can set it to receive bluetooth audio and play it to your sound system, it requires a bit of fiddling but once done that's it, you can also adapt this method to connect any device that outputs music (phone, tablet etc) and play that through your kodi box


You will need a crontab entry (something which executes every minute) and some basic linux commands to achieve this.

by placing the simple file in your crontab file (obviously alter your bluetooth mac source
to reflect what yours is (more on this later)

copy the following into a text file and call it connect.sh (minus the brackets) you'll be editing this later on with your actual details......

(

#!/bin/bash
pactl load-module module-udev-detect /dev/null
# pactl list short sinks
# pactl list short sources
pactl set-default-sink alsa_output.pci-0000_00_1b.0.analog-stereo
pactl set-default-source bluez_source.68_8A_87_9B_B7_14.a2dp_source    )

the #'s comment out what would normally be taken as commands as an aide memoire in this case
for the commands you need to discover your actual details 


you need to enable bluetooth on your kodi box if it isn't already enabled 

drop to a terminal prompt and ssh shell into your kodi box
 (you can use putty in Windoze to achieve this)

you will have to find out the root password for your kodi installation to gain access and that depends on what flavour of Kodi you have (libreelec, coreelec or stand alone)

once in type

bluetoothctl

then turn on advertising and discoverable (you can show all commands simply by typing
help in the CLI of bluetoothctl)

it's straightforward you just type discoverable on and advertise on 

this starts your kodi box broadcasting bluetooth invitations, without it you won't be able
to connect to your kodi box from your Alexa app 


then connect to your kodi box FROM your echo dot via the Alexa app on your phone/tablet 
it's important you connect FROM your echo dot and not from kodi, you are setting up an input
to kodi not an output.

Once connected and paired make sure your normal output on your kodi box remains as it was to whatever sink it was connected to originally (speakers or whatever)

your bluetooth echo dot source can be found out by

pactl list short source

and your normal sink can be found out by typing the following

pactl list short sinks

take a note of the output of these commands

bluez_source.68_8A_84_9B_B3_14.a2dp_source

the same applies to the short sink name 

alsa_output.pci-0000_00_1b.0.analog-stereo 


a sink in pulseaudio is an output  (music drains into it)

a source is like a tap above the sink (an input, geddit ?)


copy the sinks and sources into the appropriate  lines and paste it into the file called
connect.sh (don't confuse your sinks and sources)

save the connect.sh in your kodi .config directory or anywhere it's accessible  

then create a crontab file by typing 

crontab -e

cut and paste the following into it 

* * * * * /storage/.config/connect.sh

then save the crontab file

make the file connect.sh executable by typing

chmod +x /storage/.config/connect.sh   <--- connect.sh="" crontab="" entry="" file="" just="" location="" make="" nbsp="" of="" or="" p="" points="" saved="" sure="" the="" to="" wherever="" you="">

Job done !!!


this config should survive reboots (hence the crontab) 

if you ever get trouble or alexa complaining she can't connect or find the speaker it will be because
bluetoothctl has stopped broadcasting and isn't discoverable, because the rest is hardwired in.


once you've paired you can connect to your kodi box simply by saying to your echo dot

"alexa connect speaker"

and it should report back it's done it 

check the time with Alexa "Alexa what time is it" and if all has been done properly she should announce the time from your kodi box 


then enjoy considerably louder and higher quality music from Amazon music 

(you cannot control the volume with the kodi box volume is controlled by the echo dot, either manually or via voice control, although be warned if you turn up the music too high Alexa goes deaf because she can't hear you properly)


make sure your kodi box is turned on and settled before you try and connect to echo dot to your kodi box 


Enjoy !!!