In order to let HA make use of scrips that involve remote.stua_1_etg it seems to need to be in the state ON, else the script does not execute its action.
When “switching it on” using the switch shown in the screenshot below, the script executes as expected.
The corresponding ATV is in the off state, and so is the remote after a HA reboot.
If I get this right, I cannot execute scripts that involve the media_player or the remote from this point.
When using the physical remote and switching the ATV device on its state in HA is still off as is the state for the remote in HA.
At this point the Apple TV is showing its home screen on my TV device. The TV is not smart connected.
The I use the physical Apple remote to turn on a TV station…
It starts playing.
Meanwhile both the remote and the media_player shows state off in HA.
Then after turning the remoteon, using the switch as shown below, the media_player is in the playing state.
SO: The issue here is how do I get the remote and the media_player to actually get into the on or at least idle state?.
YES I have configured my ATV NOT to turn on after HA startup, so I realize this is an issue. But I do not want the TV to turn itself on when booting HA…
Ok, then I understand your situation. It is currently not possible to solve this as the remote and media player share the same “on/off” state. It would in theory be possible, of course, to not have this kind of entanglement, e.g. keep the remote always on and turn on the media player on in case it is off and then send the command. Even though it sounds simple, it is not. It is better to do with a script as I mentioned.
The main problem is that Apple has decided that CEC should be triggered when the device wakes up, which happens whenever someone initiates a connection to it (I.e. when the TCP-connection is established) So it is technically impossible to have 1:1 connection between Home Assistant and the Apple TV from a power perspective without getting any unwanted side-effects. Disabling and not using CEC is the only way because then you can have the connection active at all times.
Not use start_off: true in the configuration of apple_tv - which I don’t at the moment
Run a script to ensure the Remote always has the state on using rumote.turn_on
I was hoping this automation would do the trick, but it does not turn the remote ON.
automation:
- alias: '[Apple TV] Turn remote on'
description: Makes sure the remote in HA is alwasy int the state ON
initial_state: 'on'
trigger:
- platform: template
value_template: "{{ is_state('remote.stua_1_etg', 'off') }}"
action:
service: remote.turn_on
entity_id: remote.stua_1_etg
I can change the state manually in the States page, and also by trigging the service remote.turn_on manually from the Service page.
Let the remote still be in state on to allow further scripts to run on it.
When going through these steps manually now, the scripts for turning Apple TV on or off works as expected.
script:
atv_stue_1etg_on:
alias: Apple TV stue 1. etg. ON
sequence:
- service: remote.send_command
data:
entity_id: remote.stua_1_etg
command:
- wakeup
atv_stue_1etg_off:
alias: Apple TV stue 1. etg. OFF
sequence:
- service: remote.send_command
data:
entity_id: remote.stua_1_etg
command:
- home_hold
- delay: 00:00:03
- service: remote.send_command
data:
entity_id: remote.stua_1_etg
command:
- select
Yes, that is correct. But remember, you must disable CEC on your Apple TV otherwise your TV and other equipment will be started whenever you restart Home Assistant (assuming they are off). No way around that.
Also, I’m not sure how you set up the Apple TV in the first place, but using configuration.yaml is only a wrapper for the config flow. Once the device has been added from configuration.yaml, that configuration is never used anymore (you can basically remove it). So if the device was initially set up with start_off set to true, then changing it to something else won’t make any difference. To change the value, just go to the Integrations page, pick your Apple TV from the list and click the settings icon in the top right. There’s a setting for “not turning on…” in the settings pane that you should un-tick.
Assuming that you changed so the integration turns on when starting Home Assistant, this should not be needed. It might be nice to have the possibility to manually turn off the integration in case something is acting up.
You should refrain from altering the state manually. It is not safe in the sense that the integration might not know what is up or down anymore. For the remote to work, the corresponding media_player must be on. They share the same connection to the Apple TV and without a connection, it’s not possible to send any commands no matter what the state of the remote. Due to the way the component is implemented, you should get an error in the logs in this case (stating that the device is not connected).
Yeah, this looks about right. This should work as expected as long as start_off is set to false and CEC is disabled, so you your TV and other devices doesn’t get powered on when you restart Home Assistant. I assume the “wakeup” is also only needed when it has gone to stand by with a black screen, so that it wakes up properly and shows image.
Thank you for a throughout walk-through.
As for the quoted text above. Can I conclude start_off is set to false and CEC is disabled when Apple TV do not start after a Home Assistant reboot?
Yeah, that should be fine. If your television (and other potenial equipment, e.g. receiver) does not turn on when you press a button on the pysical remote or use the remote app, then you are fine.
CEC is Consumer Electronics Control. It’s a sub-protocol within HDMI that allows devices to control other device, e.g. so that your TV can start your Bluray player automatically, set the correct source, and so on. It’s in a menu on the Apple TV somewhere, I don’t use it myself either but a lot of people seem to do so. I don’t think Apple uses the term CEC, they just talk about controlling other devices.
Edit2: @postlund the “- top_menu - Go to main menu (long press menu)” is not working correct. The top_menu command has the functionality of the single-click home-button, and not as expected the long-press menu-button. Can this be fixed somehow, since the long-press menu-button would give the opportunity of many scripts…
Yeah, the pyatv documentation is a good source. It will be part of the Home Assistant documentation as well.
Oh, yes. That actually sounds strange. It would make more sense that it worked like that. As long as it’s possible to do with the Remote app it should be possible. Please write a bug report for it and I’ll see what I can do.
It will at some point, the PR has been up for quite some time now but it needs a review from someone that can finally give it an OK. Not pushing it too hard at the moment as I have a few improvements for pyatv in the pipeline that should improve reliability a bit. You need to add the repo as a custom source in HACS in order to find it, instructions are here.
hi postlund, implemented your new apple tv integration yesterday because the tv was already on tvos 13
i just have to say it works marvelous!! We even made the remote (based on automatitions and send commands) and this just works, thumbs up!!
I was wondering will there be an entity card for a remote later on this project?