Apple TV not working properly

Hi, I have an Apple TV 4th generation and I’m having trouble integrating it. It shows up in HA, but when its on, it continuously jumps. I’m not sure if thats the best way to describe whats happening, but it appears it is turning off then on, off then on. When it s set to off, it stays off.
Also, it never displays anything other than No Title and the play button never changes to pause or stop.
If I click the three vertical dots, I am able to send a TTS to the TV just fine except it cuts off the first word of the message sent.
The “play_media” command works, but other commands such as “media_stop” is super delayed (over 1 minute).
The ‘turn_on/off’ commands don’t work at all, yet if I use the play_media command (not the play button) it will turn the apple tv on as well as the the TV its connected to via CEC, and will turn on if I restart HA.
My HA version is .39.0 and my apple Tv is auto discovered. I have tried also adding the apple tv manually, but there is no difference.
The showing whats playing isn’t very important, but I would love the ability to turn the tv on and off at least.

Has anyone got this working?
Thanks.

UPDATE:
After some more testing, It appears the jumpy on/off behavior corresponds to other devices in HA turning on/off or just changing states (like my Lifx bulb flashing)

I will try to answer your questions as good as I can. First off, there is no known way to turn on or turn off the Apple TV. The way it is implemented in Home Assistant is that if you turn it off, it will be seen as “off” and no requests will be sent to he device. It’s a sitting duck basically. I implemented this behavior as people using CEC were having problems with other devices turning on when for instance home assistant restarted. This was due to the fact that when a request is sent to the Apple TV (to query what is currently playing for instance), it would turn on and trigger your CEC configuration. This is what you see as well.

Why actions are delayed for you is not something I’ve seen or heard about before. But I get the feeling it might be related to other things in your configuration. Did you try the Apple TV integration in previous release? Also, manually configure or auto discover makes no difference.

So, the conclusion is that you will not be able to change power state of the device as no one knows of any way to do that yet. If you don’t want to add your Apple TV, I would recommend to not configure it manually and add it to ignore under discovery so that it is not automatically discovered (see documentation for this). Another way is to configure it manually and set the config option “start_off” to true. This way it will be added be it will start in off state, so your CEC configuration is not triggered. You can then manually start it from the UI or write an automation that does it, for instance if you switch to a certain input on your tv or receiver.

Hope this help, otherwise let me know!

Thanks for the reply! And for explaining some things. Let me pose a question here, if the Atv can be turned on by a media play event, then couldn’t that work to turn it on? Second, if the device is on, any command sent to it should work, including the off right?
Maybe I’m answering part of my own question here, but I’m not sure if the Atv has th command option of a straight “off” though, considering that you have to hold down the menu button then select sleep.

Yes, I encountered the issue where HA restarts would wake up my ATV, thus turn on my TV because I had CEC enabled.

Oddly/annoyingly, even without ATVs configured in my YAML, it would still do this. I ended up having to comment out discovery in my YAML to make it stop.

It sort-of can, yes. But it’s not a spot-on solution as “on” is quite vague. It doesn’t really mean anything if you don’t have CEC enabled, like me. The Apple TV will automatically turn on when it senses HDMI, so it works automatically.

Anyway, you get the behavior you are describing regarding “turn on” with current implementation (as turning it on will trigger a request, thus “turning on” the device in case it was off). As I said earlier, there is no known command for the protocol used by the “old” remote app. So that is not solvable per se. But I believe the device automatically switch off if you turn off the HDMI source, so if your TV/projector is switched off then the Apple TV is put the standby as well. It will not go to deep sleep until much later and it also requires some device to act as sleep proxy, too. From how I see it, the Apple TV was not designed to be put to sleep or awaken by itself. That is handled automatically by other devices depending on if HDMI signal is available or not. CEC is a bit special, but I guess that is to be able to handle cases where for instance an AirPlay stream is sent to the device. In that case you can start your TV and receiver automatically.

Yes, that is why I implemented “turn on/off” functionality as I have described. The discovery component will find your device (with no configuration, that is what discovery is for). You can either disable it for the Apple TV if you don’t use it:

discovery:
  ignore:
    - apple_tv

Or configure your Apple TV to always start in off mode, thus not doing anything at all:

media_player:
  - platform: apple_tv
    host: IP_ADDRESS
    login_id: LOGIN_ID
    start_off: true

Using the latter one allows you to use press “power on” in the UI to use the integration.

Thanks for the info! I didn’t realize discovery in the YAML had configuration options to explicitly ignore only certain devices. That might be handy for some other things later on.

I’d like to actually have the Apple TV show up as a media player, however I was struggling with getting it to do anything when I tried. I have a 3rd gen and 4th gen one, but only played with the 4th gen. When I’d send a skip button command, it would give a little spinner indicator like it was going to do something, and then nothing. I may try to revisit this later.

I did like the cute feature where I could make my Apple TV “talk”, though :slight_smile:

I’ve got the same odd behavior of the UI “jumping” every other second or so. It doesn’t seem to happen with a 3rd gen Apple TV, only on my two 4th gen models. It’s not a huge deal, doesn’t seem to effect anything else. Just random UI behavior. It seems like it could be polling the device every so often. It only started on 0.39

Also the description on what the power off does is helpful, was curious as to what that actually did. Makes sense.

Yeah, I added support for ignore in discovery because of situations like these :slight_smile: It was included in 0.39 so it’s brand new.

It should work fine on both 3rd and 4th gen devices. I only have a 3rd gen myself, but other people have verified on 4th gen for me. What the skip command does depends on what you are playing. For video for instance, it will skip 10 seconds I think. You can compare behavior with the Remote app if you want. Should be the same.

Same for TTS, should work out-of-the-box in the UI :slight_smile: It does for me at least.

Polling is done every ten seconds, so it’s probably with that interval. But it should not flicker. Must be that a state change is found for some reason. Anyway, I believe this will be fixed once and for all when I add support for push updates, which will be ready in the next release. That will also give instant updates, which is quite nice.

Cool, I can hold out until the next release, doesn’t effect functionality so it’s all good.

Sweet, thanks!

Just created a PR for push update, available here: https://github.com/home-assistant/home-assistant/pull/6323
Give it a spin if you have the chance!

New here and found this thread trying to fix my problem so bumping it - hope that’s OK.

So, there’s a few posts about Apple TV “randomly” turning on, however my problem is more similar to this thread which describes the jumping in the UI. My issue is not another device like to original post update and I do not have a problem where it’s only displaying “No title”. Everything seems to be working, except I can’t keep my TV off.

I can live with the jumping in the UI, however, since I’m using CEC (and would like to keep doing that) every time I shut down my Apple TV (and thus the TV), the Apple TV and TV will start again within 1 - 5 minutes.

Even if I were to remove the CEC (which I tried), the Apple TV will still start up and that means that the Apple TV would be on (not in stand-by) 24/7 which I would like to avoid. Since I’m running Home Assistant on an always-on Raspbery Pi the polling will be made 24/7.

I’ve read about the “start_off” parameter, disabling of Apple TV discovery (my Apple TVs is added manually) etcetera but nothing really resolves my issue. So after reading this post I understood that the “start_off” is the same thing as turning the Apple TV off in the UI (no polling will be made), right? Since the jumping won’t occur in this state, nor does the TV start - this kind of resolves my issue. However I have automations setup in Home Assistant which tweaks my lights depending on states of the Apple TV so I don’t want it switched off while actually on. This is my configuration:

discovery:
  ignore:
    - apple_tv

apple_tv:
  - host: 10.10.1.17
    login_id: 00000000-xxxx-xxxx-xxxx-xxxxxxxxxxxx
    name: "Apple TV Living room"
    start_off: true

Since the TV I’m using is a Sony Bravia I was able to connect my TV to Home Assistant. Now what I’ve done is that I’ve added the following automations:

- action:
  - alias: Turn on Apple TV
    data:
      entity_id: remote.apple_tv_living_room
    service: remote.turn_on
  trigger:
  - entity_id: media_player.sony_bravia_tv
    from: 'off'
    platform: state
    to: 'on'
- action:
  - alias: Turn off Apple TV
    data:
      entity_id: remote.apple_tv_living_room
    service: remote.turn_off
  trigger:
  - entity_id: media_player.sony_bravia_tv
    from: 'on'
    platform: state
    to: 'off'

Speaking of that, is there a way to not add the remotes for every Apple TV? I can’t really see the usage of the remote since all I can do with it is to toggle the Apple TV on or off which can also be done via media_player.apple_tv.

This makes sure that whenever the TV is not on, the Apple TV in HA will be off and vice versa.

  • Is this really the intended way to setup an Apple TV 4?
  • Is there a way to avoid the Apple TV from always starting when HA is on?
  • If I turn off CEC - should the Apple TV be on 24/7 anyway?

This issue is only present on Apple TV 4 and not with Apple TV 3.

Setup
Raspberry Pi 1 (Model B)
Linux hassbian 4.9.35+ (although I had to install pyatv/atvremote manually anyway)
HA 0.51.1
Python 3.4.2
Combined with homebridge-homeassistant

Edit
Ok, it seems like the bouncing UI might be related to this, only larger jumps. Since that’s a known bug I guess my only problem is that I cannot keep my Apple TV/TV turend off.

1 Like

Hope it’s OK to bump this, I haven’t made any progress. @postlund Can you confirm or deny that the behaviour I’m experiencing is the intended way?

Yes, you have basically answered your own question. If you use CEC then you will have to turn it off (preferably using start_off:) in HA when not using it, otherwise it will start automatically at some point (especially since HA will set up a connection to it and wait for changes). As I have said before and written in the documentation, this is the design chosen by Apple and nothing I can do anything about. Using an automation to turn it on, like you have described above is the best solution I have come up with, so that’s what I would recommend.

It’s kinda like you can’t have the cake and eat it to. In order to know what is currently playing, the device must be on. So yes, even if you disable CEC, the device will be on otherwise there will be no way of knowing what the device is up to. This is also how all other platforms and components work in HA, so it’s nothing unique here.

Regarding remotes, you will have to hide them manually. Remotes are setup automatically when a device is added. You can use them to send other key presses too (like arrow keys, menu, …) but you must use the service for that since the UI currently only implements turn on/off.

1 Like

Hi everyone,
I’ve added this configuration to my HA, but as a result my appletv seems to end up being not detected by HA. I can’t even find it as an entity. I’m wondering if apart from configuring HA this way, I’m supposed to do something else.
My understanding is that, in order to avoid AppleTV from switching on my TV over CEC, one must add the start_off toggler. If then one defines a static AppleTV, should that not generate an entity? assuming this is the case, why is it not being displayed in the Overview section of HA? If the answer is no, then I understand that the automations enable you to actually see an AppleTV in the Overview section?
thanks a lot in advance,

anybody can help me with this? Thanks! :slight_smile:

You should get a media_player entity. Have you taken a look into the log? Without any further details it’s hard to tell what’s wrong.

The configuration you quoted from me is the configuration I still use, however I don’t think the ‘start_off’ option is of any help in this case since it will handle the ATV as turned off and thus not poll anything. If you want to use any kind of trigger related to your ATV it must be switched on in HA.

If you remove your manually added section for the Apple TV and enable the discovery service again, do you see your ATV?