I think this would be a nice feature to have, since I could automatically turn my receiver on when the chromecast is playing, and turn it of when it has stopped.
pychromecast seems to be very helpful:
import pychromecast
cast = pychromecast.Chromecast("192.168.x.x")
mc = cast.media_controller
print(mc.status)
returns a nice object containing lots of useful information that could be parsed and fed back to pimatic, most importantly player_state…
<MediaStatus {'player_state': u'PLAYING', 'volume_level': 1, 'images': [], 'media_custom_data': {}, 'duration': 0, 'current_time': 1319.641, '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': True, 'supports_stream_volume': True, 'content_type': u'', 'metadata_type': None, 'subtitle_tracks': [{u'trackId': 0, u'type': u'TEXT', u'language': u'en-US'}], 'album_name': None, 'series_title': None, 'album_artist': None, 'media_metadata': {}, 'episode': None, 'artist': None, 'supported_media_commands': 15, 'supports_seek': True, 'current_subtitle_tracks': [0], 'content_id': u'http://api.netflix.com/catalog/titles/series/70281312', 'supports_skip_backward': False, 'supports_pause': True}>
This always stays False though:
cast.status.is_active_input
False
If I can help to develop something useful let me know.
I made a simple script python which turns the dummy presence sensor chromecast-playing on or off.
#!/usr/bin/python
import pychromecast
import time
import os
cast = pychromecast.Chromecast("192.168.x.x")
mc = cast.media_controller
time.sleep(1)
count = 0
while (count < 9):
cast = pychromecast.Chromecast("192.168.x.x")
mc = cast.media_controller
#print(cast.device)
time.sleep(1)
testoutput = mc.status
testoutput = str(testoutput)
cast.disconnect()
print(testoutput)
if ( "PAUSED" in testoutput or "PLAYING" in testoutput or "IDLE" in testoutput):
print("playing")
os.system('curl -s xxxx/api/device/chromecast-playing/changePresenceTo?presence=true')
while ( "PAUSED" in testoutput or "PLAYING" in testoutput or "IDLE" in testoutput or "BUFFERING" in testoutput):
time.sleep(1)
cast = pychromecast.Chromecast("192.168.x.x")
mc = cast.media_controller
time.sleep(1)
testoutput = mc.status
testoutput = str(testoutput)
cast.disconnect()
if "UNKNOWN" in testoutput:
print("not playing")
os.system('curl -s xxxx/api/device/chromecast-playing/changePresenceTo?presence=false')
while ("UNKNOWN" in testoutput):
time.sleep(1)
cast = pychromecast.Chromecast("192.168.x.x")
mc = cast.media_controller
time.sleep(1)
testoutput = mc.status
testoutput = str(testoutput)
cast.disconnect()