notifications to chromecast
Moderator: leecollings
-
- Posts: 7
- Joined: Thursday 01 June 2017 16:22
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: notifications to chromecast
hi, another question.
After sending a text or sound, the volume on the google mini stays the volume set on the stream2chromecast script.
Anyone an idea to ask on google home what the current volume is in the script, so the script can put the initial volume back after sending the text/sound?
thanks,
After sending a text or sound, the volume on the google mini stays the volume set on the stream2chromecast script.
Anyone an idea to ask on google home what the current volume is in the script, so the script can put the initial volume back after sending the text/sound?
thanks,
- thecosmicgate
- Posts: 188
- Joined: Monday 06 April 2015 14:37
- Target OS: Linux
- Domoticz version: newest
- Location: The Netherlands / Hoeven
- Contact:
Re: notifications to chromecast
So what's the working script you're using ?jeroentje wrote:Hi,
same issue here. new google mini.
stream2chromecast stays "sending data" and takes 10 mins to stop.
The file is played well. I also use the french script with google TTS.
I've tried a lot (different versions of the .py files about messages and .py script and all the common solutions found in google for stream2chromecast), but still no solution.
Anyone ? " Sending data" hangs, you have to CNTL-C to stop:
Notification : testje
Volume : 0.2
Chromecast online
ip_addr: 192.168.0.200 device name:
-----------------------------------------
Stream2Chromecast version:0.6.3
Copyright (C) 2014-2016 Pat Carter
GNU General Public License v3.0
https://www.gnu.org/licenses/gpl-3.0.html
-----------------------------------------
ip_addr: 192.168.0.200 device name:
source is file: /tmp/message.mp3
local ip address: 192.168.0.202
OS identifies the mimetype as : audio/mpeg
URL & content-type: http://192.168.0.202:41791?/tmp/message.mp3 audio/mpeg
loading media...
192.168.0.200 - - [09/Sep/2018 16:18:03] "GET /?/tmp/message.mp3 HTTP/1.1" 200 -
sending data
and then it hangs
Any help is appriciated !
Sent from my ONEPLUS A6003 using Tapatalk
It's nice to be important, but it's more important to be nice
Scooter ;)
Scooter ;)
Re: notifications to chromecast
jeroentje wrote: ↑Sunday 09 September 2018 16:21 Hi,
same issue here. new google mini.
stream2chromecast stays "sending data" and takes 10 mins to stop.
The file is played well. I also use the french script with google TTS.
I've tried a lot (different versions of the .py files about messages and .py script and all the common solutions found in google for stream2chromecast), but still no solution.
Anyone ? " Sending data" hangs, you have to CNTL-C to stop:
I think this is related to a firmware upgrade in june on the chromecast. I have the same problem I see.
But after changing the code a little bit it is working again. I'am not sure it is the right solution but it is working again for me.
I did not tested a lot.
Change this in cc_media_controller.py:
Code: Select all
def is_idle(self):
""" return the IDLE state of the player """
status = self.get_status()
if status['media_status'] is None:
if status['receiver_status'] is None:
return True
else:
return status['receiver_status'].get("statusText", "") == u"Ready To Cast"
else:
return status['media_status'].get("playerState", "") == u"IDLE"
Code: Select all
def is_idle(self):
""" return the IDLE state of the player """
status = self.get_status()
if status['media_status'] is None:
return True
else:
return status['media_status'].get("playerState", "") == u"IDLE"
- sincze
- Posts: 1300
- Joined: Monday 02 June 2014 22:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.4
- Location: Netherlands / Breda Area
- Contact:
Re: notifications to chromecast
Thanks for the update modified my code and indeed running smoothly without errors.
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
-
- Posts: 101
- Joined: Tuesday 04 March 2014 10:33
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Surrey, UK
- Contact:
Re: notifications to chromecast
Hi have made the change to cc_media_controller.py but still it hangs after the message sending data. I do hear the message.
Any suggestions?
Any suggestions?
3 x Pi, 1 Master, 2 Slaves, 1x Aeotec Z-Stick S2, 4xSP103 PIR, 5xPowerNode 1, 1xSmart Energy Switch Gen5, 4xFGSS101 Smoke Sensor, 2xFGD212, 9xFGS212 , 7xFGS221/2, 1xAD142 , 1xTKB TZ68E , 2xAeotec Multi Sensor, 3 x NodOn CRC-3-1-00.
Re: notifications to chromecast
I also have sometime a hanging script. So I switched to pychromecast.mark.sellwood wrote: ↑Wednesday 19 September 2018 22:13 Hi have made the change to cc_media_controller.py but still it hangs after the message sending data. I do hear the message.
Any suggestions?
Warning: the programming below is maybe awfull but it is working (I'am not a programmer).
I use this with https://www.domoticz.com/forum/viewtopi ... 10#p175077.
Added a script play_chromecast.py:
Code: Select all
from __future__ import print_function
import time
import pychromecast
import threading
from time import sleep
import sys
args = sys.argv[1:]
if len(args) < 2:
sys.exit("Usage: notification_google_home <text> <volume 0..1>")
messageUrl=args[0]
volume=float(args[1])
print("MessageUrl: ", messageUrl)
print("Volume: ", volume)
# Your Chromecast device Friendly Name
device_friendly_name = "Family room speaker"
chromecasts = pychromecast.get_chromecasts()
# select Chromecast device
cast = next(cc for cc in chromecasts if cc.device.friendly_name == device_friendly_name)
# wait for the device
cast.wait()
#print(cast.device)
#print(cast.status)
cast.set_volume(volume)
sleep(0.3)
#print(cast.status)
# get media controller
mc = cast.media_controller
start_playing = False
completion = threading.Event()
class StatusMediaListener:
def __init__(self, name, cast):
self.name = name
self.cast= cast
def new_media_status(self, status):
# print('[',time.ctime(),' - ', self.name,'] status media change:')
# print(status)
if (status.player_is_idle and start_playing):
completion.set()
listenerMedia = StatusMediaListener(cast.name, cast)
cast.media_controller.register_status_listener(listenerMedia)
# set online video url
mc.play_media(messageUrl, 'audio/mp3')
# blocks device
mc.block_until_active()
#print(mc.status)
# plays the video
mc.play()
start_playing = True
# poll so signal handlers still work
while not completion.wait(0.5):
pass
and changed notification_chromecast.sh to:
Code: Select all
#!/bin/bash
# notification_google_home.sh Script de notification de message vocal sur la Google Home
# by JS Martin - 11/02/2018 - version 0.1
message=$1 # text message
volume=$2 # 0=auto 0.1=10% 1=100%
jingle=$3 # jingle track number (0=no track 1=default track)
echo "Started with: " $1 $2 $3
# ------ parameters ---------
# Autoset volume if volume=0
Start_day="0700"
Start_night="2200"
Night_vol="0.4"
Day_vol="0.7"
# number of arg correction
case "$#" in
"1")
volume="0"
jingle="1"
;;
"2")
jingle="1"
;;
*)
echo "Usage: notification_google_home <text> [volume 0..1]"
exit 1
;;
esac
# IP Google Home
IPGH="192.168.1.173"
echo "Notification : "$message
if [ $volume != "0" ]; then
echo "Volume : "$volume
else
CUR_TIME=`date +%H%M`
if [ $CUR_TIME -ge $Start_day -a $CUR_TIME -le $Start_night ]; then
echo "Day volume"
volume=$Day_vol
else
echo "Night volume"
volume=$Night_vol
fi
echo "Volume = automatique - set to "$volume
fi
# Exit if chromecast not online
ping -c1 -W 2 $IPGH >/dev/null
if [ $? -eq 0 ]
then echo "Chromecast online"
else echo "Chromecast offline"
exit 0
fi
if [ -f /tmp/message.mp3 ]
then
rm /tmp/message.mp3
fi
#Text to MP3; afgekeken uit izSynth
#curl -s -G "http://api.naturalreaders.com/v4/tts/macspeak" --data "apikey=<apikey>&src=pw&r=22&s=1" --data-urlencode "t=$message" -o /tmp/message.mp3
# google gebruiken
#if [ ${#message} -lt 150 ]
#then
# curl -s -G "http://translate.google.com/translate_tts" --data "ie=UTF-8&total=1&idx=0&client=tw-ob&&tl=nl-NL" --data-urlencode "q=$message" -A "Mozilla" --compressed -o /tmp/message.mp3
#else
# /home/john/.local/bin/gtts-cli "$message" -l 'nl' -o /tmp/message.mp3
#fi
#Microsoft Bing Speech API. free 5000 per maand max 5 per sec.
python /home/john/bingSpeech/BingTTSGen.py --cache=/home/john/bingSpeech/cache --dest=/tmp/message.mp3 --lang=nl-NL --voice="HannaRUS" --fileformat=audio-16khz-32kbitrate-mono-mp3 --apikey=<apikey> --text=''"$message"''
if [ -f /tmp/message.mp3 ]
then
# Problemen met stream2chromecast vanwege update chromecast juli 2018
#Set Google Home volume
# sudo python /home/john/stream2chromecast/stream2chromecast/stream2chromecast.py -devicename $IPGH -setvol $volume
#MP3 to Google Home
# sudo python /home/john/stream2chromecast/stream2chromecast/stream2chromecast.py -devicename $IPGH /tmp/message.mp3
cp /tmp/message.mp3 /home/john/domoticz/www/message.mp3
python3 /home/john/pychromecast/play_chromecast.py http://192.168.1.159:8080/message.mp3 $volume
fi
if [ -f /tmp/message.mp3 ]
then
rm /tmp/message.mp3
fi
I think this works better but I did not test for a long time.
You need python 3.4+ (check with command: python3)
Install pychromecast with:
apt-get install python3-pip (if you don't have python3 pip)
python3 -m pip install pychromecast --user
Adjust <apikey>
Last edited by glsf91 on Sunday 13 January 2019 14:10, edited 3 times in total.
- sincze
- Posts: 1300
- Joined: Monday 02 June 2014 22:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.4
- Location: Netherlands / Breda Area
- Contact:
Re: notifications to chromecast
I thought... I had a good idea to move all my IOT stuff to a seperate VLAN.
My Google Chromecasts, Google Home , LG Smart TV's you name it.
After some modifications it all works.
Domoticz can reach the devices and control them, read the status.
... However... what is not working.. Stream2chromecast.
I opened op the router VLAN Firewall (TCP & UDP) so the google home can reach the Domoticz machine where stream2chromecast is running from. However it seems it is unable to collect the file. It does adjust the playback volume to the correct level.
Where 192.168.yy.yy is the Google Home and 192.168.xx.xx is the Domoticz machine.
What did I miss 
My Google Chromecasts, Google Home , LG Smart TV's you name it.
After some modifications it all works.
Domoticz can reach the devices and control them, read the status.
... However... what is not working.. Stream2chromecast.
Code: Select all
-----------------------------------------
Stream2Chromecast version:0.6.3
Copyright (C) 2014-2016 Pat Carter
GNU General Public License v3.0
https://www.gnu.org/licenses/gpl-3.0.html
-----------------------------------------
ip_addr: 192.168.yy.yy device name:
source is file: /tmp/google/2f55628619d7d0366ece864b2cdf67d8.mp3
local ip address: 192.168.xx.xx
OS identifies the mimetype as : audio/mpeg
URL & content-type: http://192.168.xx.xx:39121?/tmp/google/2f55628619d7d0366ece864b2cdf67d8.mp3 audio/mpeg
loading media...
Where 192.168.yy.yy is the Google Home and 192.168.xx.xx is the Domoticz machine.
Code: Select all
user@raspberry-user:~ $ sudo iptables --list
iptables v1.6.0: can't initialize iptables table `filter': Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.

Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
- thecosmicgate
- Posts: 188
- Joined: Monday 06 April 2015 14:37
- Target OS: Linux
- Domoticz version: newest
- Location: The Netherlands / Hoeven
- Contact:
Re: notifications to chromecast
So what's the working script for now ?
Can't get this working . Still hangs .
Could anybody share his script or way how it's working
Verstuurd vanaf mijn ONEPLUS A6003 met Tapatalk
Can't get this working . Still hangs .
Could anybody share his script or way how it's working
Verstuurd vanaf mijn ONEPLUS A6003 met Tapatalk
It's nice to be important, but it's more important to be nice
Scooter ;)
Scooter ;)
- sincze
- Posts: 1300
- Joined: Monday 02 June 2014 22:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.4
- Location: Netherlands / Breda Area
- Contact:
Re: notifications to chromecast
This stream2chromecast is the script I am using without any problems.(after modifying the cc_media_controller.py as well.thecosmicgate wrote: ↑Friday 19 October 2018 21:29 So what's the working script for now ?
Can't get this working . Still hangs .
Could anybody share his script or way how it's working
Verstuurd vanaf mijn ONEPLUS A6003 met Tapatalk
- Spoiler: show
- Spoiler: show
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
- thecosmicgate
- Posts: 188
- Joined: Monday 06 April 2015 14:37
- Target OS: Linux
- Domoticz version: newest
- Location: The Netherlands / Hoeven
- Contact:
Re: notifications to chromecast
okay almost there , but getting :sincze wrote: ↑Saturday 20 October 2018 18:17This stream2chromecast is the script I am using without any problems.(after modifying the cc_media_controller.py as well.thecosmicgate wrote: ↑Friday 19 October 2018 21:29 So what's the working script for now ?
Can't get this working . Still hangs .
Could anybody share his script or way how it's working
Verstuurd vanaf mijn ONEPLUS A6003 met Tapatalk
cc_media_controller.py
- Spoiler: show
- Spoiler: show
Code: Select all
Notification : There is someone at the door
Night volume
Volume = automatique - set to 0.2
ip_addr: 192.168.1.46 device name: Google home hub
-----------------------------------------
Stream2Chromecast version:0.6.3
Copyright (C) 2014-2016 Pat Carter
GNU General Public License v3.0
https://www.gnu.org/licenses/gpl-3.0.html
-----------------------------------------
ip_addr: 192.168.1.46 device name: Google home hub
Traceback (most recent call last):
File "/home/pim/stream2chromecast/stream2chromecast.py", line 815, in <module>
run()
File "/home/pim/stream2chromecast/stream2chromecast.py", line 811, in run
subtitles_port=subtitles_port, subtitles_language=subtitles_language)
File "/home/pim/stream2chromecast/stream2chromecast.py", line 419, in play
save_pid(cast.host)
File "/home/pim/stream2chromecast/stream2chromecast.py", line 326, in save_pid
with open(pid_file, "w") as pidfile:
IOError: [Errno 2] No such file or directory: '/tmp/google/stream2chromecast_192.168.1.46.pid'

It's nice to be important, but it's more important to be nice
Scooter ;)
Scooter ;)
- sincze
- Posts: 1300
- Joined: Monday 02 June 2014 22:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.4
- Location: Netherlands / Breda Area
- Contact:
Re: notifications to chromecast
Does /tmp/google directory exist with necessary permissions?
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
- sincze
- Posts: 1300
- Joined: Monday 02 June 2014 22:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.4
- Location: Netherlands / Breda Area
- Contact:
Re: notifications to chromecast
Does /tmp/google directory exist with necessary permissions?
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
- sincze
- Posts: 1300
- Joined: Monday 02 June 2014 22:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.4
- Location: Netherlands / Breda Area
- Contact:
Re: notifications to chromecast
Fixed my own issue today with help of https://community.ubnt.com/t5/UniFi-Rou ... -p/2184761. Just allowed IOT VLAN traffic to my domoticz hosts machine on a pre-defined port. The pre-defined port is described in the wiki of stream2chromecast.sincze wrote: ↑Sunday 23 September 2018 19:59 I thought... I had a good idea to move all my IOT stuff to a seperate VLAN.
My Google Chromecasts, Google Home , LG Smart TV's you name it.
After some modifications it all works.
Domoticz can reach the devices and control them, read the status.
... However... what is not working.. Stream2chromecast.
I opened op the router VLAN Firewall (TCP & UDP) so the google home can reach the Domoticz machine where stream2chromecast is running from. However it seems it is unable to collect the file. It does adjust the playback volume to the correct level.Code: Select all
----------------------------------------- Stream2Chromecast version:0.6.3 Copyright (C) 2014-2016 Pat Carter GNU General Public License v3.0 https://www.gnu.org/licenses/gpl-3.0.html ----------------------------------------- ip_addr: 192.168.yy.yy device name: source is file: /tmp/google/2f55628619d7d0366ece864b2cdf67d8.mp3 local ip address: 192.168.xx.xx OS identifies the mimetype as : audio/mpeg URL & content-type: http://192.168.xx.xx:39121?/tmp/google/2f55628619d7d0366ece864b2cdf67d8.mp3 audio/mpeg loading media...
Where 192.168.yy.yy is the Google Home and 192.168.xx.xx is the Domoticz machine.
What did I missCode: Select all
user@raspberry-user:~ $ sudo iptables --list iptables v1.6.0: can't initialize iptables table `filter': Table does not exist (do you need to insmod?) Perhaps iptables or your kernel needs to be upgraded.
![]()
So a command on the Domoticz server machine:
Code: Select all
sudo ./stream2chromecast.py -port 8765 -devicename 192.168.yy.yy /tmp/google/7688df2479ece342b15cab525876d
9b5.mp3
Code: Select all
-----------------------------------------
Stream2Chromecast version:0.6.3
Copyright (C) 2014-2016 Pat Carter
GNU General Public License v3.0
https://www.gnu.org/licenses/gpl-3.0.html
-----------------------------------------
ip_addr: 192.168.yy.yy device name:
source is file: /tmp/google/7688df2479ece342b15cab525876d9b5.mp3
local ip address: 192.168.xx.xx
OS identifies the mimetype as : audio/mpeg
URL & content-type: http://192.168.xx.xx:8765?/tmp/google/7688df2479ece342b15cab525876d9b5.mp3 audio/mpeg
loading media...
192.168.yy.yy - - [03/Jan/2019 20:17:34] "GET /?/tmp/google/7688df2479ece342b15cab525876d9b5.mp3 HTTP/1.1" 200 -
sending data
waiting for player to finish - press ctrl-c to stop...
done
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
-
- Posts: 8
- Joined: Wednesday 15 October 2014 18:54
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: notifications to chromecast
Thanks for your work, this works just fine!glsf91 wrote: ↑Saturday 22 September 2018 14:42I also have sometime a hanging script. So I switched to pychromecast.mark.sellwood wrote: ↑Wednesday 19 September 2018 22:13 Hi have made the change to cc_media_controller.py but still it hangs after the message sending data. I do hear the message.
Any suggestions?
Warning: the programming below is maybe awfull but it is working (I'am not a programmer).
I use this with https://www.domoticz.com/forum/viewtopi ... 10#p175077.
Added a script play_chromecast.py:
Of course adjust the path of the scripts and domoticz url in the last script to yours.
I think this works better but I did not test for a long time.
You need python 3.4+ (check with command: python3)
Install pychromecast with:
apt-get install python3-pip (if you don't have python3 pip)
python3 -m pip install pychromecast --user
<apikey> wel aanpassen
I have two suggestions:
Suggestion 1: Making it faster
The script might take some time to start, because it searches all Google Homes for the correct one. Since I have 6 of them, this takes some time. That's not an issue if you want to announce some general message, but it is an issue when used with a doorbell. The script takes about 5 seconds to initialize and search all Google Homes, and if you want to play this sound on multiple Homes when there's someone at the door, that takes too long. Also I have made a specific mp3-doorbell file that is stored permanently in the /www/geluiden-folder of Domoticz, so it doesn't go through Google TTS/Sox/etc etc. making it even faster.
I have modified the calling notification_google_home.sh as follows:
1) Edit the call to Python at the end, so the IPGH you entered earlier in the script is passed on:
Code: Select all
python3 /home/pi/stream2chromecast/play_chromecast.py http://192.168.1.110:8080/message.mp3 $volume $IPGH
Code: Select all
messageUrl=args[0]
volume=float(args[1])
# This line is new
ip=args[2]
print("MessageUrl: ", messageUrl)
print("Volume: ", volume)
# This is new
print("Ip: ", ip)
# Comment out or delete these lines:
# Your Chromecast device Friendly Name
# device_friendly_name = "Zolder Speaker"
#chromecasts = pychromecast.get_chromecasts()
# select Chromecast device
#cast = next(cc for cc in chromecasts if cc.device.friendly_name == device_friendly_name)
# This line is new
cast = pychromecast.Chromecast(ip)
Suggestion 2: Releasing the player
In the file play_chromecast.py add this at the end:
Code: Select all
# poll so signal handlers still work
while not completion.wait(0.5):
pass
cast.quit_app()
-
- Posts: 229
- Joined: Friday 03 April 2015 20:44
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Germany (near dutch border)
- Contact:
Re: notifications to chromecast
Hi, looks promising, can you give an example of your notify_livingroom.sh script?
Thank you in advance.
Hans
Thank you in advance.
Hans
Re: notifications to chromecast
Thanks for your improvements.
I also made some improvements and included yours.
Now the volume setting is restored to the previous setting.
Is something was already playing, strange effects are sometimes occurring.
Sometimes playing was skipped.
The complete play_chromecast.py script:
Code: Select all
from __future__ import print_function
import time
import pychromecast
import threading
from time import sleep
import sys
args = sys.argv[1:]
if len(args) < 3:
sys.exit("Usage: notification_google_home <text> <volume 0..1> <IP address>")
messageUrl=args[0]
volume=float(args[1])
ip=args[2]
print("MessageUrl: ", messageUrl)
print("New volume: ", volume)
print("Ip chromecast: ", ip)
# Your Chromecast device Friendly Name
#device_friendly_name = "Family room speaker"
#device_friendly_name = "Google mini"
#chromecasts = pychromecast.get_chromecasts()
# select Chromecast device
#cast = next(cc for cc in chromecasts if cc.device.friendly_name == device_friendly_name)
cast = pychromecast.Chromecast(ip)
# wait for the device
cast.wait()
sleep(1)
#print(cast.device)
#print(cast.status)
# save current volume level
prev_volume_level = cast.status.volume_level
print('Prev volume: ',prev_volume_level)
# get media controller
mc = cast.media_controller
sleep(0.1)
#print('Mediastatus: ', mc.status)
print('PLaying?: ', mc.status.player_is_playing)
if (mc.status.player_is_playing ):
mc.stop()
sleep(0.1)
cast.set_volume(volume)
sleep(0.1)
#print('After set_volume: ', cast.status)
start_playing = False
completion = threading.Event()
class StatusMediaListener:
def __init__(self, name, cast):
self.name = name
self.cast= cast
def new_media_status(self, status):
print('[',time.ctime(),' - ', self.name,'] status media change:')
print(status)
if (status.player_is_idle and start_playing):
completion.set()
listenerMedia = StatusMediaListener(cast.name, cast)
cast.media_controller.register_status_listener(listenerMedia)
# set online video url
mc.play_media(messageUrl, 'audio/mp3')
# blocks device
mc.block_until_active()
#print('After block: ',mc.status)
# plays the video
mc.play()
sleep(0.5)
start_playing = True
# poll so signal handlers still work
while not completion.wait(0.5):
pass
# Restore volume level
cast.set_volume(prev_volume_level)
#print(cast.status)
sleep(0.1)
#print(cast.status)
cast.quit_app()
-
- Posts: 8
- Joined: Wednesday 15 October 2014 18:54
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: notifications to chromecast
Thanks for your work!glsf91 wrote: ↑Sunday 13 January 2019 16:35
Thanks for your improvements.
I also made some improvements and included yours.
Now the volume setting is restored to the previous setting.
Is something was already playing, strange effects are sometimes occurring.
Sometimes playing was skipped.
The complete play_chromecast.py script:
Only tested on a google home mini.Code: Select all
from __future__ import print_function import time import pychromecast import threading from time import sleep import sys args = sys.argv[1:] if len(args) < 3: sys.exit("Usage: notification_google_home <text> <volume 0..1> <IP address>") messageUrl=args[0] volume=float(args[1]) ip=args[2] print("MessageUrl: ", messageUrl) print("New volume: ", volume) print("Ip chromecast: ", ip) # Your Chromecast device Friendly Name #device_friendly_name = "Family room speaker" #device_friendly_name = "Google mini" #chromecasts = pychromecast.get_chromecasts() # select Chromecast device #cast = next(cc for cc in chromecasts if cc.device.friendly_name == device_friendly_name) cast = pychromecast.Chromecast(ip) # wait for the device cast.wait() sleep(1) #print(cast.device) #print(cast.status) # save current volume level prev_volume_level = cast.status.volume_level print('Prev volume: ',prev_volume_level) # get media controller mc = cast.media_controller sleep(0.1) #print('Mediastatus: ', mc.status) print('PLaying?: ', mc.status.player_is_playing) if (mc.status.player_is_playing ): mc.stop() sleep(0.1) cast.set_volume(volume) sleep(0.1) #print('After set_volume: ', cast.status) start_playing = False completion = threading.Event() class StatusMediaListener: def __init__(self, name, cast): self.name = name self.cast= cast def new_media_status(self, status): print('[',time.ctime(),' - ', self.name,'] status media change:') print(status) if (status.player_is_idle and start_playing): completion.set() listenerMedia = StatusMediaListener(cast.name, cast) cast.media_controller.register_status_listener(listenerMedia) # set online video url mc.play_media(messageUrl, 'audio/mp3') # blocks device mc.block_until_active() #print('After block: ',mc.status) # plays the video mc.play() sleep(0.5) start_playing = True # poll so signal handlers still work while not completion.wait(0.5): pass # Restore volume level cast.set_volume(prev_volume_level) #print(cast.status) sleep(0.1) #print(cast.status) cast.quit_app()
I also experienced the problem that when something else was already playing, the sound we are sending doesn't play.
You created an IF to check if something was playing and then issued a stop() command.
That doesn't seem to always work in my case.
I have found another solution, which always seems to work and doesn't even need any checking and doesn't cost any time either.
When you first create the CAST-object, just add this:
Code: Select all
cast = pychromecast.Chromecast(ip)
cast.quit_app()
Also, it doesn't destroy the CAST-object or anything, so no recreating it is neccessary.
Now all I need is a way to automatically resume playing what was played before, eg. a Spotify-song or a TuneIn Radio station...
-
- Posts: 470
- Joined: Thursday 26 October 2017 13:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Location: Delft
- Contact:
Re: notifications to chromecast
In the comments of the topic in the french site another fork of stream2chromecast is mentioned that addresses both issues listed here:
Here's the link to the topic response by bricololo: https://easydomoticz.com/forum/viewtopi ... =80#p60075
And the github page for meute's fork of stream2chromecast: https://github.com/meute/stream2chromecast
So what I did to get the working version of stream2chromecast:
edit: the mDNS search only finds chromecasts, not home devices... So you still need to address the home(s) by their ip address.
edit 2: I haven't found how to employ the -getvol parameter to actually return the volume to it's original level, but at least meute mentions the possibility to do so.
- stream2chromecast doesn't close after playback ends
- volume is not returned to it's original value after playback ends
- stream2chromecast doesn't support device groups, only ip adresses are possible
Here's the link to the topic response by bricololo: https://easydomoticz.com/forum/viewtopi ... =80#p60075
And the github page for meute's fork of stream2chromecast: https://github.com/meute/stream2chromecast
So what I did to get the working version of stream2chromecast:
Code: Select all
cd ~
rm -r -f stream2chromecast
git clone https://github.com/meute/stream2chromecast
edit 2: I haven't found how to employ the -getvol parameter to actually return the volume to it's original level, but at least meute mentions the possibility to do so.
Who is online
Users browsing this forum: No registered users and 0 guests