nohum / chromecast-mqtt-connector Goto Github PK
View Code? Open in Web Editor NEWMake your Chromecast devices discoverable and controllable via MQTT.
License: Mozilla Public License 2.0
Make your Chromecast devices discoverable and controllable via MQTT.
License: Mozilla Public License 2.0
Only one of my devices is available via MQTT.
This might be due to a space in one of the Chromecast's friendly name Simon's Zimmer
:
INFO:event:added device Simon's Zimmer
ERROR:mqtt:value conversion error
Traceback (most recent call last):
File "/Users/simon/Applications/Chromecast-MQTT-Connector/handler/properties.py", line 114, in _write
self.mqtt.send_message(formatted_topic, value)
AttributeError: 'NoneType' object has no attribute 'send_message'
I've no idea what's wrong with line 114, but Python isn't my best language, either.
Full debug output (I deleted the ID values Chromecast-Audio-AAA._googlecast._tcp.local.
, because I don't know if my devices can be globally accessed knowing this value or something):
Seim:Chromecast-MQTT-Connector simon$ python3 connector.py
DEBUG:__main__:~ reading config
INFO:config:config file path: /Users/simon/Applications/Chromecast-MQTT-Connector/config.ini
INFO:config:config file has been found
DEBUG:__main__:~ connecting to mqtt
DEBUG:__main__:~ starting chromecast discovery
DEBUG:discovery:starting discovery
DEBUG:__main__:~ initialization finished
INFO:discovery:adding chromecast with name "Chromecast-Audio-AAA._googlecast._tcp.local."
INFO:discovery:chromecast device name "Simon's Zimmer"
INFO:discovery:adding chromecast with name "Chromecast-Audio-BBB._googlecast._tcp.local."
INFO:discovery:chromecast device name "Wohnzimmer"
INFO:discovery:adding chromecast with name "Google-Cast-Group-CCC._googlecast._tcp.local."
INFO:discovery:chromecast device name "(All Speakers)"
INFO:event:added device Simon's Zimmer
ERROR:mqtt:value conversion error
Traceback (most recent call last):
File "/Users/simon/Applications/Chromecast-MQTT-Connector/handler/properties.py", line 114, in _write
self.mqtt.send_message(formatted_topic, value)
AttributeError: 'NoneType' object has no attribute 'send_message'
INFO:event:added device Wohnzimmer
ERROR:mqtt:value conversion error
Traceback (most recent call last):
File "/Users/simon/Applications/Chromecast-MQTT-Connector/handler/properties.py", line 114, in _write
self.mqtt.send_message(formatted_topic, value)
AttributeError: 'NoneType' object has no attribute 'send_message'
DEBUG:mqtt:connected to mqtt with result code 0
DEBUG:event:mqtt connected callback has been invoked
DEBUG:mqtt:subscribing to topic chromecast/+/command/volume_level
DEBUG:mqtt:subscribing to topic chromecast/+/command/volume_muted
DEBUG:mqtt:subscribing to topic chromecast/+/command/player_position
DEBUG:mqtt:subscribing to topic chromecast/+/command/player_state
DEBUG:event:mqtt topics have been subscribed
INFO:event:added device (All Speakers)
ERROR:mqtt:value conversion error
Traceback (most recent call last):
File "/Users/simon/Applications/Chromecast-MQTT-Connector/handler/properties.py", line 114, in _write
self.mqtt.send_message(formatted_topic, value)
AttributeError: 'NoneType' object has no attribute 'send_message'
INFO:discovery:adding chromecast with name "Chromecast-Audio-DDD._googlecast._tcp.local."
INFO:discovery:chromecast device name "Badezimmer"
INFO:event:added device Badezimmer
DEBUG:mqtt:sending topic chromecast/Badezimmer/connection_status with value "WAITING"
INFO:pychromecast:Querying device status
INFO:pychromecast:Querying device status
DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): 10.1.1.133
DEBUG:urllib3.connectionpool:Starting new HTTP connection (2): 10.1.1.133
INFO:pychromecast:Querying device status
DEBUG:urllib3.connectionpool:Starting new HTTP connection (3): 10.1.1.133
DEBUG:urllib3.connectionpool:http://10.1.1.133:8008 "GET /ssdp/device-desc.xml HTTP/1.1" 200 1086
DEBUG:urllib3.connectionpool:http://10.1.1.133:8008 "GET /ssdp/device-desc.xml HTTP/1.1" 200 1086
DEBUG:urllib3.connectionpool:http://10.1.1.133:8008 "GET /ssdp/device-desc.xml HTTP/1.1" 200 1086
DEBUG:pychromecast.controllers:Receiver:Updating status
DEBUG:root:Thread started...
INFO:pychromecast:Querying device status
DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): 10.1.1.30
DEBUG:urllib3.connectionpool:http://10.1.1.30:8008 "GET /ssdp/device-desc.xml HTTP/1.1" 200 1077
DEBUG:pychromecast.controllers:Receiver:Updating status
DEBUG:root:Thread started...
INFO:pychromecast:Querying device status
DEBUG:urllib3.connectionpool:http://10.1.1.30:8008 "GET /ssdp/device-desc.xml HTTP/1.1" 200 1077
DEBUG:pychromecast.controllers:Receiver:Updating status
DEBUG:root:Thread started...
INFO:pychromecast:Querying device status
DEBUG:urllib3.connectionpool:http://10.1.1.30:8008 "GET /ssdp/device-desc.xml HTTP/1.1" 200 1077
INFO:pychromecast:Querying device status
In handler/properties.py, line 185, should be
is_relative = payload[0] == "-" or payload[0] == "+"
instead of
is_relative = payload[0] == "-" or payload[1] == "+"
At the moment audio groups are not supported because they have the same IP as one of the devices.
Do you think its possible to use the friendly_name instead?
Also the player_state and some other propeties of the single devices are not correct if i stream something to a group (Maybe this is a limitation of pychromecast?).
Listening to a song without album or a cover art lets the MQTT update code fail because a expected key is missing within the data:
ERROR:chromecast:command CastMediaStatus(status=<MediaStatus {'metadata_type': 3, 'title': "xxx", 'series_title': None, 'season': None, 'episode': None, 'artist': 'xxx', 'album_name': '', 'album_artist': 'xxx', 'track': None, 'subtitle_tracks': {}, 'images': [MediaImage(url=None, height=0, width=0)], 'supports_pause': True, 'supports_seek': True, 'supports_stream_volume': True, 'supports_stream_mute': True, 'supports_skip_forward': False, 'supports_skip_backward': False, 'current_time': 0.591299, 'content_id': 'xxx', 'content_type': 'audio/mpeg', 'duration': 272.79200000000003, 'stream_type': 'BUFFERED', 'idle_reason': 'INTERRUPTED', 'media_session_id': 37, 'playback_rate': 1, 'player_state': 'BUFFERING', 'supported_media_commands': 207, 'volume_level': 1, 'volume_muted': False, 'media_custom_data': {}, 'media_metadata': {'metadataType': 3, 'title': "xxx", 'albumName': '', 'albumArtist': 'xxx', 'artist': 'xxx', 'images': [{'height': 0, 'width': 0}]}, 'current_subtitle_tracks': []}>) failed
Traceback (most recent call last):
File "/home/x/PycharmProjects/chromecast-mqtt-connector/handler/adapter.py", line 204, in _worker
self._worker_cast_media_status(item.status)
File "/home/x/PycharmProjects/chromecast-mqtt-connector/handler/adapter.py", line 389, in _worker_cast_media_status
image_filtered = image["url"]
KeyError: 'url'
When trying to call connector.py I get the following error:
Traceback (most recent call last):
File "./connector.py", line 4, in <module>
from handler.event import EventHandler
File "/home/stephan/chromecast_mqtt/chromecast-mqtt-connector/handler/event.py", line 1, in <module>
from handler.adapter import ChromecastConnection, ChromecastConnectionCallback
File "/home/stephan/chromecast_mqtt/chromecast-mqtt-connector/handler/adapter.py", line 2, in <module>
from pychromecast import get_chromecast, ChromecastConnectionError, IDLE_APP_ID
ImportError: cannot import name 'get_chromecast'
Output of pip3 freeze:
enum-compat==0.0.2
netifaces==0.10.4
numpy==1.8.2
paho-mqtt==1.2.1
Pillow==2.6.1
protobuf==3.2.0
PyChromecast==0.8.1
requests==2.13.0
RTIMULib==7.2.1
sense-hat==2.2.0
six==1.10.0
zeroconf==0.19.0
Problematic line seems to be:
from handler.event import EventHandler
Since I am not a python guy I have no clue how to fix it.
Regards,
Stephan
friendly_name not published - everything else is there. Publishing controls does also work:
(I have two CC - one is @ 192.168.0.117)
pi@smarthome:~ $ mosquitto_sub -v -t "chromecast/192.168.0.117/#"
chromecast/192.168.0.117/connection_status CONNECTED
chromecast/192.168.0.117/current_app TuneIn Free
chromecast/192.168.0.117/volume_level 100
chromecast/192.168.0.117/volume_muted 0
chromecast/192.168.0.117/player_state PAUSED
chromecast/192.168.0.117/player_position 41
chromecast/192.168.0.117/media/title Corinne Bailey Rae - The Scientist (Fifty Shades Darker [Original Motion Picture Soundtrack])
chromecast/192.168.0.117/media/images http://cdn-albums.tunein.com/gn/066DWXTHDLg.jpg
chromecast/192.168.0.117/media/content_type audio/mp3
chromecast/192.168.0.117/media/content_url http://stream.srg-ssr.ch/m/rsp/mp3_128
Regards,
Stephan
If you run the service from a working directory other than the connector.py path we need an aboslout path to the config.ini.
For now i solved it like this:
os.path.join(os.path.abspath(os.path.dirname(__file__)), 'config.ini')
Hello,
Please I don't understand how to use your code?
Can you kindly tell me what and what I need to do?
regards
After several connection retries the application ends up with a chromecast object where it thinks that it is connected, but it isn't. In the end, controlling the chromecast does not work:
May 10 19:05:14 rouven chromecast[21369]: INFO:pychromecast.controllers:Receiver:Launching app CC1AD845
May 10 19:05:34 rouven chromecast[21369]: WARNING:pychromecast.socket_client:Heartbeat timeout, resetting connection
May 10 19:06:05 rouven chromecast[21369]: ERROR:pychromecast.socket_client:Failed to connect, retrying in 5.000000s
May 10 19:06:05 rouven chromecast[21369]: Traceback (most recent call last):
May 10 19:06:05 rouven chromecast[21369]: File "/usr/local/lib/python3.4/dist-packages/pychromecast/socket_client.py", line 239, in initialize_connection
May 10 19:06:05 rouven chromecast[21369]: self.socket.connect((self.host, self.port))
May 10 19:06:05 rouven chromecast[21369]: File "/usr/lib/python3.4/ssl.py", line 840, in connect
May 10 19:06:05 rouven chromecast[21369]: self._real_connect(addr, False)
May 10 19:06:05 rouven chromecast[21369]: File "/usr/lib/python3.4/ssl.py", line 827, in _real_connect
May 10 19:06:05 rouven chromecast[21369]: socket.connect(self, addr)
May 10 19:06:05 rouven chromecast[21369]: socket.timeout: timed out
May 10 19:07:16 rouven chromecast[21369]: INFO:discovery:removing chromecast with name "Chromecast-Audio-xxxxxx_googlecast._tcp.local."
May 10 19:07:16 rouven chromecast[21369]: WARNING:event:device 192.168.xx.xx is still connected and not removed
May 10 19:09:11 rouven chromecast[21369]: ERROR:pychromecast.socket_client:Failed to connect. No retries.
May 10 19:40:05 rouven chromecast[21369]: DEBUG:mqtt:received mqtt publish of chromecast/192.168.xx.xx/command/player_state with data "b'["http://stream.url", "audio/mpeg"]'"
May 10 19:40:05 rouven chromecast[21369]: DEBUG:event:found device to handle mqtt message
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.