Apple TV - apple_tv:failed to login

  • TV on, ATV showing screensaver.
  • Restart HA.
  • Play 21 Jump Street on Plex on ATV.
  • ATV component displays title correctly.
  • Call atvremote playing from another shell: Correct title
  • Stop movie.
  • HA doesn’t react. Still shows title as playing rather than “No title”.
  • atvremote shows “Paused”

Logs:

Timestamped image of ATV component playing after atvremote reported Paused (as well as Plex component):

Great summary there! What I was starting to suspect was aiohttp, but since push_updates with atvremote works… it would still feel a bit better to try an older version. Could you maybe try pinning an older version, like 2.0.0 and run Home assistant again? There has been issues with aiohttp in the past. Another way is to sniff traffic with wireshark and see if updates some from the Apple TV but is not propagated correctly to user space.

1 Like

I was using playing rather than push_updates btw, but I’m pretty sure the same effect would have been seen.

Could you give me some more info on the commands to get that to work? I don’t know how to do that :confused: (My git experience is nil).

Yeah, I assume that it be the same based on earlier experiments.

How did you install Home assistant?

I’m running Hassbian.

So a virtualenv under /srv/homeassistant and my config here: /home/homeassistant/.homeassistant

So, i think you can just activate your virtualenv, remove aiohttp and install it again, e.g.:
pip uninstall aiohttp
pip install aiohttp==2.0.0
Then just restart hass. Hope that works.

Hmm… So the aiohttp install worked correctly ( https://hastebin.com/coqabizufi ) but for the life of me I cannot get the pyatv component to see anything. It just displays “No title”.

I tried starting HA with the ATV off, on the main screen, in Plex but in screensaver, nothing. Starting HA during any of those states and playing 21 Jump Street yields nothing. Here’s the log just in case: https://hastebin.com/ohekavaraz

Interestingly, atvremote fails to detect that 21 Jump Street is playing too: https://hastebin.com/jozigifasu

Again, no reaction in HA log that atvremote used session 84.

I’m seeing a similar problem to @chimpy above.
Running HA 0.43.0

The HA component is just reporting “No Title” even when playing something on the atv. I dug a little further, outside of HA…

While playing a show on the atv (via plex) I ran this command in a terminal on the HA machine:
atvremote --address <redacted> --login_id <redacted> playing

Which returns the following:

album: None
artist: None
media_type: 2
play_state: 3
position: 0
title: None
total_time: 0

Then I ran the same command with debugging:
atvremote --address <redacted> --login_id <redacted> playing --debug

Here’s the output:

DEBUG: GET URL: http://<redacted>:3689/login?hsgid=<redacted>&hasFP=1
DEBUG: Data[32]: b'6d6c6f67000000186d73747400000004000000c86d6c69640000000400000015'
DEBUG: _login_request: mlog: [container, dmap.loginresponse]
  mstt: 200 [uint, dmap.status]
  mlid: 21 [uint, dmap.sessionid]
INFO: Logged in and got session id 21
DEBUG: GET URL: http://<redacted>:3689/ctrl-int/1/playstatusupdate?session-id=21&revision-number=0
DEBUG: Data[155]: b'636d7374000000936d73747400000004000000c8636d737200000004000001bb63616673000000010063616665000000010063617665000000010063617673000000010063617073000000010363617368000000010063617270000000010063616172000000040000000663616173000000040000000263616b730000000101'...
DEBUG: _get_request: cmst: [container, dmcp.playstatus]
  mstt: 200 [uint, dmap.status]
  cmsr: 443 [uint, dmcp.serverrevision]
  cafs: 0 [uint, dacp.fullscreen]
  cafe: False [bool, dacp.fullscreenenabled]
  cave: False [bool, dacp.dacpvisualizerenabled]
  cavs: 0 [uint, dacp.visualizer]
  caps: 3 [uint, dacp.playstatus]
  cash: 0 [uint, dacp.shufflestate]
  carp: 0 [uint, dacp.repeatstate]
  caar: 6 [uint, dacp.albumrepeat]
  caas: 2 [uint, dacp.albumshuffle]
  caks: 1 [uint, unknown tag]
  casc: 1 [uint, unknown tag]
  cavc: True [bool, dacp.volumecontrollable]
  casu: 0 [uint, dacp.su]
DEBUG: Already logged in, re-using seasion id 21
DEBUG: GET URL: http://<redacted>:3689/ctrl-int/1/playstatusupdate?session-id=21&revision-number=0
DEBUG: Data[155]: b'636d7374000000936d73747400000004000000c8636d737200000004000001bb63616673000000010063616665000000010063617665000000010063617673000000010063617073000000010363617368000000010063617270000000010063616172000000040000000663616173000000040000000263616b730000000101'...
DEBUG: _get_request: cmst: [container, dmcp.playstatus]
  mstt: 200 [uint, dmap.status]
  cmsr: 443 [uint, dmcp.serverrevision]
  cafs: 0 [uint, dacp.fullscreen]
  cafe: False [bool, dacp.fullscreenenabled]
  cave: False [bool, dacp.dacpvisualizerenabled]
  cavs: 0 [uint, dacp.visualizer]
  caps: 3 [uint, dacp.playstatus]
  cash: 0 [uint, dacp.shufflestate]
  carp: 0 [uint, dacp.repeatstate]
  caar: 6 [uint, dacp.albumrepeat]
  caas: 2 [uint, dacp.albumshuffle]
  caks: 1 [uint, unknown tag]
  casc: 1 [uint, unknown tag]
  cavc: True [bool, dacp.volumecontrollable]
  casu: 0 [uint, dacp.su]
album: None
artist: None
media_type: 2
play_state: 3
position: 0
title: None
total_time: 0

Makes me think Apple silently (and sadly) changed something in their atv code, since this same command used to return information about what the atv was playing. Anyone else seeing this behavior?

Please let me know if we need some more details.

As of 0.44.1, my ATV card simply permanently states, “Not connected to Apple TV”.

/srv/homeassistant/bin/atvremote --debug -a playing reports paused and playing status correctly though.

Can you provide any logs from Home Assistant? It’s not possible to draw any conclusion without that.

Hey @postlund,

Check these out: https://hastebin.com/tezopatobi

Initial loading on the ATV component, then I included the 4 shell commands I use to turn my TV/ATV on, then a test I ran just now with pyatv.

I was watching TV all last night and got nothing from the ATV component.

As we saw earlier, it seems it gets a login ID and then fails to replace it when my 4 pyatv commands (that I use to turn on the TV) invalidate it.

Let me know your thoughts.

Hey @postlund , so I just restarted HA, and then turned on the TV with my remote (rather than my automation) and the component works.

So yeah, try issuing an atvremote command and seeing whether your component continues to respond: mine doesn’t.

Problem seems to be that the component only tries to use the first login ID it obtains, without checking if it’s actually still valid (and renewing if not).

Lastly, even though the component is working (if I don’t use any atvremote commands), I have no album/series art (earlier versions had it) - is this normal?

The problem isn’t that the wrong session id (not login id) is used, because that is allocated by the Apple TV and returned during a login. If an invalid session id is used, then the Apple TV will respond with error when doing requests (which will make pyatv try to re-login, thus getting a new session id).

Once Home Assistant is up and running, push updates are used. This means that a request is made to the device that just keeps hanging/waiting until something happens. After this Home Assistant does nothing - it is a sitting duck. When the Apple TV changes state, for instance starts playing something, then the hanging request will return current media state, update the component and start all over again (a new hanging request). This keeps happening when state changes on the Apple TV. The problem seems to be that the hanging connection just keeps hanging, even when something happens. For example like when you use the atvremote, which should break the connection in HA and trigger a re-login followed by a new hanging connection. I don’t know why this happens and it’s really hard to troubleshoot. Could be that the device is not doing what it should, some problem with aiohttp, other network issues or something completely different. I don’t seem to have this issue with my ATV3 and I’m almost starting to give up ATV4 support using DAAP, there are just too many issues.

The artwork is a recurring bug that I seem to not be able to sort out… It of course should work and one rainy day when I get some time, I will try to fix that. I would also like to upgrade to pyatv 0.3.0 as well but there are some dependency issues to deal with, unfortunately.

2 Likes

My bad about the session id/login id mix up.
I understand what you mean and that’s what I thought was happening too.

It would be a real shame to give up on ATV4 support as when it works it’s super! :slight_smile: I apologise about being the bearer of bad news.

I tested atvremote directly in two shells: If I do “-a push_updates” in one and get the correct status, then I can cause the session to hang (and not request a new session_id) by running “-a playing” in the other shell. Just in case that helps. (Obviously ctrl-c on the “push_updates” shell and re-running the command gives a new session_id and correct output).

Thanks again for your contribution to the project!

I tried this command, but I ended up with this big error:

Command “/srv/homeassistant/bin/python3 -u -c “import setuptools, tokenize;file=‘/tmp/pip-build-tw6ewxjh/cffi/setup.py’;f=getattr(tokenize, ‘open’, open)(file);code=f.read().replace(‘\r\n’, ‘\n’);f.close();exec(compile(code, file, ‘exec’))” install --record /tmp/pip-k13suuij-record/install-record.txt --single-version-externally-managed --compile --install-headers /srv/homeassistant/include/site/python3.4/cffi” failed with error code 1 in /tmp/pip-build-tw6ewxjh/cffi/

@postlund Thank you thank you thank you thank you thank you thank you!

0.49 with the remote functionality is perfect! I can turn on my TV and navigate to specific apps without resorting to shell commands, so the ATV stays logged in. THANK YOU!

I’m glad you liked it! :smile:

1 Like

Hello again!

Sorry to be the bearer of bad news again :disappointed:
It seems like the error is back. I keep getting “Establishing a connection to Apple TV” in the front end.
I can’t help but think this may be because of the modification you pushed recently as everything was working fine before that.
Any thoughts?

I feel that it would be very unlikely as I didn’t change anything related to the protocol logic (dependencies will have been bumped to higher versions, so that has changed though). Could you extract the actual error from the logs? The text from the UI doesn’t say much really.

I will only make a quick check if it’s an easy fix. My current stand is that I will not support any issues with ATV4(K) until I have fully implemented support for MRP. It’s in the making but not finished yet.

Hey @postlund, do you have an ATV4? If not, I bet we could take up a collection to send you one as a thank you for all the work you’ve put into this and make troubleshooting a little easier.

1 Like