Binding for Apple-TV

yep, I’m already keeping that in mind. Even if those might not be auto-installed by the binding (which should be possible) the documentation should include the depend modules, because existing setups could be very different (more or less modules already installed).

One impact with jpy is that it needs the platform specific modules. That was the reasons why I like the option to install “python3-jpy with apt-get”. Obviously those modules are already loaded by openHAB (maybe by the integrated Jython support) so a load attempt by the binding results in a exception (see above). So for the moment I want to stay with the embedded modules, that could be changed later.


I could fix my Python3.5 setup by running “python3.5 get-pip.py” and “pip3.5 install zeroconf”. So your snippet could be part of an auto-install - it’s on the list :wink: Integration that script should be easy, but first 1 want to move forward to get a working alpha on macOS, Raspi and Synology (your environment)


I had version 18 and now 19 - I think this could also be handled by the script (pip3 install --upgrade pip)

yes, that’s correct and would be the smart thing to use the jpy modules installed by package python3-jpy. Python 3.5 will be the preferred choice, 3.6 is not widely adapted.

yes, libpython3.6m.so is the correct one, which I used for the 3.6 testing - same result like 3.5 :frowning:


What I don’t get is why it is working on macOS and not the Raspberry.


I’ll add your modules to the bundle so you could do some testing on your side. I already contacted the developer of pyatv - maybe he could provide some hints

alpha2 is ready to test on macOS and Raspberry, maybe Synology
https://github.com/markus7017/org.openhab.binding.appletv/blob/alpha2/target/org.openhab.binding.appletv-2.4.0-SNAPSHOT.jar

The problem was a mixup of Python 3.5 and 3.6. Now using Python 3.5 on the Raspberry


During startup the binding creates log files in /tmp

  • ohpyatv-console.log - stdout output
  • ohpyatv-error.log - stderr output

check those if something gets wrong (beside openhab log)

make sure you complete the “atvremote pair” sequence

verified it with HABpanel and it works well (running on RPI):grinning:

I installed the latest jar, and the thing is showing “Online” in paper UI. (I previously paired with atv remote). I am using openhabian on rp3.

So, how do I send commands? I’ve been trying with a couple sample switches in an items file as below, but it doesn’t seem to be working.

  Switch Atv_Menu "ATV Menu" <Switchable> ["Switchable"]{channel="appletv:device:34fc39d8:menu"}
Switch Atv_Play "ATV Play" <Switchable> ["Switchable"] {channel="appletv:device:34fc39d8:play"}

I have it working!

Items

String Atv_Remote "ATV [%s]" {channel="appletv:device:34fc39d8:control#remoteKey"}

Sitemap

Switch item=Atv_Remote mappings=[up = "^" ]
Switch item=Atv_Remote mappings=[left = "<", select = "Sel", right = ">" ]
Switch item=Atv_Remote mappings=[menu = "Menu", down = "  v   ", play = "Play" ]
Switch item=Atv_Remote mappings=[previous='Prev', pause='Pause', next='Next']

Log on startup

2019-02-24 20:48:30.759 [DEBUG] [org.openhab.binding.appletv         ] - BundleEvent INSTALLED - org.openhab.binding.appletv
2019-02-24 20:48:31.027 [DEBUG] [org.openhab.binding.appletv         ] - BundleEvent RESOLVED - org.openhab.binding.appletv
2019-02-24 20:48:31.032 [DEBUG] [org.openhab.binding.appletv         ] - BundleEvent [unknown:512] - org.openhab.binding.appletv
2019-02-24 20:48:34.011 [DEBUG] [org.openhab.binding.appletv         ] - ServiceEvent REGISTERED - {org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory}={service.id=83, service.bundleid=191, service.scope=bundle, component.name=org.openhab.binding.appletv.internal.AppleTVHandlerFactory, component.id=45} - org.openhab.binding.appletv
2019-02-24 20:48:39.486 [DEBUG] [org.openhab.binding.appletv         ] - BundleEvent STARTING - org.openhab.binding.appletv
2019-02-24 20:48:39.494 [DEBUG] [org.openhab.binding.appletv         ] - BundleEvent STARTED - org.openhab.binding.appletv
2019-02-24 20:48:39.517 [DEBUG] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.Factory: Activate HandlerFactory
2019-02-24 20:49:00.145 [INFO ] [letv.internal.handler.AppleTVHandler] - Apple-TV.Handler: Initializing AppleTV
2019-02-24 20:49:00.219 [DEBUG] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: Initialize PyATV (current installation path: 'null')
2019-02-24 20:49:00.227 [INFO ] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: Modules will be installed in '/var/lib/openhab2/tmp/ohlib-683765653998905557'
2019-02-24 20:49:00.229 [DEBUG] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: Platform info: 'linux', architecture: 'arm'
2019-02-24 20:49:00.232 [DEBUG] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: jpyLib=lib/jpy/lib.linux-armv7l-3.5
2019-02-24 20:49:00.235 [DEBUG] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: jpy.pythonExecutable: /usr/bin/python3
2019-02-24 20:49:00.237 [DEBUG] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: jpy.pythonLib: /usr/lib/arm-linux-gnueabihf/libpython3.5m.so
2019-02-24 20:49:00.240 [DEBUG] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: jpy.jpyLib: /var/lib/openhab2/tmp/ohlib-683765653998905557/jpy.so
2019-02-24 20:49:00.242 [DEBUG] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: jpy.jdlLib: /var/lib/openhab2/tmp/ohlib-683765653998905557/jdl.so
2019-02-24 20:49:00.245 [DEBUG] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: jpy.pythonPrefix: /usr
2019-02-24 20:49:00.385 [DEBUG] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: Starting Python
2019-02-24 20:49:00.776 [INFO ] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: load PyATV
2019-02-24 20:49:04.862 [INFO ] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: Sending command top_menu to ip 192.168.0.72, lid 0x86AD23F7032474BC
2019-02-24 20:49:04.990 [DEBUG] [letv.internal.handler.AppleTVHandler] - Apple-TV.Handler: PyATV installation path: /var/lib/openhab2/tmp/ohlib-683765653998905557

sounds great! Raspberry, correct?

Did you had to install any Python modules etc. beside those mentioned?


With regards to the jpy platform modules: As I learned I can’t load directory the jpy platform modules, because they are already loaded (at least in my setup). So to have a initial approach as well as avoiding conflicts with other apps I got the following idea:

  • The installation is based on the python3-jpy module, which needs to be available/installed
  • During installation the binding creates a copy of both modules and
  • loads this “private” copy = different file name = will be accepted by the JVM (like I do it now with the embedded copy)

This means the bundle doesn’t need to bring the modules for any platform variation. The only disadvantage is that I can’t make sure, which version I load, which might cause conflicts, but that could also happen with other modules.

Just installed the latest jar and for me the ‘thing’ now also shows as online.
The log however shows:

2019-02-25 10:56:17.088 [INFO ] [letv.internal.handler.AppleTVHandler] - Apple-TV.Handler: Initializing AppleTV
2019-02-25 10:56:17.094 [INFO ] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: Modules will be installed in '/var/lib/openhab2/tmp/ohlib-4567354087173947365'
2019-02-25 10:56:17.098 [ERROR] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: Unable to start Python (jpy): Architecture not supported yet, please contact the author and provde platform information (class java.lang.Exception)

Not sure why its doing this…?

BTW. I started having issues with python 3.6.8 so I removed it and just used apt to install python3 and libpython3 (it’s version 3.5.3 to be exact)

Just had a thought:
In one of my previous error messages

2019-02-22 12:21:47.623 [DEBUG] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: Platform info: 'linux', architecture: 'amd64'

The architecture there is listed as amd64, whereas i’ve also seen it as x86_64
Perhaps the appropriate jpy and jdl can just be copied to support both of these architectures?

It feels a bit like Python calls it x86_64 and java is calling it amd64, but in reality it’s the same…

Hi,

maybe Java detects that there with a AMD 64-bit processor rather than an Intel one.
I changed the code to match both:

if (os.contains("linux") && (platform.contains("x86_64") || platform.contains("amd64")))

next we will run into Ubunto runnuning on Intel/AMD…but for the moment - it’s alpha and early adoptors get priority :wink:

I still need the location of “libpython3.5m.so” for your setup

check this build: https://github.com/markus7017/org.openhab.binding.appletv/blob/alpha2/target/org.openhab.binding.appletv-2.4.0-SNAPSHOT.jar

Ah yes, sorry…
I seem to have 2 copies of libpython3.5m.so
one in: /usr/lib/x86_64-linux-gnu/libpython3.5m.so
and also one in: /usr/lib/python3.5/config-3.5m-x86_64-linux-gnu/libpython3.5m.so

With the latest jar the ‘thing’ shows as unkown again.
The log shows:

2019-02-25 12:46:38.835 [INFO ] [letv.internal.handler.AppleTVHandler] - Apple-TV.Handler: Initializing AppleTV
2019-02-25 12:46:38.843 [INFO ] [pletv.internal.AppleTVHandlerFactory] - Apple-TV.PyATV: Modules will be installed in '/var/lib/openhab2/tmp/ohlib-4823276808541727152'
2019-02-25 12:46:38.914 [WARN ] [mmon.WrappedScheduledExecutorService] - Scheduled runnable ended with an exception:
java.lang.UnsatisfiedLinkError: /var/lib/openhab2/tmp/ohlib-4823276808541727152/jpy.so: /var/lib/openhab2/tmp/ohlib-4823276808541727152/jpy.so: undefined symbol: PyFloat_Type
        at java.lang.ClassLoader$NativeLibrary.load(Native Method) ~[?:?]
        at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941) ~[?:?]
        at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1824) ~[?:?]
        at java.lang.Runtime.load0(Runtime.java:809) ~[?:?]
        at java.lang.System.load(System.java:1086) ~[?:?]
        at org.jpy.PyLib.loadLib(PyLib.java:416) ~[?:?]
        at org.jpy.PyLib.<clinit>(PyLib.java:465) ~[?:?]
        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) [?:?]

Hi everyone and thanks for all the tries regarding this binding.
Quick question, when you try to add the thing in UI asks for IP and Login ID, what’s the entry in Login ID? and Lib install path?
Thank you in advance.
Mike

Yes, Raspberry Pi, running openhabian.

I have several python modules from previous unsuccessful attempts to load pyatv. I also previously loaded jpy with apt-get.

ls /usr/bin | grep python

python
python2
python2.7
python2.7-config
python2-config
python3
python3.5
python3.5-config
python3.5m
python3.5m-config
python3-config
python3m
python3m-config
python-config

I noticed in the jpy documentation that they recommend using Oracle java for your jdk. I have a OpenJDK installed and it seems to be working.

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?