State Change is partly not recognised

After many failures, I have managed to create a switch that allows me to turn my LG WebOS TV on and off.
In addition, I have created an automation that automatically switches on my Sony soundbar when the TV turns on.
I created the automation separately (and did not include it in the switch) because I sometimes switch on the TV with the remote control and then the soundbar should also switch on automatically.
The first time I tested it yesterday, it worked fine. When I switched on the TV, the icon colour changed and the soundbar started.
Since today, however, I have noticed that this is not always the case.
Sometimes it takes up to 30 seconds for HomeAssistant to recognise that the TV has been switched on.
Sometimes it takes even longer.
I would say that in 4 out of 5 cases HA immediately recognises that the TV has been switched on or off.
Why does it take so long in 1 out of 5 cases?

- id: '1649546489619'
  alias: Soundbar_anschalten
  description: ''
  - platform: state
    entity_id: media_player.lg_webos_tv_un74007lb
    from: 'off'
    to: 'on'
  condition: []
  - service: wake_on_lan.send_magic_packet
      mac: 10:4F:A8:AA:AC:72
  - service: media_player.select_source
      source: HDMI1
      device_id: 6feedba24bd837d1f5769c8b8c75cdc6
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
  - service: media_player.select_source
      source: TV
      device_id: 6feedba24bd837d1f5769c8b8c75cdc6
  mode: single

Has anyone a idea ?