Hi Home Assistant Community,
i have multiple apple tv 4k.
I use the following Scripts to control power state:
power off script (scripts.yml)
atv01_off:
alias: ATV01 off
sequence:
- service: remote.send_command
target:
entity_id: remote.atv01
data:
command:
- home_hold
- select
- service: media_player.turn_off
target:
entity_id: media_player.atv01
power on script (scripts.yml)
atv01_trigger_on:
alias: ATV01 on trigger
sequence:
- service: remote.send_command
target:
entity_id: remote.atv01
data:
command:
- home
- service: media_player.turn_on
target:
entity_id: media_player.atv01
sadly i need to execute power on trigger twice, because of that error:
2021-03-10 08:32:59 ERROR (MainThread) [homeassistant.components.apple_tv.remote] Unable to send commands, not connected to ATV01
Thats why i created third script (scripts.yml) calling the power on trigger script twice
atv01_on:
alias: ATV01 on
sequence:
- repeat:
count: '1'
sequence:
- service: script.atv01_trigger_on
data: {}
- delay:
hours: 0
minutes: 0
seconds: 2
milliseconds: 0
- service: script.atv01_trigger_on
mode: single
i wrap these scripts into a button (switch.yml)
- platform: template
switches:
atv01_power_switch:
friendly_name: ATV01
value_template: >-
{% if is_state('media_player.atv01','off') %}Off
{% else %}On
{% endif %}
turn_on:
service: script.atv01_on
turn_off:
service: script.atv01_of
Now my questions:
a) Can you help me finding out why i need to send power on command twice?
and
b) how can i create a single script for powering on and off the devices, with parameter (e.g. atv01, atv02 …) for using these scripts with different (calculated) entity ids for media player and remote? Can entity ids be calculated via script? Also i am a little bit stuck with the “data” and the “data-template” and the “fields” and the “variables” Can you help me solving that puzzle, so that i can use two parameterized scripts in multiple buttons for multiple atvs?
Regards
Clem