npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sebbo2002/pyatv-mqtt-bridge

v8.0.1

Published

Bridge which allows you to control your Apple TV via MQTT

Downloads

867

Readme

pyatv-mqtt-bridge

License Dependencies

MQTT Bridge allows you to remote control your Apple TV using the MQTT protocol. For many home automation systems, for example, this protocol is supported, so Apple TV can be integrated into your existing automation system. In addition to simulating key presses, you can also query the current state of Apple TV.

☁ Installation

Before you use this module you need to install pyatv. See FAQ section for installation tips.

To install the javascript module via npm run:

npm install -g @sebbo2002/pyatv-mqtt-bridge

You can also use the provided Docker container to run pyatv-mqtt-bridge within docker:

docker pull sebbo2002/pyatv-mqtt-bridge

⚒ Quick Start

  1. Use pyatv to connect to your Apple TV and authenticate [?]

  2. Create a new pyatv-mqtt-bridge configuration file. Your can use the config.example.json to start with.

{
    "broker": "mqtt://192.168.1.1",
    "devices": [
        {
            "name": "Any Name",
            "topic": "home/livingroom/appletv",
            "host": "192.168.1.2",
            "id": "AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE",
            "airplayCredentials": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA:BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB:CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC:DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
        }
    ]
}
  1. Start pyatv
  • By command line :
pyatv-mqtt-bridge /home/eve/pyatv-mqtt-bridge.json
  • or use the Docker container :
docker run -d --restart=always --name=pyatv-mqtt-bridge \
    -v $(pwd)/config.json:/app/config.json:ro \
    sebbo2002/pyatv-mqtt-bridge
docker-compose up -d

🤨 FAQ

How to install pyatv

pip3 install pyatv

How can I enable debugging mode ?

You just need to add the --debug option.

  • In command line :
pyatv-mqtt-bridge --debug /home/eve/pyatv-mqtt-bridge.json
  • or while using the Docker container :
docker run -d --restart=always --name=pyatv-mqtt-bridge \
    -v $(pwd)/config.json:/app/config.json:ro \
    sebbo2002/pyatv-mqtt-bridge \
    pyatv-mqtt-bridge --debug /app/config.json
command: pyatv-mqtt-bridge --debug /app/config.json

       then restart the container with :

   docker-compose up

How can I send commands to the Apple TV?

To execute a command send any message to the topic $device/$command. $device is the configured topic of the device and $command is a command from this list. Example: /home/living/appletv/menu. To launch an app, send it's unique id (e.g. com.google.ios.youtube) to the topic $device/launch

How to check the current Apple TV power state and other status information ?

You can listen to several subtopics from the root MQTT topic you've set on your config.json file (i.e. : /home/living/appletv), such as /powerState (on, off) and /deviceState (iddle, playing, etc...).

When the Apple TV is off, the turnOff command turns it on instead, how to fix this ?

Say you send an MQTT message to turn off your Apple TV each time you're leaving home, with the following MQTT topic : /home/living/appletv/turnOff.
... but when you are back home, sometimes your Apple TV is on ! 🤔

Actually, if you press the power button in the right upper corner of your Apple TV remote iOS app, while your Apple TV is already off, it will switch it on as well, and this project only provides bridging between MQTT and PyATV / Apple TV APIs, with no additional data persistence.

(You could use the /suspend command instead of /turnOff to avoid this, but the suspend and wakeup commands are deprecated and may lead to unexpected behaviors).

So you just need to implement a listener for the powerState MQTT topic (i.e. : /home/living/appletv/powerState) in your own app, and store the payload value somewhere (DB, local file, Redis...).

Then your app logic with some "standby apple TV" feature should trigger an MQTT /turnOff command ONLY when your powerState stored value is 'on'.

Copyright and license

Copyright (c) Sebastian Pekarek under the MIT license.