Binding for Apple-TV

Regarding the ON/OFF command, I’m not sure how is it working on previous ATV versions but on ATV4 the ON command can be executed by pressing any of the keys, it doesn’t matter which one at all. Regarding the OFF command can be executed by one long pressing “3 sec” of “Home” button and a short press of “Glass Touch Surface”.

Do you mean Power ON? Yes, you could press any key (also with the ATV3) so I didn’t saw the need to have an extra switch even if you can’t power off using this way, which is confusing. But as said, if you want to see it I could do it (maybe calling it Wakeup to make clear that it’s not possible to power off)

Thanks a lot,

I just thinking that this way would be more easy when you add the [ “Switchable” ] command for Amazon echo and Google home assistant devices to add Power ON and OFF in a routine.

I succedeed pair the remote but when the binding starts I have the following error:
Apple-TV.Handler: Initializing AppleTV

2019-02-25 19:54:54.296 [DEBUG] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: Initialize PyATV (current installation path: ‘null’)

2019-02-25 19:54:54.379 [INFO ] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: Modules will be installed in ‘/var/lib/openhab2/tmp/ohlib-1278379705016263054’

2019-02-25 19:54:54.422 [DEBUG] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: Platform info: ‘linux’, architecture: ‘arm’

2019-02-25 19:54:54.461 [DEBUG] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: jpyLib=lib/jpy/lib.linux-armv7l-3.5

2019-02-25 19:54:54.500 [DEBUG] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: jpy.pythonExecutable: /usr/bin/python3

2019-02-25 19:54:54.541 [DEBUG] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: jpy.pythonLib: /usr/lib/arm-linux-gnueabihf/libpython3.5m.so

2019-02-25 19:54:54.580 [DEBUG] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: jpy.jpyLib: /var/lib/openhab2/tmp/ohlib-1278379705016263054/jpy.so

2019-02-25 19:54:54.607 [DEBUG] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: jpy.jdlLib: /var/lib/openhab2/tmp/ohlib-1278379705016263054/jdl.so

2019-02-25 19:54:54.659 [DEBUG] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: jpy.pythonPrefix: /usr

2019-02-25 19:54:56.530 [WARN ] [mmon.WrappedScheduledExecutorService] - Scheduled runnable ended with an exception:

java.lang.NoClassDefFoundError: Could not initialize class org.jpy.PyLib

hmm, sounds like there is some module missing or something like that. Please go though the installation hints above and make sure all modules have been installed and you are using Python 3.5.

I checked in a clean rebuild and also the updated path for libpython3.5 for Synology (@JohnnyBravo)
https://github.com/markus7017/org.openhab.binding.appletv/blob/alpha2/target/org.openhab.binding.appletv-2.4.0-SNAPSHOT.jar

please give it a try

Tried your latest release and it works! Great work!

good news :slight_smile: So just @JohnnyBravo is missing

alpha3 will bring

  • First documentation (README)
  • Wakeup ON/OFF switch
  • Support for command sequences (e.g. top_menu down down select)
  • Better handling for installation
  • verified macOS support (need to re-test)
1 Like

I updated the README:

Please provide feedback.

Just had a chance to try the latest jar and it works just fine!

Here is the log:

2019-02-26 08:38:25.121 [DEBUG] [org.openhab.binding.appletv         ] - BundleEvent STARTING - org.openhab.binding.appletv
2019-02-26 08:38:25.123 [DEBUG] [org.openhab.binding.appletv         ] - BundleEvent STARTED - org.openhab.binding.appletv
2019-02-26 08:38:25.139 [DEBUG] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.Factory: Activate HandlerFactory
2019-02-26 08:38:25.196 [INFO ] [letv.internal.handler.AppleTVHandler] - Apple-TV.Handler: Initializing AppleTV
2019-02-26 08:38:25.201 [DEBUG] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: Initialize PyATV (current installation path: 'null')
2019-02-26 08:38:25.202 [INFO ] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: Modules will be installed in '/var/lib/openhab2/tmp/ohlib-6624325051341057749'
2019-02-26 08:38:25.203 [DEBUG] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: Platform info: 'linux', architecture: 'amd64'
2019-02-26 08:38:25.204 [DEBUG] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: jpyLib=lib/jpy/lib.synology-x86-64-3.5
2019-02-26 08:38:25.205 [DEBUG] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: jpy.pythonExecutable: /usr/bin/python3
2019-02-26 08:38:25.206 [DEBUG] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: jpy.pythonLib: /usr/lib/x86_64-linux-gnu/libpython3.5m.so
2019-02-26 08:38:25.206 [DEBUG] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: jpy.jpyLib: /var/lib/openhab2/tmp/ohlib-6624325051341057749/jpy.so
2019-02-26 08:38:25.207 [DEBUG] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: jpy.jdlLib: /var/lib/openhab2/tmp/ohlib-6624325051341057749/jdl.so
2019-02-26 08:38:25.207 [DEBUG] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: jpy.pythonPrefix: /usr
2019-02-26 08:38:25.330 [DEBUG] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: Starting Python
2019-02-26 08:38:25.499 [INFO ] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: load PyATV
2019-02-26 08:38:26.897 [INFO ] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: Sending command top_menu to ip 192.168.0.82, lid 0xE405DF5F717AF87D
2019-02-26 08:38:27.091 [DEBUG] [letv.internal.handler.AppleTVHandler] - Apple-TV.Handler: PyATV installation path: /var/lib/openhab2/tmp/ohlib-6624325051341057749

Just a few minor points:

  • I have an Apple-TV 4, so add that to the list of supported devices :slight_smile:

  • In various posts i see mentioned that the following command is needed.

sudo apt-get install avhi-utils

This gives a ‘package not found error’ and it should be:

sudo apt-get install avahi-utils
  • Even though i run my install on a synology (virtual machine), it really is a standard Debian9 install, so i think you can just add Debian on amd64 / x86_64 as supported :slight_smile:

  • Just to be on the safe side; instead of

sudo pip3.5 install pyatv zeroconf sh

I would recommend to use

sudo python3 -m pip install pyatv zeroconf sh

This just reduces the chance of running into problems with various versions of pip.

Other than that it’s great to see this binding come to life! Thanks for all the effort!

nice update👍

ok, but how tommake sure that python3 points to the Python 3.5 runtime? so more specific?
sudo python3.5 -m pip install pyatv zeroconf sh

On Debian and Raspbian (and Ubuntu) when you use apt to install python then the command python3 will point to the installed version of python3.5. That’s just how it’s packaged, so i think it’s safe to use it that way. However, if you want to absolutely make sure that you’re calling python 3.5 then you can also use the command python3.5
I don’t think it makes any difference to be honest.

I’m wondering if there is a way to detect if the AppleTV is either on or off?
I don’t mean having the ability to turn it on or off (I’m not really interested in that), but i mean detecting if it’s on or off.

I’ve had a read through the PyATV library and i’m not so sure if that can be done. Also, even when the AppleTV is off, it still replies to ping and when sending any command it will obviously wake up. I just can’t think of how to detect whether it’s on or off…

Do you have any idea’s on this?

lets answer this way: I spend a lot of time finding a way to detect the “screen status” of my setop box (Telekom TV receiver), which is similar. It’s always pingable, but you can’t query the display state.

One idea: If you could do a Wireshark on the IP of your AppleTV we could check it the ATV , which my setop box does. In this case I could implement a UPnP handler, which catches this message.

@JohnnyBravo I picked up your idea to detect the jpy path, so a simple .py

import jpy
print (jpy.__file__)

but it fails:

apt-get install python3-jpy
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3-jpy is already the newest version (0.8-5).
0 upgraded, 0 newly installed, 0 to remove and 72 not upgraded.
[23:24:35] root@home-oh:/var/lib/openhab2/tmp# pip3.5 install jpy
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: jpy in /usr/lib/python3/dist-packages (0.8.0)

python3.5 test.py
raceback (most recent call last):
  File "test.py", line 1, in <module>
    import jpy
ImportError: libjvm.so: cannot open shared object file: No such file or directory

I have

/usr/lib/jvm/java-8-openjdk-armhf/jre/lib/arm/client/libjvm.so
/usr/lib/jvm/zulu-embedded-8-armhf/jre/lib/aarch32/client/libjvm.so

which could be added to the LD_LIBRARY_PATH, but again we have a module where the binding would need to know the location.

This is a common problem when using jpy. It’s stupid if any app develop has to take this challenge there must be a smarter way.

I updated the README


Question: Are you running OH “directory” on the Synology, or in a VM which runs Debian Stretch?

Hi, I’m running a VM that has Debian Stretch on it.

It’s weird that you’re getting an error about libjvm.so
The only difference that I can think of is that I have Oracle Java 8 installed and not openjdk or zulu.
In my experience Oracle Java has been very stable where other java version have had some issues.

There’s two things that i would maybe try:

  1. Try reinstalling openjdk (sudo apt-get install --reinstall openjdk-8-jre-headless). This might fix any symlinks and could be an easy fix.
  2. Give Oracle Java 8 a try with the instructions below.

Oracle Java installation for RasPi:

sudo echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee /etc/apt/sources.list.d/webupd8team-java.list
sudo apt-get install dirmngr
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
sudo apt-get update
sudo apt-get install oracle-java8-installer

Note that you can also just issue ‘sudo apt-get install oracle-java8-jdk’ and this will work as the package exists in the raspbian repo, but this is quite and old version.
Using the steps above will ensure you have the latest stable release!

There can be multiple Java installations on one machine.
You can configure which version is the default for use in the command line by using:

sudo update-alternatives --config java

I’m going to have a go at wireshark now :wink:

Ok that confirms my assumption. A VM setup is different to “running openHAB and the binding natively on the NAS”. I also have a Synology, but no dev environment installed so far. I just make the first step and it seems not straight forward, because it’s not Debug (e.h. ipkg is not the same as apt-get). Mybe I find some time at the weekend.

For know I had no issues with OpenJDK and don’t want to switch, because openhabian is based on OpenJDK. The question is: Is my installation ist just broken (symlink) or is this a general issue with openhabian/openjdk, which means that other users will trap into the same problem. As shown above the .so module is there, but the directory is not added by LD_LIBRARY_PATH by the installation process.

Could anyone else with a RPi try to run the above script? so we get a feeling if this is a general fact or just a problem with my installation.

1 Like

Hi,

this binding is a big step forward! Used pyatv before. Besides it is a very nice developer. If you have questions regarding pyatv contact him. He will answer and is open for new ideas.

Because I am at work at the moment I cannot test, but will try later in the evening. Installation: RPi 3+ with openhabian 1.4 and openHAB 2.4 and Apple TV 4K.

Ciao
HFM

I have a RasPi laying around and gave it a try. I’m getting the exact same error message even though libjvm.so is there.

I tried re-installing openjdk, but that didn’t solve it.
I tried installing Oracle Java 8 as i described above, but that didn’t solve it either.
I finally added the path to LD_LIBRARY_PATH and it worked…

I dont understand why things seem to work just fine on a standard Debian installation, but not on a Raspbian installation. I’m surprised to see this actually…

thanks for the effort

at the end: different platforms means different setup scripts, maybe it’s an issue in the openhabian base image…