Page 1 of 6

New Python3 AppleTV indigo Plugin

PostPosted: Sat Nov 26, 2022 12:47 am
by GlennNZ
AppleTV indigoDomo Plugin

Image

Hi all,

This is a appleTV plugin for remote control and instant monitoring of activity of your appleTV devices. Hopefully with Karls blessing (well according to a User!) I have updated, started again in python3 the appleTV plugin. Using asyncio & python3.

Appears compatible with all appleTV devices, hopefully new 4k and OS16

https://github.com/Ghawken/appleTV-indigoPlugin

It uses the pyatv library (many thanks! https://github.com/postlund/pyatv) and this needs to be installed via a pip3 terminal command before usage. (Packaging it wasn't an option unfortunately as to many depencencies)

It use the pyatv PushListeners for playback activities to be immediately 'pushed' to the Indigo plugin devices. No polling required.

This means if have lights dimming up on pause and off on Play (as I do) - it should happen immediately!


New version 1.2.20 (only in Indigo 2023.2). No library or terminal commands needed, and no xattr unquarantine commands needed (!)

Potential issue:
pyatv and it’s dependencies need to compile some library code at install time. This compiling needs xcode command line tools installed on your system, if not already.
This is a potential issue for other libraries in the future as well - so installing xcode command line tools (free) advised to avoid other issues.

Install Xcode Command Line tools. (Google this for more advice - but easiest seems below)

Code: Select all
xcode-select --installl

or
Can download directly from apple:
https://developer.apple.com/download/more/

(If you get errors (seems to stem from mini audio needing clang to compile - you may need to install xcode command line tools. Typically the pip above will prompt - but if not see end of post/FAQ for how to install manually without needing full xcode install.)


Double click the release indigoplugin File and install.

All going well - nothing will happen...

Steps:

Go to PluginConfig

Image

This one above.
Press the "Generate AppleTV Devices"

This will search your network for appleTV device and generate plugin Devices corresponding.
These devices will be located in the main device folder, but can be moved anywhere you like later.
You can re-press and re-press the button (if you like), and new devices should not duplicate.

Devices

Next go to a Device:

Open a device, with the Edit Device Details

Image

You should see the above.

Since OS16 and Apple4k you will need to pair your indigoplugin Device with your appleTV

Steps:
Press the Start Pairing Button.

The plugin should find and connect to your appleTV.

A pincode should be displayed on the screen.

Enter the Pincode in the box, and press submit Pincode (Press) Button.

You should receive confirmation that pairing has been successful.

Press the SAVE button on the Config Dialog.

(I believe we need to do this only once... but time will tell...)

Device Details

I expose a number of playback states (Thanks Karl for the typing on these!)

Image

You will also see the device is an Indigo Relay - so there are Turn On/Turn Off/Toggle buttons that power down/power on the relevant appleTV.

Remote Control / Actions

Image


The plugin exposes all remote control options via commands.

Launch App

Image

I have also implemented Launch App - which allows you to launch a specific application of the appleTV.

Unfortunately it doesn't allow LiveTV within the app, or more detailed control - but this can be managed with a lauchApp command, and then, left, down, down, select remote commands for example


FAQ / Troubleshooting


pip3 install pyatv

Fails - with some red lines and an error about a dependency miniaudio (which we don't use...)
It appears to want to install some x-code "command line developer tools" -- commandline tools - to help build this dependency.
Install the xcode components, appears to be usr/bin/clang and hopefully will able to be installed.

Oh No - it looks like needs 14gig of Xcode for this to work. What a pain.
Try:
https://developer.apple.com/download/more/
Login and download Command Line Tools for Xcode and install.

The above worked for my production machine - which hit this issue. (avoided Xcode install thankfully)

Can't remote control certain device.

Currently I expose all airplay devices - Sonos included. I do not believe these can be controlled or report status - but have not specifically tested them.
The AppleTV devices are those we are aiming to support here.

PowerState reporting not always uptodate eg. On/Off

This is an known issue with the appleTVs particularly OS16 and above.
The removal of some of the protocols impacts this reporting, and On/Off state reporting is not always updated or correct.
This will likely vary by OS and appleTV itself.

Re: New Python3 AppleTV indigo Plugin

PostPosted: Sat Nov 26, 2022 4:08 am
by durosity
Oh my this looks awesome! I’ll be trying it out soon! I know it’s not the intention for the plugin but I do hope it allows control of AirPlay/HomePod devices too as that would be super useful!


Sent from my iPhone using Tapatalk Pro

Re: New Python3 AppleTV indigo Plugin

PostPosted: Sat Nov 26, 2022 6:55 am
by dtich
this is fantastic, thanks so much for working on it!

upon install i got this:

Nov 26, 2022 at 4:43:04 AM
Indigo Cocoa client connected
Installing and enabling plugin appleTV Plugin v0.0.13
Error ReloadPlugin() caught exception: FileIOError -- cannot move: destination file exists
Reloading plugin "Web Server 2022.1.1" using API v2.5
Stopping plugin "Web Server 2022.1.1" (pid 795)
Web Server Stopping Indigo Web Server...
Web Server disconnecting from Indigo server
Web Server client disconnected
Stopped plugin "Web Server 2022.1.1"
Starting plugin "Web Server 2022.1.1" (pid 77943)
Installing and enabling plugin appleTV Plugin v0.0.13
Error ReloadPlugin() caught exception: FileIOError -- cannot move: destination file exists
Reloading plugin "Web Server 2022.1.1" using API v2.5
Stopping plugin "Web Server 2022.1.1" (pid 795)
Web Server Stopping Indigo Web Server...
Web Server disconnecting from Indigo server
Web Server client disconnected
Stopped plugin "Web Server 2022.1.1"
Starting plugin "


disabling old plugin solves this i think. now i get this, even though i did install pyatv via terminal before even dl'ing plugin. i haven't restarted the machine but have quit and restarted indigo server. error persists. looking at terminal return it seems i may have hit the mini audio error.... will try installing the dev tools.

appleTV Plugin Error Error in plugin execution InitializeMain:

File "plugin.py", line 144, in <module>
type: name 'pyatv' is not defined

Stopping plugin "appleTV Plugin 0.0.13" (pid 78388)




thanks!

Re: New Python3 AppleTV indigo Plugin

PostPosted: Sat Nov 26, 2022 8:36 am
by dtich
success!

had to update OS to install latest dev tools. mini audio then installed and plugin followed suit. auto discovery was quick and impressive. nice work!


thx~!

Re: New Python3 AppleTV indigo Plugin

PostPosted: Sat Nov 26, 2022 3:20 pm
by Korey
Thanks Glenn!!

This is fantastic!!

Super handy!

Re: New Python3 AppleTV indigo Plugin

PostPosted: Sat Nov 26, 2022 10:46 pm
by GlennNZ
dtich wrote:
this is fantastic, thanks so much for working on it!

upon install i got this:

Nov 26, 2022 at 4:43:04 AM
Indigo Cocoa client connected
Installing and enabling plugin appleTV Plugin v0.0.13
Error ReloadPlugin() caught exception: FileIOError -- cannot move: destination file exists
Reloading plugin "Web Server 2022.1.1" using API v2.5
Stopping plugin "Web Server 2022.1.1" (pid 795)
Web Server Stopping Indigo Web Server...
Web Server disconnecting from Indigo server
Web Server client disconnected
Stopped plugin "Web Server 2022.1.1"
Starting plugin "Web Server 2022.1.1" (pid 77943)
Installing and enabling plugin appleTV Plugin v0.0.13
Error ReloadPlugin() caught exception: FileIOError -- cannot move: destination file exists
Reloading plugin "Web Server 2022.1.1" using API v2.5
Stopping plugin "Web Server 2022.1.1" (pid 795)
Web Server Stopping Indigo Web Server...
Web Server disconnecting from Indigo server
Web Server client disconnected
Stopped plugin "Web Server 2022.1.1"
Starting plugin "


disabling old plugin solves this i think. now i get this, even though i did install pyatv via terminal before even dl'ing plugin. i haven't restarted the machine but have quit and restarted indigo server. error persists. looking at terminal return it seems i may have hit the mini audio error.... will try installing the dev tools.

appleTV Plugin Error Error in plugin execution InitializeMain:

File "plugin.py", line 144, in <module>
type: name 'pyatv' is not defined

Stopping plugin "appleTV Plugin 0.0.13" (pid 78388)

thanks!


The old plugin - may be named the same... probably should change the name of my bundle to overcome that.

Yes - it appears you haven't installed pyatv
`pip3 install pyatv`

Check the readme FAQ if issues.

Re: New Python3 AppleTV indigo Plugin

PostPosted: Sat Nov 26, 2022 10:50 pm
by GlennNZ
See this post for Changelog/Updates:

viewtopic.php?f=382&t=26703

Re: New Python3 AppleTV indigo Plugin

PostPosted: Sun Nov 27, 2022 1:44 pm
by Korey
Is there a REBOOT command available anywhere?

I currently use an `ir code to achive this.

Code: Select all
<NEC:87ee/5418>

Re: New Python3 AppleTV indigo Plugin

PostPosted: Mon Nov 28, 2022 12:49 am
by MarcoGT
Wonderful, I will install for sure.
Useful and very nice the possibility to launch specific app :)

I will report back.

Re: New Python3 AppleTV indigo Plugin

PostPosted: Mon Nov 28, 2022 9:33 pm
by GlennNZ
Korey wrote:
Is there a REBOOT command available anywhere?

I currently use an `ir code to achive this.

Code: Select all
<NEC:87ee/5418>

Reboot options:
https://support.apple.com/en-us/HT201836

Unfortunately these are not supported over IP


Sent from my iPad using Tapatalk

Re: New Python3 AppleTV indigo Plugin

PostPosted: Fri Dec 02, 2022 5:50 am
by Londonmark
Great plugin - thanks so much.

Is there any chance of pulling down the artwork of whatever is playing and saving it somewhere?

Re: New Python3 AppleTV indigo Plugin

PostPosted: Fri Dec 02, 2022 6:05 pm
by GlennNZ
Londonmark wrote:
Great plugin - thanks so much.

Is there any chance of pulling down the artwork of whatever is playing and saving it somewhere?
On the todo list:
Will look at action to run to download / update


Sent from my iPhone using Tapatalk

Re: New Python3 AppleTV indigo Plugin

PostPosted: Fri Dec 02, 2022 6:07 pm
by Londonmark
Sounds great. Thanks I’m advance.

Re: New Python3 AppleTV indigo Plugin

PostPosted: Sat Dec 03, 2022 1:20 am
by GlennNZ
Londonmark wrote:
Sounds great. Thanks I’m advance.
Try latest version - 0.0.27 I think, via Download Code button..

Adds Save Artwork via an Action Group.

Probably some caveats - need MRP protocol supported (one of my appleTVs this is disabled), and some apps do not seem to support Artwork. Currently saves a blank png file if nothing - but may change this to a default artwork image as often better usability in control pages with this approach.

Happy to take feedback!


Sent from my iPad using Tapatalk

Re: New Python3 AppleTV indigo Plugin

PostPosted: Sat Dec 03, 2022 5:26 am
by durosity
What is MRP?


Sent from my iPhone using Tapatalk Pro