Tv Idle automation

Hi there, i am quite new on HA, i am trying to create an automation with my sony tv whenever becomes idle or stopped playing for few minutes should then change to HDMI 1 input. I did try to create the automation setting the state of the tv as idle as trigger and call adb android tv command HDMI1 as action but doesn’t start, the adb command works on his own.

Please share the YAML for what you tried. Make sure to format it for the forum correctly, see: https://community.home-assistant.io/t/how-to-help-us-help-you-or-how-to-ask-a-good-question/114371#oneone-format-it-properly-16

alias: "Tv Idle "
description: ""
trigger:
  - platform: state
    entity_id:
      - media_player.living_room_tv_2
    from: playing
    to: idle
    for:
      hours: 0
      minutes: 0
      seconds: 30
    id: Tv Idle
condition:
  - condition: trigger
    id:
      - Tv Idle
action:
  - service: androidtv.adb_command
    target:
      entity_id: media_player.sony_tv
    data:
      command: HDMI1
mode: single`Preformatted text`

Format it properly.

f6be36681e0da431418ec7781fb6c62712941803

How to do that ? i don’t understand the screenshot

Click the link you were provided.

You click on </>, this appears

type or paste code here

Then you paste your code there.

Is it ok now?

Can you check if the automation is active? Go to Settings → automations and check if the icon is greyed out or red. If it is then your code is not properly formated.

Then check if was triggered and take a look at traces.

Also remember to reload the automations when you edit them.

I think you need to remove the condition

Removed but still doesn’t work, automation is active created with gui so how the code can be wrong,?

How to reload the automation?

Developer tools → YAML → Automations

Done nothing happens with any tv state

I dont know, try removing the from: playing , and leave the to: idle

trigger:
  - platform: state
    entity_id: media_player.living_room_tv_2
    to: 'idle'
    for:
      seconds: 5

And just for the test, put five seconds.

Are you sure the state of media_player.living_room_tv_2 is showing as idle?
Check it in developer tools, states

I do it the other way around. There is more than one state a media player can change to (off, idle, paused) when not playing. This is the trigger I use to change out of my movie scene:

  trigger:
    platform: state
    entity_id: media_player.lounge_osmc_kodi
    from: 'playing'
    for:
      seconds: 1

Thanks, your trick works better, i changed the Tv device and now seams to work the automation. Luca.