Page 1 of 3
Chromecast status
Posted: Tuesday 23 June 2015 15:51
by piotr
The Chromecast status can be retrieved in JSON (see
http://fiquett.com/2013/07/chromecast-traffic-sniffing/). Would it be possible to add the Chromecast to Domoticz so we can use the status in events ?
Re: Chromecast status
Posted: Wednesday 24 June 2015 7:38
by jannl
Hm I have a chromecast. Why would you want to see the chromecast status?
Re: Chromecast status
Posted: Wednesday 24 June 2015 13:11
by piotr
To use it in Events. Example: Domoticz turns the lights off when it's past 23:00 AND no one is watching TV (Mediacenter virual switch). And: because we can

Re: Chromecast status
Posted: Wednesday 24 June 2015 13:29
by Siewert308SW
piotr wrote:To use it in Events. Example: Domoticz turns the lights off when it's past 23:00 AND no one is watching TV (Mediacenter virual switch). And: because we can

Already done this by using the Network presence detection.
Dim lights when Chromcast/TV is on and brighten them when Chromcast/TV is off.
Or when nobody is home for more then 1hr and Chromecast/TV is off then switch OFF TV standby killer (KaKu unit)
Re: Chromecast status
Posted: Wednesday 24 June 2015 13:49
by jannl
ok, your tv has not network connection? That would make sense.
Re: Chromecast status
Posted: Wednesday 24 June 2015 13:50
by Siewert308SW
jan_nl wrote:ok, your tv has not network connection? That would make sense.
Indeed, my TV doesn't have network connection and there for the Chromecast solves that issue

Re: Chromecast status
Posted: Monday 11 January 2016 18:17
by Heisenberg
Does someone know if it's possible to start a stream through Chromecast (audio) via Domoticz?
Re: Chromecast status
Posted: Monday 11 January 2016 22:20
by wmn79
Heisenberg wrote:Does someone know if it's possible to start a stream through Chromecast (audio) via Domoticz?
I don't know it but this repository was posted in the tweakers domoticz topic last week by user zeu:
https://github.com/balloob/pychromecast
He has created a simple web interface himself to use with it and put it here:
https://github.com/roberthorlings/chromecast-web maybe you can use these repositories to create your wanted situation.
Re: Chromecast status
Posted: Friday 12 February 2016 11:01
by daandamhuis
wmn79 wrote:Heisenberg wrote:Does someone know if it's possible to start a stream through Chromecast (audio) via Domoticz?
I don't know it but this repository was posted in the tweakers domoticz topic last week by user zeu:
https://github.com/balloob/pychromecast
He has created a simple web interface himself to use with it and put it here:
https://github.com/roberthorlings/chromecast-web maybe you can use these repositories to create your wanted situation.
I'll give it a try Sunday, or maybe tonight.
Re: Chromecast status
Posted: Friday 19 February 2016 11:06
by tbowmo
Another possible scenario is, that when you start playback on chromecast it could dim down the lights automatically, and if the playback is paused, it could turn up the lights to normal levels..
Right now I have almost accomplished this, with pychromecast reporting into domoticz, and setting a dummy light switch according to play state. Works for most casts. Except netflix, it doesn't report back pause events (only play events, even when returning from pause state).
Right now I don't have any lights connected to domoticz (have it planned though). So I'm not pursuing netflix support actively at the moment. But I'm in the planning state of installing controllable led strips.
Re: Chromecast status
Posted: Friday 19 February 2016 11:22
by daandamhuis
tbowmo wrote:Another possible scenario is, that when you start playback on chromecast it could dim down the lights automatically, and if the playback is paused, it could turn up the lights to normal levels..
Do you have an example script?
Re: Chromecast status
Posted: Saturday 20 February 2016 18:44
by tbowmo
downloaded pychromecast from github
https://github.com/balloob/pychromecast
and then using the following python script
Code: Select all
from __future__ import print_function
import time
import sys
import logging
import json
import codecs
from urllib.request import urlopen
from urllib.parse import urlencode
import pychromecast
import pychromecast.controllers.youtube as youtube
domoticz = "http://localhost:8080"
if '--show-debug' in sys.argv:
logging.basicConfig(level=logging.DEBUG)
cast = pychromecast.get_chromecast()
class mediaListener:
domurl="http://localhost:8080"
device=20
def __init__(self, domoticzurl, deviceno):
self.domurl = domoticzurl
self.device=deviceno
self.oldPlayerStatus = 'NONE'
def new_media_status(self, status):
print("mediaListener")
print(status)
if (self.oldPlayerStatus != status.player_state):
self.oldPlayerStatus = status.player_state
if status.player_state == "PLAYING" or status.player_state == "BUFFERING":
data = urlopen(self.domurl+"/json.htm?type=command¶m=switchlight&idx="+self.device+"&switchcmd=on")
else :
data = urlopen(self.domurl+"/json.htm?type=command¶m=switchlight&idx="+self.device+"&switchcmd=off")
self.storeVariable('ChromeState', new_state)
def storeVariable(self,name, value):
value = urlencode({'vvalue':value, 'vname':name, 'vtype':2})
d = urlopen(self.domurl+'/json.htm?type=command¶m=updateuservariable&'+value)
reader = codecs.getreader("utf-8")
obj = json.load(reader(d))
if (obj['status'] == 'ERR'):
d = urlopen(self.domurl+'/json.htm?type=command¶m=saveuservariable&'+value)
listener = mediaListener(domoticz, 106)
cast.media_controller.register_status_listener(listener)
while (1):
pass
It's a draft and seems to work.. Setting a virtual switch on / off, according to the playing state. And also populates a uservariable with the current state.
I don't have any lights connected, so haven't checked how well this works.. (The lights are in development..)
Re: Chromecast status
Posted: Sunday 21 February 2016 0:13
by Varazir
tbowmo wrote:downloaded pychromecast from github
https://github.com/balloob/pychromecast
and then using the following python script
Code: Select all
from __future__ import print_function
import time
import sys
import logging
import json
import codecs
from urllib.request import urlopen
from urllib.parse import urlencode
import pychromecast
import pychromecast.controllers.youtube as youtube
domoticz = "http://localhost:8080"
if '--show-debug' in sys.argv:
logging.basicConfig(level=logging.DEBUG)
cast = pychromecast.get_chromecast()
class mediaListener:
domurl="http://localhost:8080"
device=20
def __init__(self, domoticzurl, deviceno):
self.domurl = domoticzurl
self.device=deviceno
self.oldPlayerStatus = 'NONE'
def new_media_status(self, status):
print("mediaListener")
print(status)
if (self.oldPlayerStatus != status.player_state):
self.oldPlayerStatus = status.player_state
if status.player_state == "PLAYING" or status.player_state == "BUFFERING":
data = urlopen(self.domurl+"/json.htm?type=command¶m=switchlight&idx="+self.device+"&switchcmd=on")
else :
data = urlopen(self.domurl+"/json.htm?type=command¶m=switchlight&idx="+self.device+"&switchcmd=off")
self.storeVariable('ChromeState', new_state)
def storeVariable(self,name, value):
value = urlencode({'vvalue':value, 'vname':name, 'vtype':2})
d = urlopen(self.domurl+'/json.htm?type=command¶m=updateuservariable&'+value)
reader = codecs.getreader("utf-8")
obj = json.load(reader(d))
if (obj['status'] == 'ERR'):
d = urlopen(self.domurl+'/json.htm?type=command¶m=saveuservariable&'+value)
listener = mediaListener(domoticz, 106)
cast.media_controller.register_status_listener(listener)
while (1):
pass
It's a draft and seems to work.. Setting a virtual switch on / off, according to the playing state. And also populates a uservariable with the current state.
I don't have any lights connected, so haven't checked how well this works.. (The lights are in development..)
Are you running on a raspberry pi? Looks like I have python 2.7 on my Pi and the script is made for 3 right ?
Re: Chromecast status
Posted: Sunday 21 February 2016 9:50
by daandamhuis
Varazir wrote:tbowmo wrote:downloaded pychromecast from github
https://github.com/balloob/pychromecast
and then using the following python script
Code: Select all
from __future__ import print_function
import time
import sys
import logging
import json
import codecs
from urllib.request import urlopen
from urllib.parse import urlencode
import pychromecast
import pychromecast.controllers.youtube as youtube
domoticz = "http://localhost:8080"
if '--show-debug' in sys.argv:
logging.basicConfig(level=logging.DEBUG)
cast = pychromecast.get_chromecast()
class mediaListener:
domurl="http://localhost:8080"
device=20
def __init__(self, domoticzurl, deviceno):
self.domurl = domoticzurl
self.device=deviceno
self.oldPlayerStatus = 'NONE'
def new_media_status(self, status):
print("mediaListener")
print(status)
if (self.oldPlayerStatus != status.player_state):
self.oldPlayerStatus = status.player_state
if status.player_state == "PLAYING" or status.player_state == "BUFFERING":
data = urlopen(self.domurl+"/json.htm?type=command¶m=switchlight&idx="+self.device+"&switchcmd=on")
else :
data = urlopen(self.domurl+"/json.htm?type=command¶m=switchlight&idx="+self.device+"&switchcmd=off")
self.storeVariable('ChromeState', new_state)
def storeVariable(self,name, value):
value = urlencode({'vvalue':value, 'vname':name, 'vtype':2})
d = urlopen(self.domurl+'/json.htm?type=command¶m=updateuservariable&'+value)
reader = codecs.getreader("utf-8")
obj = json.load(reader(d))
if (obj['status'] == 'ERR'):
d = urlopen(self.domurl+'/json.htm?type=command¶m=saveuservariable&'+value)
listener = mediaListener(domoticz, 106)
cast.media_controller.register_status_listener(listener)
while (1):
pass
It's a draft and seems to work.. Setting a virtual switch on / off, according to the playing state. And also populates a uservariable with the current state.
I don't have any lights connected, so haven't checked how well this works.. (The lights are in development..)
Are you running on a raspberry pi? Looks like I have python 2.7 on my Pi and the script is made for 3 right ?
I Changed
Code: Select all
from urllib.request import urlopen
from urllib.parse import urlencode
to and now it works with Python 2.7
Re: Chromecast status
Posted: Sunday 21 February 2016 10:00
by Varazir
daandamhuis wrote:
I Changed
Code: Select all
from urllib.request import urlopen
from urllib.parse import urlencode
to and now it works with Python 2.7
Got one more step forward.
I guess I have to do something more as it's not finding the
Code: Select all
Traceback (most recent call last):
File "chromecast.py", line 10, in <module>
import pychromecast
ImportError: No module named pychromecast
I cloned the git and run the pip requirement installer step.
Re: Chromecast status
Posted: Sunday 21 February 2016 10:33
by daandamhuis
Did you place the Python script inside the Pychromecast folder? That did the trick for me.
Re: Chromecast status
Posted: Sunday 21 February 2016 13:19
by Varazir
daandamhuis wrote:Did you place the Python script inside the Pychromecast folder? That did the trick for me.
I got it to work sort of:
Code: Select all
~/pychromecast $ python chromecast.py
mediaListener
<MediaStatus {'player_state': u'PLAYING', 'volume_level': 1, 'images': [], 'media_custom_data': {}, 'duration': 2546, 'current_time': 841.182, 'playback_rate': 1, 'title': None, 'media_session_id': 1, 'volume_muted': False, 'supports_skip_forward': False, 'track': None, 'season': None, 'idle_reason': None, 'stream_type': u'BUFFERED', 'supports_stream_mute': False, 'supports_stream_volume': False, 'content_type': u'video/mp4', 'metadata_type': None, 'subtitle_tracks': {}, 'album_name': None, 'series_title': None, 'album_artist': None, 'media_metadata': {}, 'episode': None, 'artist': None, 'supported_media_commands': 1, 'supports_seek': False, 'content_id': u'http://dummy', 'supports_skip_backward': False, 'supports_pause': True}>
But nothing happens on my domoticz
I changed this in the script
Code: Select all
domoticz = "http://localhost:80"
domurl="http://localhost:80"
device=33
Anything ells I need to change?
Edit: I saw that the script is maxing out the CPU
Re: Chromecast status
Posted: Wednesday 24 February 2016 23:49
by tbowmo
I'm not here on this forum that often..
Anyway, it's a work in progress. Running on a pi2, so don't notice that one core is maxed out by the script. But yes dome kind of wait loop should be made instead of the current while loop, so it doesn't use max cpu.
And yes I'm using it with python3. I have both python 2.7 and 3.4 installed.
Re: Chromecast status
Posted: Saturday 23 April 2016 21:26
by Heisenberg
I installed pychromecast but cannot seem to find the folder. Do I really need to put the python script inside this folder to run?
Re: Chromecast status
Posted: Sunday 11 December 2016 11:21
by turnhob
Im trying to get this working.
But i am keeping getting this error
Code: Select all
Traceback (most recent call last):
File "D:\Domoticz\Scripts\PyChromecast\ChromeStatus.py", line 49, in <module>
cast.media_controller.register_status_listener(listener)
AttributeError: 'NoneType' object has no attribute 'media_controller'
Im not a python programmer. I can read code but im not good at wrtiting.
So if you could give me a hint that would be very helpfull
(using raspberry pi2 and python 2).