Binding for Apple-TV

this works for me to go to

movies: top_menu up up down left left left left select left left select right
tv shows: top_menu up down left left left left right select left select
music: top_menu up up down left left left left right right select select

without delays

thatā€˜s my HABpanel screen

1 Like

I updated the release, new jar available at
https://github.com/markus7017/org.openhab.binding.appletv/blob/beta2/target/org.openhab.binding.appletv-2.4.0-SNAPSHOT.jar

which brings some fixes and new features:

  • auto background discovery is configurable (maybe turned off after initial setup)
  • channel totalTime fixed
  • channel totalPercent added: percentage within the media / set position on % (see below)
  • special keys movie renamed to movies (with s, beside tvshows and music)
  • binding configuration and thing config options for pairing added (work in progress)
  • some refactoring, pyatv.zip added to repository

If you want to use the new channel you need to delete and re-discover the thing. Disabling auto discovery is possible, maybe no need to discover new Apple-TVs in the background if you know that there will be no new one. Default is ON for new users.

A nice gimmick is setting the position by %, e.g. sending ā€œ50%ā€ to the totalPercent channel. This allows for example to use a slider in your HABpanel.

Please stop OH before updating the binding. You may need to clear the cache.

My remote control now looks like


(one slider for volume, one for position plus delta buttons for +/- x sec)
PS: the +1:45 button is for skipping the intro of Games of Thrown :slight_smile:

Hi!

Is there any way to speed up the status polling? Iā€™d like to control my hue lights depending on whether my ATV is playing, paused, idle etc. Right now it takes up to 10s before a status change is detected by openhab.

I also noticed that my ATV get woken up by the polling. A short while after I put it to sleep it will wake up again. Any workaround for this?

Otherwise the plugin works great. Setup was a breeze :slight_smile:

ok, so the problem was that I the jar was corrupt. Now I get this error:

2019-09-06 15:11:01.256 [ERROR] [org.openhab.binding.appletv         ] - bundle 
java.lang.UnsatisfiedLinkError: /var/lib/openhab2/tmp/ohlib-1904034541317644345/jpy.so: /var/lib/openhab2/tmp/ohlib-1904034541317644345/jpy.so: undefined symbol: PyFloat_Type
	at java.lang.ClassLoader$NativeLibrary.load(Native Method) ~[?:?]

My openHAB is running on Ubuntu 18.04 x64 with python 3.6 and as I see the code is using 3.5 on linux. I somehow thought of altering the java file and rebuilding the jar, but it somehow fails to find org.jpy.PyLib when compiling.

Are there any build instructions? I have jpy installed via python3.6 setup.py --maven build on my macOs X

Iā€™m using macOS too. You need a OH 2.4 build environment. Then it should work if you go to the binding dir and run ā€œmvn installā€ or ā€œmvn clean installā€ w/o -DskipChecks=true

go to the binding settings (PaperUI:Confoguration:Bindings:Apple TV). There you could set the update interval, e.g. set it to 3s

thatā€™s the price you have to pay for the polling

the binding uses Python 3.6 on macOS (jpy module is located under lib/jpy/lib.macosxā€¦)
and the code has

System.setProperty("jpy.pythonLib",
                        "/Library/Frameworks/Python.framework/Versions/3.6/lib/libpython3.6.dylib");
jpyLib = "lib/jpy/lib.macosx-x86_64-3.6";
System.setProperty("jpy.jpyLib", jpyPath + "/jpy.so");
System.setProperty("jpy.jdlLib", jpyPath + "/jdl.so");

But this for runtime, How about compile time? Cause what I get is

[ERROR] Failed to execute goal org.eclipse.tycho:tycho-compiler-plugin:1.2.0:compile (default-compile) on project org.openhab.binding.appletv: Compilation failure: Compilation failure:
[ERROR] /Users/gytis/projects/org.openhab.binding.appletv/src/main/java/org/openhab/binding/appletv/internal/jpy/LibPyATV.java:[26]
[ERROR] 	import org.jpy.PyLib;
[ERROR] 	       ^^^^^^^

I donā€™t see any dependency in pom.xml related to jpy. So afaik it cannot find the jar file, and complains about this import. Are there any steps that I need to do with jpy afer doing python3.6 setup.py --maven build ? E.g. copy jar somehere?

Hello! I have followed all steps carefully and have a problem setting up the AppleTV Thing.

In Paper UI the status is UNINITIALIZED.

I have tried removing and setting up again with no luck. Thing discovery comes up blank too.

In terminal I am able to see and control my atv, as well as pair with no errors.

Any help getting this solved would be amazing.

Perhaps some helpful log info, Iā€™m pretty new to this and donā€™t know how to interpret

2019-09-11 15:42:23.397 [ERROR] [org.openhab.binding.appletv ] - bundle org.openhab.binding.appletv:2.4.0.201905122036 (234)[org.openhab.binding.appletv.internal.AppleTVHandlerFactory(20)] : The activate method has thrown an exception
at org.openhab.binding.appletv.internal.jpy.LibPyATV.(LibPyATV.java:162) ~[?:?]
at org.openhab.binding.appletv.internal.AppleTVHandlerFactory.activate(AppleTVHandlerFactory.java:58) ~[?:?]
2019-09-11 15:42:23.406 [WARN ] [org.openhab.binding.appletv ] - FrameworkEvent WARNING - org.openhab.binding.appletv
2019-09-11 15:46:02.371 [INFO ] [ding.appletv.internal.AppleTVHandler] - Apple-TV.Discovery: Factory not initialized, skip scan


thatā€™s the point where it tries to call Python the first time
which platform are you running?

Please provide a TRACE log

  • open OH console
  • type ā€œlog:set TRACE org.openhab.binding.appletvā€
  • restart binding or OH

pyATV now is broken due to the new TVOS13 ā€¦

thatā€™s really bad news
what happens?

did you tried the latest pyatv build?
even this works it will be a lot of effort to upgrade the binding. Iā€™m using a modified pyatv version, which required a lot of time

I donā€™t have an ATV4 so I canā€™t do any testing

There is a new build pyatv 0.4.0a1 that is supposed to work with TVOS13. I am wondering if anyone tried it?

Pyatv is under development for TVOS, there are many missing things. You can check GitHub for progress and issues.

this doesnā€™t work. While integrating pyatv I need to make a lot of changes to fit into the java environment. The binding is not just running a command line, because this took 3-5s per key. It directly integrates the Python code (using jpy). You could check the repo and compare the initial checkin with the latest code.

Hi all,

First of all thank you for your work and efforts.
I really like to use this binding and tried all sorts of ideas in this thread.
But I canā€™t get it to work.
Installing to the stage of scanning and registering with my atv4 is done. I can put commands to my atv via atvremote, thatā€™s fine.
But if I drop the jar 2.5.0 into my addons folder, oh crashes. After i restart oh, all other bindings are working well, but appletv binding posts errors every 10s.
I suspect itā€™s the polling.
I think itā€™s a conflict of the python versions installed on my rpi4. The readme tells 3.5 is needed, I have 3.7 running. I canā€™t get the install of pyatv to work with 3.5.
My oh is 2.5.3 stable, server is raspberry pi 4, running openhabian.
I would greatly appreciate any help to get this working. I donā€™t want to go the path of doing a minimal control via executecommands for atvremote via cli.
Thanks in advance,
Thomas

any update with this working with tvOS 13?

No, the situation

  • the binding is embedding pyatv 0.3, which was fine until Apple made those changes, which leads into
  • ATV4 with iOS 13 doesnā€™t work
  • ATV3 still works fine, but the bindings shows the exception every 10s (which doesnā€™t impact overall functionality, at least in my own installation)
  • I worked a lot on the embedded PyATV version to build a bridge between the binding and pyatv. This is based on Python, which I have only ā€œtrial&errorā€ knowledge. In fact I tried to wrap the CLI version directly into the binding and have some kind of events (bacllbacks to the binding) - sounds ugly, is ugly, but was the only way to get something working
  • This would have to be done with PyATV4 again and I know thatā€™s a good bunch of work
  • Iā€™m pretty sure the current approach will never pass the review process

In fact Iā€™m lacking the required Python knowledge. I know that OH embeds the same Java/Python bridge to enable Jython based rules. The PyATV didnā€™t show much interest to help on this.

Fianally itā€™s a matter of time. Iā€™m already spending significant time on developing the bindings for Shelly, MagentaTV, GREE, Carnet, Rachio so the ATV binding got less and less priority. And last, but not least: I donā€™t have an ATV4, which means a lot of back and forth for testing.

1 Like

If any one else is missing Markusā€™ great AppleTV binding because of tvOS upgrade, there is a workaround!
I was frustrated losing the binding but in my research for a solution I found this:
HABApp

Using HABApp, I can use the pyatv library directly. It is not as integrated as a binding and I havenā€™t succeeded in getting all ā€œpushā€ functionality in pyatv to work, but my main use is to be able to use my single remote for ā€œeverythingā€ and for that it works great!

I hope this helps someone!