Binding for Apple-TV

Great work!
I will test it now.
Was just about to sit down and have another go, but you beat me to it :slight_smile: .

I believe AI is hallucinating here, because I’m fairly certain this openhab/tmp folder is populated by these manual steps we have to do every time there is a new OH version. Regular restarts should be OK.

OH_HOME=/var/lib/openhab
sudo chmod 777 /var/lib/openhab/tmp
python3 -m venv $OH_HOME/tmp/appletv-binding
source $OH_HOME/tmp/appletv-binding/bin/activate
pip3 install git+https://git.sr.ht/~hww3/pyatv

Edit:


Only difference is that my python version was 3.12 instead of 3.11 :slight_smile:

No hero and not a spare per se, but I have a second ATV4k in my basement den with no current automations, but connected to OH. I could, from now on do updates on that one first, and post here whether new updates are OK or not.

Worked for me as well. Thx! :slight_smile:

Others experiencing stale channel updates lately?
After turning on with remote, hours later power channel shows off.
Disabling and reenabling updates to true state again.
I’m on 5.2.0M2

not sure when it happened but my instance has errors rigtht now and i cant fix them

Version: 5.1.4 (Build)

2026-06-13 14:04:22.250 [WARN ] [ding.appletv.internal.AppleTVHandler] - Pairing failed: 2026-06-13 14:04:21 ERROR [pyatv.protocols.companion]: Could not fetch SystemStatus, power_state will not work (Command FetchAttentionState failed)
Traceback (most recent call last):
  File "/usr/lib/python3.13/asyncio/tasks.py", line 507, in wait_for
    return await fut
           ^^^^^^^^^
  File "/usr/lib/python3.13/asyncio/locks.py", line 213, in wait
    await fut
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/var/lib/openhab/tmp/appletv-binding/lib/python3.13/site-packages/pyatv/protocols/companion/api.py", line 172, in _send_command
    resp = await self._protocol.exchange_opack(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<6 lines>...
    )
    ^
  File "/var/lib/openhab/tmp/appletv-binding/lib/python3.13/site-packages/pyatv/protocols/companion/protocol.py", line 153, in exchange_opack
    return await self._exchange_generic_opack(frame_type, data, identifier, timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/lib/openhab/tmp/appletv-binding/lib/python3.13/site-packages/pyatv/protocols/companion/protocol.py", line 166, in _exchange_generic_opack
    unpacked_object = await self._queues[identifier].wait(timeout)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/lib/openhab/tmp/appletv-binding/lib/python3.13/site-packages/pyatv/support/collections.py", line 161, in wait
    await asyncio.wait_for(self._event.wait(), timeout)
  File "/usr/lib/python3.13/asyncio/tasks.py", line 506, in wait_for
    async with timeouts.timeout(timeout):
               ~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/usr/lib/python3.13/asyncio/timeouts.py", line 116, in __aexit__
    raise TimeoutError from exc_val
TimeoutError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/var/lib/openhab/tmp/appletv-binding/lib/python3.13/site-packages/pyatv/protocols/companion/__init__.py", line 219, in initialize
    system_status = await self.api.fetch_attention_state()
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/lib/openhab/tmp/appletv-binding/lib/python3.13/site-packages/pyatv/protocols/companion/api.py", line 439, in fetch_attention_state
    resp = await self._send_command("FetchAttentionState", {})
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/lib/openhab/tmp/appletv-binding/lib/python3.13/site-packages/pyatv/protocols/companion/api.py", line 183, in _send_command
    raise exceptions.ProtocolError(f"Command {identifier} failed") from ex
pyatv.exceptions.ProtocolError: Command FetchAttentionState failed
12:54:B9:78:AA:8B

@hww3
Any chance you could share your latest binding source? (5.0.1)
Or if you already did, where can i find it?

Thanks.

Hello-

The source is located at:

I’m traveling this week, but should be able to spend a little time looking at this when I return mid-next-week.

Thanks, but both I and my AI agent is at a loss as to how to build a jar from this source.
AI claims it can only find version 4.3.2, but I am currently running version 5.0.1 of the binding.
Any pointers?

The code for both versions is the same, it’s just that the openhab it’s built against is different.

I’m currently out of town for work, but will be back home in a few days and can try to get an up-to-date version prepared for testing.

So I upgraded OpenHAB from 5.0.1 to 5.2.0… and now the Apple TV binding is offline :flushed_face:

Any suggestions as to how I should approach fixing it? Thanks!

I guess you’ll probably want to look in the log files to see what happens when the bundle loads. You can use the bundle:list and bundle:restart commands to find the bundle id and trigger a reload of the binding.

Once you have that information, it will be much easier to speculate on the source of the problem.

Bill

You need to do this song and dance again:

OH_HOME=/var/lib/openhab
sudo chmod 777 /var/lib/openhab/tmp
python3 -m venv $OH_HOME/tmp/appletv-binding
source $OH_HOME/tmp/appletv-binding/bin/activate
pip3 install git+https://git.sr.ht/~hww3/pyatv

Thank you! That worked, plus I added the code to the init.py file. I shall be a little more cautious when performing the next update!

Nice.. :smiling_face:
Do you get consistent power status reports over time?
Mine gets stale after half a day or so and automations fail.
Disabling and reenabling the appletv thing gets it working for some hours again..

What do you mean by power status reports? Nothing of my setup goes stale, the whole setup remains very stable.

After a few hours if I turn my TV off using the Siri remote, the Power channel state remains On.
Similarly if Off, On is not reported.

Ah, got it. I’ve not had this experience. The Apple TV power state reports and updates correctly. I have several events trigger (Sonos music stops, lights dim) when the Apple TV turns on and it works every time.

Hi- A quick update: I’m back in town and had a little time to set up an openhab 5.2 environment. I can confirm that the binding I was running under openhab 4.3 runs just fine on 5.2, no new version is required. I have some small bits of code that haven’t been pushed to the source repository, I need to understand where I was heading with that, but I think they were minor improvements that should be available later this week.

However, if you happen to be using the audio sink feature, that doesn’t seem to be working (though it was not completely reliable to begin with, mostly due to apple breaking things frequently). I had seen it work on HomePods, but it didn’t seem to work on AppleTVs. Trying to get that working in some fashion is on the to-do list.

Also, my AppleTV is still running tvOS 26.4, so doesn’t exhibit the problems that others have reported on newer versions of tvOS. I have an older device sitting on a shelf and I’m going to see whether I can upgrade it to do some testing with the fixes in pyatv that reportedly fix the problem.

Finally, I hear everyone’s tiredness with having to reinstall pyatv on a regular basis. I can’t guarantee a reliable result, but I have some ideas about how to at least attempt an auto-install. That might take a bit of time, so I make no promises about when that will be ready.

I appreciate everyone’s patience as we continue to work our way around various problems that are showing up. Please do continue to report problems here so we can understand what’s working (or not).

Thanks again!

Glad you have the opportunity to spend some time with the binding again..

My 2 main issues is that the channel updates goes stale after a while. Disabling and reenabling makes it ok again for a while. Rarly survives the night.

I’m on 5.2 release and have 2 AppleTVs connected, both on the latest TVos.

Also, the binding is very log talkative, constantly flooding the logs making normal logs hard to read.

Regarding the stale update, an AI session suggested a fix, but I ran out of tokens and after an involuntary Windows update I lost the chat history.

So, your two concerns are interlinked and somewhat at odds… 1) The cause of your problem of the binding losing track of the state of the device is likely caused by pyatv not reporting state changes after a while. This is likely due to some quirk of the AppleTV silently stopping its reports. Unfortunately, there isn’t much the binding can do to fix this problem, since the binding only sees a working connection to pyatv. Your options are probably limited to a rule or cron job that periodically restarts the binding, forcing a a new connection to pyatv and thus the device in question. That’s a highly unsatisfying solution from an engineering standpoint, but it might solve your problem in a practical way.

The problem with making the finding less “talkative” is that it makes troubleshooting these sorts of problems far more difficult. It’s always possible to filter out the undesired lines when you don’t need them, but if the data isn’t captured, there’s no way to know what’s happened. I certainly understand the annoyance of having so much log traffic (I certainly feel it myself at times), but having the data has at times meant the difference between solving a problem and having to wait for it to reappear later.

A tip: you can use grep to find both lines for the appletv binding or exclude all lines from the binding:

# show only lines from appletv
tail -f openhab.log |grep  apple 
# show lines that /aren't/ from appletv
tail -f openhab.log | grep -v apple