@suchalaugh According to the docs it is possible to query the status of a connected device. If you’re familiar with scripting you can explore this yourself, e.g., by using https://github.com/balloob/pychromecast . The example given as part of the README describes how to query the status. If this is any useful and your requests gets reasonably upvoted, we can use your findings to draft a plugin.
-
Read Chromecast State
"It always takes longer than you expect, even when you take into account Hofstadter's Law.", Hofstadter's Law
-
Thanks for your highly appreciated answers.
Unfortunately I have neither an idea of developing in general nor scripting specially.
So I’m quite dependent on a motivated developer here. I hope that I’m not alone with this special wish:)Thanks a lot again! Good to know, that it is basically possible!
-
Another option is to checkout CastNow which is already in node.js. So already it is much closer to pimatic than the python example. Take a look/read at this post which is giving examples from the command line. I already understand that you don’t want that, but being node.js based it should be easier to implement a plugin.
-
@Harry-van-der-Wolf Those CastNow player controls are really nice to have !
Pimatic could work independently as a remote for the usual tasks and there would be less need for using the app running on the Chromecast.
player controls:
space // toggle between play and pause
m // toggle mute
up // volume up
down // volume down
left // seek backward (keep pressed / multiple press for faster seek)
right // seek forward (keep pressed / multiple press for faster seek)
n // next item in the playlist (only supported in launch-mode)
s // stop playback
q // quit -
Athom’s Home automation device “Homey” is based on node.js, they have a chromecast plugin also:
-
Any news here?
pimatic + MySensors + Homeduino + z-way
https://github.com/n3roGit/MySensors_n3ro -
@n3ro said in Read Chromecast State:
Any news here?
Did you have a kook at https://github.com/balloob/pychromecast?
"It always takes longer than you expect, even when you take into account Hofstadter's Law.", Hofstadter's Law
-
@mwittig yes. But don’t bring it to work
pimatic + MySensors + Homeduino + z-way
https://github.com/n3roGit/MySensors_n3ro -
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()
-
Hi, I recently got this working using a few scripts:
It uses the Castnow program and to make things a little bit easier, it also uses the castnow control program.
Since castnow opens very slowly (about 10 seconds), the script uses the ‘screen’ program to keep castnow open. Now commands can be send to the castnow that are executed almost instantly.
In pimatic I used a ShellSensor to display the now-playing and a few buttons with rules to control the chromecast.
The device to check the state is the following:{ "attributeName": "state", "attributeType": "string", "command": "/home/pi/castnow_control/castnow_get_state.sh | grep Source |sed 's/Source: //g''", "id": "chromecast-audio-state", "name": "Chromecast now playing", "class": "ShellSensor", }
I have no experience with making a plugin, but all it should do is install castnow, screen and castnow_control. Note that configuring the castnow_control was a bit of trouble since it couldn’t find the screen program and I have multiple chromecasts so this had to be changed in the configuration file.
-
@tnederlof19 i am getting;
Pipo@rasp:/home/pi/pimatic-app/scripts/castnow_control# ./castnow_get_state.sh No screen session found. cat: /home/pi/hardcopy_castnow_screen: Bestand of map bestaat niet <file/folder doesnt excist cat: /home/pi/hardcopy_castnow_screen: Bestand of map bestaat niet <file/folder doesnt excist State: Source: Pipo@rasp:/home/pi/pimatic-app/scripts/castnow_control#
Any idea?
-
@Gleno0h I also had a bit of struggle to get the castnow script running, make sure you check out the configuration (castnow_scripts.cfg). In my case it couldn’t find the location of the screen program, find it with the command: “whereis screen”.
Casnow uses a temp file, the hardcopy file, to store the screens output, make sure this location is writable. -
@tnederlof19 after making some modifications to the watchdog and added the correct path to castnow it worked but keeps telling me “connecting”… Castnow cant find my chromecast, i think because it is on another router or something…
Non the less, castnow_control only would show what i start through that app, and not what i cast via my phone, right? Would be useless for me then
-
In case anyone is still looking for Chromecast integration: I just released the pimatic-chromecast plugin: https://forum.pimatic.org/topic/4771/pimatic-chromecast