Logitech Harmony and LG C9 issues

Hi. Ive got two issues which im hoping i might get some help with. One of them is purely Logitech Harmony related and doesnt really have much to do with HA (although im hoping that maybe someone will be able to help with resolving it), while the second issue is with the way i tried to resolve it in HA.

Basically, i have several Harmony activities which use different inputs on the TV. Normally (when the TV is on) the activities work perfectly fine, but when the TV is off and i start an activity it only works when it’s the same activity (input) as it was last used on the TV, but if its a different input, then Harmony fails to change the input on TV start most of the times. Originally i thought its a CEC issue, but completely unplugged all HDMI cables and the behaviour doesnt change. I have also tried adding a delay to activities between switching TV on and changing the input - even as high as 20 seconds and it still doesnt help.

Anyhow, i have made an automation which triggers on the Harmony state change, checks which activity is selected and sends 5 “change input” commands every 2 seconds.

alias: Logitech Harmony ensure that TV has proper input
description: ''
trigger:
  - platform: state
    entity_id: remote.living_room_harmony_hub
condition:
  - condition: not
    conditions:
      - condition: state
        entity_id: remote.living_room_harmony_hub
        state: 'off'
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: remote.living_room_harmony_hub
            state: Watch TV
            attribute: current_activity
        sequence:
          - repeat:
              count: '10'
              sequence:
                - delay:
                    hours: 0
                    minutes: 0
                    seconds: 2
                    milliseconds: 0
                - service: media_player.select_source
                  target:
                    entity_id: remote.living_room_harmony_hub
                  data:
                    source: Live TV
      - conditions:
          - condition: state
            entity_id: remote.living_room_harmony_hub
            attribute: current_activity
            state: Watch PC
        sequence:
          - repeat:
              count: '10'
              sequence:
                - delay:
                    hours: 0
                    minutes: 0
                    seconds: 2
                    milliseconds: 0
                - service: media_player.select_source
                  target:
                    entity_id: remote.living_room_harmony_hub
                  data:
                    source: Denon
      - conditions:
          - condition: state
            entity_id: remote.living_room_harmony_hub
            attribute: current_activity
            state: Play XboxOne
        sequence:
          - repeat:
              count: '10'
              sequence:
                - delay:
                    hours: 0
                    minutes: 0
                    seconds: 2
                    milliseconds: 0
                - service: media_player.select_source
                  target:
                    entity_id: remote.living_room_harmony_hub
                  data:
                    source: Denon
      - conditions:
          - condition: state
            entity_id: remote.living_room_harmony_hub
            attribute: current_activity
            state: Play Nintendo Switch
        sequence:
          - repeat:
              count: '10'
              sequence:
                - delay:
                    hours: 0
                    minutes: 0
                    seconds: 2
                    milliseconds: 0
                - service: media_player.select_source
                  target:
                    entity_id: remote.living_room_harmony_hub
                  data:
                    source: Denon
      - conditions:
          - condition: state
            entity_id: remote.living_room_harmony_hub
            attribute: current_activity
            state: Play PS3
        sequence:
          - repeat:
              count: '10'
              sequence:
                - delay:
                    hours: 0
                    minutes: 0
                    seconds: 2
                    milliseconds: 0
                - service: media_player.select_source
                  target:
                    entity_id: remote.living_room_harmony_hub
                  data:
                    source: Denon
      - conditions:
          - condition: state
            entity_id: remote.living_room_harmony_hub
            attribute: current_activity
            state: Play Wii U
        sequence:
          - repeat:
              count: '10'
              sequence:
                - delay:
                    hours: 0
                    minutes: 0
                    seconds: 2
                    milliseconds: 0
                - service: media_player.select_source
                  target:
                    entity_id: remote.living_room_harmony_hub
                  data:
                    source: Denon
    default: []
mode: restart

and this automation has improved things - it changes the input on power on much more often - but still not fixed it. 20-30% of times, the TV switches on, automation kicks in and… the input still doesnt change. I have thought that maybe 10x2s is still to short for the automation, so i have tried to re-run the automation a couple of times and still it doesnt change the input.
Here is the trace: https://easyupload.io/j4o156
But then i run the change source service manually and it works instantly and i have reproduced same steps multiple times.
So what i cannot wrap my head around is how can TV not react to a command send through Harmony from Home Assistant via a service call from within an automation, but works perfectly fine with the same command send via Dev Tools.

Have you tried adjusting the delay and repeat settings on the harmony for the LG TV?

I would try increasing all of the following:
power on delay, inter-key delay, input delay, inter device delay

If you dont have any luck with that I would revert to the previous settings and try adjusting the repeats up