notifications to chromecast

Alexa, Google Home and Siri
jeroentje
Posts: 8
Joined: Thursday 01 June 2017 16:22
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: notifications to chromecast

Post by jeroentje » Wednesday 12 September 2018 17:14

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,

User avatar
thecosmicgate
Posts: 258
Joined: Monday 06 April 2015 14:37
Target OS: Linux
Domoticz version: newest
Location: The Netherlands / Hoeven
Contact:

Re: notifications to chromecast

Post by thecosmicgate » Saturday 15 September 2018 15:46

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 !
So what's the working script you're using ?

Sent from my ONEPLUS A6003 using Tapatalk

It's nice to be important, but it's more important to be nice
Scooter ;)

glsf91
Posts: 38
Joined: Tuesday 14 November 2017 22:56
Target OS: Linux
Domoticz version:
Contact:

Re: notifications to chromecast

Post by glsf91 » Sunday 16 September 2018 17:43

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"
to this:

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"
Also working on my google mini.

User avatar
sincze
Posts: 962
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi
Domoticz version: 4.9700
Location: Netherlands
Contact:

Re: notifications to chromecast

Post by sincze » Sunday 16 September 2018 18:09

glsf91 wrote:
Sunday 16 September 2018 17:43
Spoiler: show

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"
Thanks for the update modified my code and indeed running smoothly without errors.
Using Pass2php since 2016-12
LAN: RFLink, P1-Port, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266, Xiaomi Gateway
Solar: Omnik Inverter, PVOutput
Video: Kodi clients with Harmony HUB
Sensors: You name it I probably got 1.

mark.sellwood
Posts: 47
Joined: Tuesday 04 March 2014 11:33
Target OS: Raspberry Pi
Domoticz version:
Location: Surrey, UK
Contact:

Re: notifications to chromecast

Post by mark.sellwood » 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?
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.

glsf91
Posts: 38
Joined: Tuesday 14 November 2017 22:56
Target OS: Linux
Domoticz version:
Contact:

Re: notifications to chromecast

Post by glsf91 » Saturday 22 September 2018 14:42

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?
I also have sometime a hanging script. So I switched to pychromecast.
Warning: the programming below is maybe awfull but it is working (I'am not a programmer).

I use this with viewtopic.php?f=69&t=22610#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

Change device_friendly_name to yours.

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=b98x9xlfs54ws4k0wc0o8g4gwc0w8ss&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. Via Azure account john.brattinga@live.nl; 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=c28d318e36b2422cb88f216bc63b0a4b  --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
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

User avatar
sincze
Posts: 962
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi
Domoticz version: 4.9700
Location: Netherlands
Contact:

Re: notifications to chromecast

Post by sincze » 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.

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...
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.

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.
What did I miss :lol:
Using Pass2php since 2016-12
LAN: RFLink, P1-Port, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266, Xiaomi Gateway
Solar: Omnik Inverter, PVOutput
Video: Kodi clients with Harmony HUB
Sensors: You name it I probably got 1.

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests