Conditions (And + Or) in Script

Sometimes it doesn’t capture well enough that chromecast went idle but right away another clip starting playing again and Hass automation didn’t capture that new “playing”.
So just before my timer script really turns off the tv after 20min I want to do a last check if both Kodi and Chromecast are indeed Idle and or Off.
However the below tvidletimer2 script gives errors when Hass is starting. So it’s not working.

tvidletimer1:
  alias: "Start Turn Off tv timer"
  sequence:
    # Cancel ev. old timers
    - service: script.turn_off
      data:
        entity_id: script.tvidletimer2
    # Set new timer
    - service: script.turn_on
      data:
        entity_id: script.tvidletimer2

tvidletimer2:
  alias: "Turn off tv after 20 min"
  sequence:
    - delay:
        minutes: 20
    - condition:
       condition: and
       conditions:
       - condition: state
         entity_id: media_player.kodi
         state: 'idle'
       - condition: or
         conditions:
         - condition: state
           entity_id: media_player.tv_ls
           state: 'idle'
         - condition: state
           entity_id: media_player.tv_ls
           state: 'off'
    - service: media_player.turn_off
      data:
        entity_id:
        - media_player.sony_bravia_tv

Anyone an idea how to fix this?

Seems that your indentation for conditions is wrong.
Try this:

tvidletimer2:
  alias: "Turn off tv after 20 min"
  sequence:
    - delay:
        minutes: 20
    - condition:
        condition: and
        conditions:
          - condition: state
            entity_id: media_player.kodi
            state: 'idle'
          - condition: or
            conditions:
              - condition: state
                 entity_id: media_player.tv_ls
                 state: 'idle'
              - condition: state
                 entity_id: media_player.tv_ls
                 state: 'off'
    - service: media_player.turn_off
      data:
        entity_id: media_player.sony_bravia_tv

Indentations are a b$tch.
Still how I have it works fine within automations but apparently not in scripts.

I tried your version but that also fails because the last 2 entity_id and state lines need to be 1 space to the left.

Then it gives a less severe error when loading, however…it still doesn’t work.
This is what I have now:

tvidletimer2:
  alias: "Turn off tv after 20 min"
  sequence:
    - delay:
        minutes: 20
    - condition:
        condition: and
        conditions:
          - condition: state
            entity_id: media_player.kodi
            state: 'idle'
          - condition: or
            conditions:
              - condition: state
                entity_id: media_player.tv_ls
                state: 'idle'
              - condition: state
                entity_id: media_player.tv_ls
                state: 'off'
    - service: media_player.turn_off
      data:
        entity_id:
        - media_player.sony_bravia_tv

Intentation format is also not always consistent it seems because I would expect this condition in an automation would fail because from the second line where it says condition: or, it’s further intended to the right than I usually do. But it works!

  trigger:
    platform: state
    entity_id: sensor.fibaro_system_fgsd002_smoke_sensor_burglar_9_10
  condition:
      condition: or
      conditions:
        - condition: state
          entity_id: sensor.fibaro_system_fgsd002_smoke_sensor_burglar_9_10
          state: '3'
        - condition: state
          entity_id: sensor.fibaro_system_fgsd002_smoke_sensor_burglar_9_10
          state: '8'

So if anyone can help me…