Chromecasts are not controllable using an IR remote control. This projects adds that function by using a raspberry pi with an IR sensor that receives the remote cotrol codes and converts them into http calls.
download and install latest version of spotipy
and pychromecast
python3
Using sudo easy_install3 ...
doesn't work as it retrieves an older version. (why?)
Login to the https://developer.spotify.com
and create a new application. Remember client_id
, client_secret
and redirect_uri
.
copy remote.py
and config.py
to /spotify.google/ (or other folder) then make it executable
update config.py
with all the required credentials:
#name of the chromecast device
chromecast = "your_chromecast_name"
chromecast_ip = "x.x.x.x"
volume = 0.8
#spotify_client credentials
accounts = {"default":{"username":"", "password":""}}
#Application
client_id = "as_created_above"
client_secret = "as_created_above"
redirect_uri = "as_created_above"
login
url. ex: accounts = {"john":{"username":"john_spotify@gmail.com", "password":"73847893497389478389479374892398"}}
becomes http://127.0.0.1:9999/login/john
The system loggs in to the last used account or to account
"default"
(if present), if no user is logged in yet. (callinghttp://127.0.0.1:9999/login
is equivalent to callinghttp://127.0.0.1:9999/login/default
if adefault
user has been provided)
/lib/systemd/system/spotify.service
with content:[Unit]
Description=Spotify Remote
After=network.target auditd.service
[Service]
ExecStart=/usr/bin/python3 /spotify.google/remote.py
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
[Install]
WantedBy=multi-user.target
Alias=spotify.service
sudo systemctl enable spotify
sudo systemctl start spotify
The command map file for lirc
(/etc/lirc/lircrc
):
begin
prog = irexec
button = SPOTIFY_PLAY
config = curl http://127.0.0.1:9999/play
end
begin
prog = irexec
button = SPOTIFY_PAUSE
config = curl http://127.0.0.1:9999/pause
end
begin
prog = irexec
button = SPOTIFY_PREVIOUS
config = curl http://127.0.0.1:9999/previous
end
begin
prog = irexec
button = SPOTIFY_NEXT
config = curl http://127.0.0.1:9999/next
end
begin
prog = irexec
button = SPOTIFY_ON
config = curl http://127.0.0.1:9999/login/john
end
begin
prog = irexec
button = SPOTIFY_OFF
config = curl http://127.0.0.1:9999/off
end
begin
prog = irexec
button = SPOTIFY_REBOOT
config = curl http://127.0.0.1:9999/reboot
end
Where SPOTIFY_*
buttons in the lircd.conf
file recorded (irrecord --disable-namespace -d /dev/lirc0 /etc/lirc/lircd.conf
) or random created codes and then taught to the remote (see https://github.com/MoonshineSG/remote.ir)
Setup a new device and a new activity, thne configure the buttons as usual.
Accepting beer tips...