Binding for Apple-TV

Currently, you have to pair openhab to your ATV at the commandline to get the login ID, as described GitHub - postlund/pyatv: A client library for Apple TV and AirPlay devices

I left “Lib install path” blank, and it works. IP address is in the settings menu of your ATV.

Thank you for the reply, I will do what you suggested.

Where che i find the CLI application? I have a Raspberry and pytv is installed by the binding. I searched the tmp path with non luck.

From the command line of your Raspberry Pi type:

atvremote scan
atvremote pair -p 1234

Have your AppleTV on and go to the menu where you can pair additional remotes.
It should show up as pyatv and the pin code is 1234 (as indicated by the -p option above)
When pairing is complete you’ll get the Login ID given to you in the command line of the Pi

It seems that atvremote is not available when you use the pyTV version installed by the binding.

OK, instead you can try

python3 -m pyatv scan
python3 -m pyatv pair -p 1234

If this still doesnt work then issue the following command

python3 -m pip install pyatv

After that you should be able to use atvremote as well as python3 -m pyatv

1 Like

And what if you’re logged in to your pi through Mac OS cli?

I’m not sure if I understand your question…?
Unless you mean that you’ll need to add 'sudo ’ to the commands mentioned, depending on your user privileges.

Then it would be:

sudo python3 -m pyatv scan

etc…

That helps a lot :slight_smile:
I’m not a Pro

but I’m getting this
/usr/bin/python3: No module named pyatv

As mentioned above, try this:

sudo python3 -m pip install pyatv

Then you should be able to run:

sudo python3 -m pyatv scan
sudo python3 -m pyatv pair -p 1234

Thank you @JohnnyBravo

I’m getting this now

/usr/bin/python3: No module named pip

Ok, please bear with us, it’s still very much in Alpha state…

The following should solve your issues

sudo apt-get update
sudo apt-get install python3 python3-pip libpython3.5
sudo python3 -m pip install pyatv
sudo python3 -m pyatv scan
sudo python3 -m pyatv pair -p 1234

@markus7017

I think I had messed up my Python install when changing to different versions all the time.
The error i had before about ‘undefined symbol’ has gone away.

My log now shows:

2019-02-25 16:27:51.615 [INFO ] [letv.internal.handler.AppleTVHandler] - Apple-TV.Handler: Initializing AppleTV
2019-02-25 16:27:51.617 [INFO ] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: Modules will be installed in '/var/lib/openhab2/tmp/ohlib-7997981974257508372'
2019-02-25 16:27:51.650 [WARN ] [mmon.WrappedScheduledExecutorService] - Scheduled runnable ended with an exception:
java.lang.NoClassDefFoundError: Could not initialize class org.jpy.PyLib
        at org.openhab.binding.appletv.internal.jpy.LibPyATV.<init>(LibPyATV.java:157) ~[?:?]
        at org.openhab.binding.appletv.internal.handler.AppleTVHandler.lambda$0(AppleTVHandler.java:59) ~[?:?]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[?:?]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[?:?]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) ~[?:?]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) ~[?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
        at java.lang.Thread.run(Thread.java:748) [?:?]

It seems that I made a progress, sorry for the inconvenience

I suppose “/usr/lib/x86_64-linux-gnu/libpython3.5m.so” is the right one and changed the code - lets see how that works


Do you have TRACE mode enabled? I’m missing some expected log messages.

java.lang.UnsatisfiedLinkError: /var/lib/openhab2/tmp/ohlib-4823276808541727152/jpy.so: /var/lib/openhab2/tmp/ohlib-4823276808541727152/jpy.so: undefined symbol: PyFloat_Type

sound like an inconsistency with the jpy module. Need to check if I copied the correct binaries from your post to the correct lib directory.

Sorry, my bad with the TRACE log.
Here it is:

2019-02-25 16:45:41.061 [INFO ] [letv.internal.handler.AppleTVHandler] - Apple-TV.Handler: Initializing AppleTV
2019-02-25 16:45:41.061 [DEBUG] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: Initialize PyATV (current installation path: 'null')
2019-02-25 16:45:41.063 [INFO ] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: Modules will be installed in '/var/lib/openhab2/tmp/ohlib-9132383442221655067'
2019-02-25 16:45:41.063 [DEBUG] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: Platform info: 'linux', architecture: 'amd64'
2019-02-25 16:45:41.064 [DEBUG] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: jpyLib=lib/jpy/lib.synology-x86-64-3.5
2019-02-25 16:45:41.065 [DEBUG] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: jpy.pythonExecutable: /usr/bin/python3
2019-02-25 16:45:41.066 [DEBUG] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: jpy.pythonLib: libpython3.5m.so
2019-02-25 16:45:41.066 [DEBUG] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: jpy.jpyLib: /var/lib/openhab2/tmp/ohlib-9132383442221655067/jpy.so
2019-02-25 16:45:41.067 [DEBUG] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: jpy.jdlLib: /var/lib/openhab2/tmp/ohlib-9132383442221655067/jdl.so
2019-02-25 16:45:41.068 [DEBUG] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: jpy.pythonPrefix: /usr
2019-02-25 16:45:41.110 [WARN ] [mmon.WrappedScheduledExecutorService] - Scheduled runnable ended with an exception:
java.lang.NoClassDefFoundError: Could not initialize class org.jpy.PyLib
        at org.openhab.binding.appletv.internal.jpy.LibPyATV.<init>(LibPyATV.java:157) ~[?:?]
        at org.openhab.binding.appletv.internal.handler.AppleTVHandler.lambda$0(AppleTVHandler.java:59) ~[?:?]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[?:?]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[?:?]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) ~[?:?]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) ~[?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
        at java.lang.Thread.run(Thread.java:748) [?:?]

Worked great on my ATV4 for me.
If an amature like me wanted to know the procedure to install it on Pi, I could help.
Also I would appreciate the implementation of an ON/OFF switch, I could help in any way.

Thank you again everyone

Yes, I know the next step should be to start with more specific information in README.md describing pre-requisites and the installation. @JohnnyBravo maybe you could already start working on this :wink:

If the remote is not selectable within the ATV menu you need to restart the ATV. Usually after a reboot it comes up showing the new (unpared) remote.

In general the basic steps:

  • You need to have Python 3.5 on the system. 2.x will not be supported, 3.6 maybe in the future, but not yet scope of testing etc. (we are in alpha stage)
  • Also pyatv has to be install, which includes the atvremote module as well as the packages avhi-utils and python3-jpy
  • You need to install the Python libs zeroconf and sh
  • You need to make sure that Python modules go into the Python 3.5 folders if you have multiple Python versions install (e,g, use pip3.5 instead of pip or pip3 commands)
  • You need to do a manual pairing (see the pyatv doc on Github)

That said I try to bring it together (not verified)

Make sure you have the latest version, check the repo for the lastest branch. Currently alpha2 (will move to alpha3 when Synology is integrated): org.openhab.binding.appletv/target/org.openhab.binding.appletv-2.4.0-SNAPSHOT.jar at alpha2 · markus7017/org.openhab.binding.appletv · GitHub

Check out the README for futher information: org.openhab.binding.appletv/README.md at alpha2 · markus7017/org.openhab.binding.appletv · GitHub
current status needs to be improved, e.g. by consolidating the below informsation there.

sudo apt-get update
sudo apt-get install python3.5 python3-pip libpython3.5 python3-jpy
sudo apt-get install avhi-utils
sudo pip3.5 install pyatv zeroconf sh
sudo atvremote scan
sudo atvremote pair -r openHAB

maybe something is missing.
“atvremote scan” will provide you the IP address
“atvremote pair” will provide you the login_id

You should verify the installation before installing/configuring the binding.

atvremote --address <ip address>  --login_id <login id from pairing>  top_menu

should work without error messages and move the focus on the Apple-TV to the top menu.

Next step: Configuring the thing

  • Copy binding jar to addons folder
  • set log level to TRACE mode
  • restart OH (so we have all messages from TRACE mode)
  • Go to PaperUI->Configuration->Things
  • Add a new thing with ‘+’
  • Enter IP address and Login ID from the manual pairing process (see above)
  • The thing should become online, check openhab log for errors
  • Go to PaperUI->Control, find the new thing
  • Change “AppleTV Command Sequence” to a vlid key (like menu, up, down…)

You could get a list of valid commands/keys by running “atvremote commands”, section “Remote control commands”

Check here for an example items and sitemap definition: Binding for Apple-TV - #33 by jacksteraz

I have no ATV4 (from my point of view too expensive, so I bought a 2nd ATV3), but would expect that this binding should also work if atvremote works.

see above notes:
Status:

  • RPi should work
  • I’m working with @JohnnyBravo on Synology
  • macOS is not tested recently (I know one issue to be fix) - let me know if someone want to try
  • Windows: currently not supported, in fact I would need to create a Windows environment; postponed until we have a clear view how to simplify installation and get access to the platform jpy modules without embedding them with the bundle
  • Ubuntu: not tested, would need some changes - would be nice if someone could support

I though about that, but this means to have a ON/OFF for every possible command. If this is a request by you guys I could do it - not a big thing, but from experience I know that user’s get confused with a ton of channels.