Hello,
I recently found pyatv and it works very well on a Mac Mini that I am using as a domotica hub. My system runs Indigo, which uses python2.7. This means, I think, that I cannot really use pyatv to obtain (near) real-time status updates from the AppleTV. Best I can think of is temporary polling using e.g. "playing" and "artwork_save" commands, but I thought I'd check with you to make sure I am not overlooking a better solution.
Best regards and thanks for your great work!
Mark Stoutjesidjk
You are correct. Python 2.x has been deprecated since last year and don't get any updates at all anymore, so you should make a switch and upgrade to python 3.x. For pyatv you require at least python 3.6. If you can run docker, you can probably create a container based on the official python docker image and install pyatv there. That's not something I've tried myself, so you would have to do some tinkering to get that working.
Unfortunately, Indigo will be using 2.7 for a while longer. I have python 3.9 co-existing nicely with 2.7. So while it is possible to use _atvremote_ to send commands, I have a challenge to efficiently read the AppleTV in near real-time.
I'm not much of a python expert myself, but I was thinking that it should be possible to report the device state in some dynamic file that is continuously updated with _atvscript_, using some (custom?) listener app/script. This script could also send a message to Indigo to re-read the dynamic state file whenever it has been updated.
Would this be a feasible approach?
I'm not sure how to do it in the best way, but it looks like there's a plug-in for node-red:
https://flows.nodered.org/node/node-red-contrib-indigo
I know that it's possible to read the output continuously from atvscript and pass it into node-red, so if you can get up and running it should be possible to get live updates.
Nice, thanks!
If you need help, I think @crxporter might be able to help (I've never used node-red myself).
Hi yes! I run atvscript in node red continuously. I'm using the daemon node for playing and power state information, it's fantastic. I'm controlling lights in response to play state and "fixing" when HDMI CEC controls aren't properly implemented from the TV manufacturers...
Daemon node is here.
I have a little nodered dashboard to monitor things and restart the daemon if I ever need to. I'm not sure your starting point but I'd be happy to share nodered flows and whichever other knowledge you might find useful.
Sounds wonderful, and almost exactly what I intend to use it for. I will take a look at NodeRed and the daemon node. I have a very busy week ahead so it may take a while before I can take a shot at it. But thank you very much for the offer -- I'm sure I'll be back with some questions!
EDIT: corrected typo
I just couldn't wait, and gave it a quick whirl. NodeRed and Daemon were a breeze to install. I am currently inserting some text into Indigo's log every 5 seconds, so I've got the basics.
Is there some easy way to keep atvscript continuously updating a file with the "playing" output and doing an "artwork_save=512,-1"?
I'm running daemon node with this:
atvscript -s 10.11.11.2 push_updates
Looks like:

It outputs basically forever? I haven't touched it in weeks/months...