{"id":13586250,"url":"https://github.com/tbowmo/chrome2mqtt","last_synced_at":"2025-06-11T23:03:48.164Z","repository":{"id":39706277,"uuid":"80116748","full_name":"tbowmo/chrome2mqtt","owner":"tbowmo","description":"python script to bring chromecast and mqtt together","archived":false,"fork":false,"pushed_at":"2024-02-25T09:17:30.000Z","size":156,"stargazers_count":21,"open_issues_count":1,"forks_count":7,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-02-26T08:41:13.895Z","etag":null,"topics":["chromecast","chromecasts","docker-container","home-automation","mqtt","python-script","python3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tbowmo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-01-26T13:27:36.000Z","updated_at":"2024-08-01T16:32:15.113Z","dependencies_parsed_at":"2023-12-06T19:28:08.208Z","dependency_job_id":"1ba89ea1-e0ae-467d-89aa-7adcd523762c","html_url":"https://github.com/tbowmo/chrome2mqtt","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tbowmo/chrome2mqtt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbowmo%2Fchrome2mqtt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbowmo%2Fchrome2mqtt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbowmo%2Fchrome2mqtt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbowmo%2Fchrome2mqtt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tbowmo","download_url":"https://codeload.github.com/tbowmo/chrome2mqtt/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbowmo%2Fchrome2mqtt/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259360794,"owners_count":22845817,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chromecast","chromecasts","docker-container","home-automation","mqtt","python-script","python3"],"created_at":"2024-08-01T15:05:25.674Z","updated_at":"2025-06-11T23:03:48.146Z","avatar_url":"https://github.com/tbowmo.png","language":"Python","funding_links":[],"categories":["Interfaces","Python"],"sub_categories":["Misc"],"readme":"Chrome2MQTT\n==================\n\n[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=tbowmo_chrome2mqtt\u0026metric=alert_status)](https://sonarcloud.io/dashboard?id=tbowmo_chrome2mqtt)\n\nPython program to enable MQTT control endpoints for chromecasts (both audio and video).\n\nIt listens to events from the connected chromecasts, and send their status to MQTT on the following events:\n* Change in which app is running\n* Media events (play, pause, stop etc.)\n* Media information (title, artist, album etc)\n\nIt also listens to a MQTT topic, for commands. So you can send commands to your chromecasts like play, pause, stop etc.\n\n**NOTE!** Chromecast devices are collected into rooms, old operation where devices are treated seperately is available with option ```--standalone```\n\nTable of contents\n===\n\u003c!--ts--\u003e\n   * [Chrome2MQTT](#chrome2mqtt)\n   * [Table of contents](#table-of-contents)\n   * [Installation](#installation)\n      * [Starting python script with virtual-environment](#starting-python-script-with-virtual-environment)\n      * [Starting with systemd](#starting-with-systemd)\n      * [Start in a docker container](#start-in-a-docker-container)\n      * [Command line options](#command-line-options)\n   * [MQTT topics](#mqtt-topics)\n      * [Rooms or single devices](#rooms-or-single-devices)\n      * [Topics reported on by chromecast2mqtt](#topics-reported-on-by-chromecast2mqtt)\n      * [Aliasing device topics](#aliasing-device-topics)\n   * [JSON types](#json-types)\n   * [Controlling your chromecast via mqtt](#controlling-your-chromecast-via-mqtt)\n   * [Logging](#logging)\n   * [Thanks to](#thanks-to)\n\n\u003c!-- Added by: thomas, at: søn 12 apr 22:29:18 CEST 2020 --\u003e\n\n\u003c!--te--\u003e\n\nInstallation\n===\n\nStarting python script with virtual-environment\n-----------------------------------------------\n\nFirst ensure that you have at least python3.6 and venv installed, then create a new virtual environment for your python script:\n\n```shell\n$ git clone https://github.com/tbowmo/chrome2mqtt.git\n$ cd chrome2mqtt\n$ python3 -m venv .\n$ source ./bin/activate\n$ pip install --no-cache-dir -r requirements.txt\n```\n\nYou are now ready to start the script with\n\n`python -m chrome2mqtt \u003coptions\u003e`\n\nStarting with systemd\n---\nStart by following the description for enabling a virtual environment for python\n\nThen create a file named .service in /etc/systemd/system, with the following content (update paths and hosts as desired)\n```\n[Unit]\nDescription=Chrome2mqtt\nWants=network.target\nAfter=network.target\n\n[Service]\nType=simple\nWorkingDirectory=/home/pi/chrome2mqtt\nExecStart=/home/pi/chrome2mqtt/bin/python -m chrome2mqtt\n\n[Install]\nWantedBy=multi-user.target\n```\n\nThen in a terminal, execute the following two commands to enable your new service\n```shell\n# systemctl enable chrome2mqtt.service\n# systemctl start chrome2mqtt.service\n```\n\nStart in a docker container\n---\nIf you wish to run inside a docker container, you can build your own image with `docker build . --tag chrome2mqtt` and then run it with `docker run --network=host chrome2mqtt \u003coptions\u003e` \n\nCommand line options\n-------------\nConfigure through command line options, as shown below\n```\nusage: chrome2mqtt [-h] [--mqttport MQTTPORT] [--mqttclient MQTTCLIENT] [--mqttroot MQTTROOT] [--mqttuser MQTTUSER] [--mqttpass MQTTPASS] [-H MQTTHOST] [-l LOGFILE] [-d] [-v] [-V] [-C] [-S] [--alias ALIAS]\n\nchrome2mqtt\n\nConnects your chromecasts to a mqtt-broker\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --mqttport MQTTPORT   MQTT port on host\n  --mqttclient MQTTCLIENT\n                        Client name for mqtt\n  --mqttroot MQTTROOT   MQTT root topic\n  --mqttuser MQTTUSER   MQTT user (if authentication is enabled for the broker)\n  --mqttpass MQTTPASS   MQTT password (if authentication is enabled for the broker)\n  -H MQTTHOST, --mqtthost MQTTHOST\n                        MQTT Host\n  -l LOGFILE, --logfile LOGFILE\n                        Log to filename\n  -d, --debug           loglevel debug\n  -v, --verbose         loglevel info\n  -V, --version         show program's version number and exit\n  -C, --cleanup         Cleanup mqtt topic on exit\n  -S, --standalone      Split into separate devices\n  --alias ALIAS         topic aliases for devices\n\nSee more on https://github.com/tbowmo/chrome2mqtt/README.md\n```\n\nMQTT topics\n===========\n\nRooms or single devices\n-----------------------\nchrome2mqtt can organize devices into rooms, or as standalone devices. Normal operation is to organize into rooms, where it can collect two devices (one audio and one video) into one endpoint, automatically directing commands to the active device.\n\nIf you send a play command with an audio stream to a room, then it will automatically send this to the audio chromecast, and if you send a video stream it will be sent to the video chromecast. When starting the a new stream on an inactive chromecast, the other device will automatically be stopped, if it is playing.\n\nIn rooms mode, it will use the device name of your chromecast to identify which room it is placed in. To do this you must have the follow the following scheme for naming the devices `\\\u003croom\u003e_tv` or `\\\u003croom\u003e_audio`. As an example, my chromecasts are named `livingroom_tv`and `livingroom_audio`, then I get a topic called `\u003cMQTT_ROOT\u003e/livingroom/...`\n\nIn standalone mode each device is treated as a separate one, and will have separate topics in your mqtt tree, the topic name will be a a normalized version of the friendly name given to each chromecast, where the name is converted to lower cases, and spaces have been replaced with underscores.\n\nTopics reported on by chromecast2mqtt\n-------------------------------------\nEach room (or device if using `--standalone` will have a set of mqtt topics where status will be emitted\nThe following topics will be used:\n\n| Topic | Payload |\n| ----- | ------- |\n| \u003cMQTT_ROOT\u003e/\\\u003cROOM\u003e/app | Name of the currently running app (netflix, spotify, hbo, tidal etc). |\n| \u003cMQTT_ROOT\u003e/\\\u003cROOM\u003e/state | Current state of the chromecast (playing, paused, buffering) |\n| \u003cMQTT_ROOT\u003e/\\\u003cROOM\u003e/volume | Current volume level (an integer value between 0 and 100) |\n| \u003cMQTT_ROOT\u003e/\\\u003cROOM\u003e/media | Returns a json object containing detailed information about the stream that is playing. Depending on the information from the app vendor. |\n| \u003cMQTT_ROOT\u003e/\\\u003cROOM\u003e/capabilities | Json object containing the capabilities of the current activated app |\n\n*Notes:*  \n*MQTT_ROOT is specified through option `--mqttroot` and will default to empty if not specified.*  \n*ROOM will be device, if `--standalone` is specified*\n\nAliasing device topics\n----------------------\nBy supplying the `--alias` option and a list of device / alias pairs, you can rename your device topics. Specify a comma separated list of device / topic alias pairs:\n`device1=alias/path1,device2=alias/path2` if an alias is not found for a device upon discovery, then the device name itself will be used in topic generation.\n\n*NOTE* When running with `--standalone` you need to specify the full devicename, in lowercases and spaces converted into \"_\", that is if you have a device named \"Livingroom audio\" then you need to specify \"livingroom\\_audio\" as device name. If running in standard mode (where chromecasts are collected into rooms), you need to use the room name for the device in aliasing.\n\nAll aliases will have mqtt_root topic prepended (specified through option `--mqttroot`)\n\nJSON types\n==========\njson formats for media and capabilities are as follows:\n\nmedia object:\n```javascript\n{\n  \"title\": string,\n  \"artist\": string,\n  \"album\": string,\n  \"album_art\": string, // URL to a static image for the current playing track\n  \"metadata_type\": number,\n  \"duration\": number, // Total duration of the current media track\n  \"current_time\": number, // current time index for the playing media\n  \"last_update\": number, // timestamp for last media update\n}\n```\n\ncapabilities object, this is a json containing state and feature capabilities of the current stream playing:\n```javascript\n{\n  \"state\": string, // same as sent to \u003cmqtt_root\u003e/\u003cfriendly_name\u003e/state\n  \"volume\": integer, // same as sent to \u003cmqtt_root\u003e/\u003cfriendly_name\u003e/volume\n  \"muted\": boolean,    // indicates if device is muted\n  \"app\": string, // same as sent to \u003cmqtt_root\u003e/\u003cfriendly_name\u003e/app\n  \"app_icon\": string, // url to a icon / image representing the current running app (Netflix, spotify etc. logo)\n  \"supported_features\": {\n    \"skip_fwd\": boolean, // indicates if skip_fwd is available\n    \"skip_bck\": boolean, // indicates if skip_bck is available\n    \"pause\": boolean,    // indicates if pause is available\n    \"volume\": boolean,   // indicates if volume control is available\n    \"mute\": boolean,     // indicates if audio stream can be muted\n  }\n}\n```\n\nControlling your chromecast via mqtt\n====================================\nIt's possible to control the chromecasts, by sending a message to the `\u003cMQTT_ROOT\u003e/\\\u003cROOM\u003e/control/\u003caction\u003e` endpoint for each device, where `\u003caction\u003e` is one of the following list, some takes a payload as well:\n\n| Action | Payload required | Value for payload |\n| ------ | ------- | ----------------- |\n| play | Optional | If no payload, just starts from a pause condition, otherwise send a json object {\"link\":string, \"type\": string} |\n| pause | Optional | If no payload is supplied it will toggle pause state, otherwise send 1/True to pause or 0/False to play |\n| stop | No | |\n| next | No | |\n| prev | No | |\n| mute | Optional| If no payload is supplied it will toggle mute state, otherwise send 1/True to mute or 0/False to unmute |\n| volume | Required|Integer 0 - 100 specifying volume level |\n| update | No | Requests the chromecast to send a media status update\n| quit | No | Quit the currently running app on the chromecast\n\nPlay\n----\nThe json object for the play command contains a link to the media file you want to play, and a mime type for the content:\n\n```javascript\n// Start playing a mp3 audio file\n { \"link\": \"https://link.to/awesome.mp3\", \"type\": \"audio/mp3\" }\n\n// Start playing a mp4 video file\n { \"link\": \"https://link.to/awesome.mp4\", \"type\": \"video/mp4\" } \n \n// Special mimetype \"youtube\"\n { \"link\": \"zSmOvYzSeaQ\", \"type\": \"youtube\" }\n```\n\nLogging\n=======\nLogging can be configured in two ways, either simple with commandline options, -v for verbose (loglevel INFO and higher) or -d for debug (loglevel DEBUG or higher). You can also specify a file to dump your logs to with -l / --logfile.\n\nA more advanced setup is to make a json file in your root project with the name logsetup.json, an example file (logsetup.json-example) is included, that you can rename and use as a basis for your own setup. This file will take precedence over the commandline arguments, which will be ignored if the file is found.\n\nThanks to\n=========\nI would like to thank [Paulus Schoutsen](https://github.com/balloob) for his excelent work on [pychromecast](https://github.com/balloob/pychromecast), without his library this project couldn't have been made.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftbowmo%2Fchrome2mqtt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftbowmo%2Fchrome2mqtt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftbowmo%2Fchrome2mqtt/lists"}