Giter Site home page Giter Site logo

nohum / chromecast-mqtt-connector Goto Github PK

View Code? Open in Web Editor NEW
46.0 11.0 21.0 71 KB

Make your Chromecast devices discoverable and controllable via MQTT.

License: Mozilla Public License 2.0

Python 100.00%
chromecast chromecast-device python python3 cast internet-of-things mqtt mqtt-service

chromecast-mqtt-connector's People

Contributors

berryk avatar decke avatar nohum avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chromecast-mqtt-connector's Issues

Possible problem with spaces in friendly_name

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

Bad management of relative volume

In handler/properties.py, line 185, should be
is_relative = payload[0] == "-" or payload[0] == "+"
instead of
is_relative = payload[0] == "-" or payload[1] == "+"

Support for audio groups

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?).

Song without album art prevents successful update of media status

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'

ImportError: cannot import name 'get_chromecast'

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 available through MQTT

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

Use absolut Path for config.ini

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')

How to use

Hello,

Please I don't understand how to use your code?

Can you kindly tell me what and what I need to do?

regards

Play command is not sent to chromecast

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.