Automation - Call switch when my Sony Bravia goes into App mode

Hi

Iv been trying to call a switch when my tv goes into app mode, here is what i have tried using examples iv found:

automation switch to kodi:
alias: Switch to kodi input
trigger:
platform: state
from: ‘HDMI 1’
to: ‘App’
entity_id: media_player.sony_tv
action:
service: switch.turn_on
entity_id:
- switch.kodi_input_amp

automation switch to tv:
alias: Switch to TV input
trigger:
platform: state
from: ‘App’
to: ‘HDMI 1’
entity_id: media_player.sony_tv
action:
service: switch.turn_on
entity_id:
- switch.tv_input_amp

The switch that it calls send an ir command to my amp, so id like to be able to switch to the relevant input based on what state my tv is in.

The first 2 automations above work if i trigger them, but they havent been triggered automatically yet,

Can anyone help?

Do you use a specific input when you go to App mode, or could it be from any of your input’s? Thinking maybe you could track the change from/to “HDMI 1” or “HDMI 2”

When I want to watch TV, the state of my TV is hdmi 1. When I launch kodi from my TV (Its an android TV) the state changes to app.

So based on what state the TV is in, I want a switch to turn on - switch.kodi_input_amp

Everything goes through hdmi 1 on my tv, I don’t use hdmi 2.

Thanks for the response

Hmmm, I went to the home menu on mine and it still showed HDMI2. I’ll have to see what happens if I actually select something from the menu.

Yeah you need to open an app to go into the app state.

ok, I’ll play with it when I get home tonight and see what I can figure out.

what about something like this :

  trigger:
    platform: template
    value_template: "{{ is_state_attr('media_player.sony_bravia_tv', 'media_content_id', 'App') }}"  

I’ll give this a go shortly, haven’t looked at templating yet so thanks for the code!

like yllar said it’s under the media_content_id or the media_title. But you may need to check and see if it’s on first. Those attributes disappear if the tv isn’t on.

1 Like

hi all,

this looks good and after reading some documentation it appears to be the correct approach, although its not working just yet:

automation switch to kodi: alias: Switch to kodi input trigger: platform: template value_template: "{{ is_state_attr('media_player.sony_bravia_tv', 'media_title', 'App') }}" action: service: switch.turn_on entity_id:

Both media_content_id and the media_title are listed in my states page and return App so everything appears to be correct… just isnt working…yet

is the entity_id correct? your first example has media_player.sony_tv but this snippet is using my example media_player.sony_bravia_tv

@yllar school boy error! It used to be sony_bravia_tv before but forgot i changed it…

Thanks alot for your help mate

automation switch to kodi: alias: Switch to kodi input trigger: platform: template value_template: "{{ is_state_attr('media_player.sony_tv', 'media_title', 'App') }}" action: service: switch.turn_on entity_id: switch.kodi_input_amp

automation switch to tv:
alias: Switch to tv input
trigger:
platform: template
value_template: “{{ is_state_attr(‘media_player.sony_tv’, ‘media_title’, ‘HDMI 1’) }}”
action:
service: switch.turn_on
entity_id: switch.tv_input_amp

Now i want to switch the input to hdmi 1 on my tv when i switch my switch.tv_input_amp on - basically closing the app im using on my tv.

Iv only created my own switches so far, haven’t tested many of the components. But i can see and set HDMI 1 using the sony bravia component using the input selector, so would i just call the input_select.xxx ?

thank all