Chromecast status

Use this forum to discuss possible implementation of a new feature before opening a ticket.
A developer shall edit the topic title with "[xxx]" where xxx is the id of the accompanying tracker id.
Duplicate posts about the same id. +1 posts are not allowed.

Moderators: leecollings, remb0

piotr
Posts: 26
Joined: Monday 15 July 2013 8:17
Target OS: Linux
Domoticz version: Beta
Location: Drenthe
Contact:

Chromecast status

Post 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 ?
jannl
Posts: 625
Joined: Thursday 02 October 2014 6:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Geleen
Contact:

Re: Chromecast status

Post by jannl »

Hm I have a chromecast. Why would you want to see the chromecast status?
piotr
Posts: 26
Joined: Monday 15 July 2013 8:17
Target OS: Linux
Domoticz version: Beta
Location: Drenthe
Contact:

Re: Chromecast status

Post 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 :)
User avatar
Siewert308SW
Posts: 288
Joined: Monday 29 December 2014 15:47
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

Re: Chromecast status

Post 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)
Setup:
- RPi4 - Domo Stable / Aeotec Z-stick7 / PiHole Unbound Gemini
- RPi4 - PiHole / PiVPN Unbound Gemini
- Synology DS923+ / DS218j
- P1 Gas/Power, SmartGateway watermeter
- Fibaro switches, contacts, plugs, smoke/Co2 ect
- rootfs @ USB HDD
jannl
Posts: 625
Joined: Thursday 02 October 2014 6:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Geleen
Contact:

Re: Chromecast status

Post by jannl »

ok, your tv has not network connection? That would make sense.
User avatar
Siewert308SW
Posts: 288
Joined: Monday 29 December 2014 15:47
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

Re: Chromecast status

Post 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 ;-)
Setup:
- RPi4 - Domo Stable / Aeotec Z-stick7 / PiHole Unbound Gemini
- RPi4 - PiHole / PiVPN Unbound Gemini
- Synology DS923+ / DS218j
- P1 Gas/Power, SmartGateway watermeter
- Fibaro switches, contacts, plugs, smoke/Co2 ect
- rootfs @ USB HDD
Heisenberg
Posts: 135
Joined: Monday 27 January 2014 14:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Chromecast status

Post by Heisenberg »

Does someone know if it's possible to start a stream through Chromecast (audio) via Domoticz?
Raspberry Pi Type B
Raspberry Pi Type B2
RFXCOMtrx433e
wmn79
Posts: 27
Joined: Monday 13 April 2015 23:19
Target OS: NAS (Synology & others)
Domoticz version: 3.5033
Location: Amsterdam, The Netherlands
Contact:

Re: Chromecast status

Post 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.
daandamhuis
Posts: 19
Joined: Tuesday 19 January 2016 10:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.4608
Location: 's-Hertogenbosch
Contact:

Re: Chromecast status

Post 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.
RPi Model 2: Domoticz Server (Beta)
RPi Model B+: Smart Meter Slave (Stable)
Particle Photon (2x): Prototyping, Controlling LEDS and gathering Sensor data for Domoticz
Arduino Uno R3: with CC2500 Shield for Philips LivingColor Lights 1st Gen.
tbowmo
Posts: 7
Joined: Thursday 11 June 2015 13:50
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.2480
Location: Denmark
Contact:

Re: Chromecast status

Post 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.
Mysensors HW developer / hacker.
Creator of Sensebender Micro temperature / humidity sensor
daandamhuis
Posts: 19
Joined: Tuesday 19 January 2016 10:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.4608
Location: 's-Hertogenbosch
Contact:

Re: Chromecast status

Post 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?
RPi Model 2: Domoticz Server (Beta)
RPi Model B+: Smart Meter Slave (Stable)
Particle Photon (2x): Prototyping, Controlling LEDS and gathering Sensor data for Domoticz
Arduino Uno R3: with CC2500 Shield for Philips LivingColor Lights 1st Gen.
tbowmo
Posts: 7
Joined: Thursday 11 June 2015 13:50
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.2480
Location: Denmark
Contact:

Re: Chromecast status

Post 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&param=switchlight&idx="+self.device+"&switchcmd=on")
            else :
                data = urlopen(self.domurl+"/json.htm?type=command&param=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&param=updateuservariable&'+value)
        reader = codecs.getreader("utf-8")
        obj = json.load(reader(d))
        if (obj['status'] == 'ERR'):
            d = urlopen(self.domurl+'/json.htm?type=command&param=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..)
Mysensors HW developer / hacker.
Creator of Sensebender Micro temperature / humidity sensor
User avatar
Varazir
Posts: 360
Joined: Friday 20 February 2015 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Chromecast status

Post 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&param=switchlight&idx="+self.device+"&switchcmd=on")
            else :
                data = urlopen(self.domurl+"/json.htm?type=command&param=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&param=updateuservariable&'+value)
        reader = codecs.getreader("utf-8")
        obj = json.load(reader(d))
        if (obj['status'] == 'ERR'):
            d = urlopen(self.domurl+'/json.htm?type=command&param=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 ?
Raspberry PI 2 with RaZberry Controller 2016 ZWave+ and CC2531(zigbee)
Several IKEA devices/z-wave devices
daandamhuis
Posts: 19
Joined: Tuesday 19 January 2016 10:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.4608
Location: 's-Hertogenbosch
Contact:

Re: Chromecast status

Post 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&param=switchlight&idx="+self.device+"&switchcmd=on")
            else :
                data = urlopen(self.domurl+"/json.htm?type=command&param=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&param=updateuservariable&'+value)
        reader = codecs.getreader("utf-8")
        obj = json.load(reader(d))
        if (obj['status'] == 'ERR'):
            d = urlopen(self.domurl+'/json.htm?type=command&param=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

Code: Select all

import urllib
RPi Model 2: Domoticz Server (Beta)
RPi Model B+: Smart Meter Slave (Stable)
Particle Photon (2x): Prototyping, Controlling LEDS and gathering Sensor data for Domoticz
Arduino Uno R3: with CC2500 Shield for Philips LivingColor Lights 1st Gen.
User avatar
Varazir
Posts: 360
Joined: Friday 20 February 2015 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Chromecast status

Post 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

Code: Select all

import urllib
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.
Raspberry PI 2 with RaZberry Controller 2016 ZWave+ and CC2531(zigbee)
Several IKEA devices/z-wave devices
daandamhuis
Posts: 19
Joined: Tuesday 19 January 2016 10:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.4608
Location: 's-Hertogenbosch
Contact:

Re: Chromecast status

Post by daandamhuis »

Did you place the Python script inside the Pychromecast folder? That did the trick for me.
RPi Model 2: Domoticz Server (Beta)
RPi Model B+: Smart Meter Slave (Stable)
Particle Photon (2x): Prototyping, Controlling LEDS and gathering Sensor data for Domoticz
Arduino Uno R3: with CC2500 Shield for Philips LivingColor Lights 1st Gen.
User avatar
Varazir
Posts: 360
Joined: Friday 20 February 2015 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Chromecast status

Post 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
Raspberry PI 2 with RaZberry Controller 2016 ZWave+ and CC2531(zigbee)
Several IKEA devices/z-wave devices
tbowmo
Posts: 7
Joined: Thursday 11 June 2015 13:50
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.2480
Location: Denmark
Contact:

Re: Chromecast status

Post 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.
Mysensors HW developer / hacker.
Creator of Sensebender Micro temperature / humidity sensor
Heisenberg
Posts: 135
Joined: Monday 27 January 2014 14:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Chromecast status

Post 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?
Raspberry Pi Type B
Raspberry Pi Type B2
RFXCOMtrx433e
turnhob
Posts: 7
Joined: Sunday 11 December 2016 9:44
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Chromecast status

Post 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).
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest