Kodi wait for trigger with kodi_call_method_result

I have a remote to control my kodi that can call HA entities.
Now I have a left and right button on this remote. During navigation I like to use the buttons for left and right as normal.
But during video playback I like to use the left and right button to skip back or forward.

So I have a script asking first the GUI.GetProperties of the current kodi instance. If I get a value back of 12005 I know that a video is playing.
The “wait for a trigger” does not fire probably since it is already too late to receive something over kodi_call_method_result?

Here my script for the left button:

alias: Kodi left button
sequence:
  - service: kodi.call_method
    data:
      method: GUI.GetProperties
      properties:
        - currentwindow
    target:
      entity_id: media_player.192_168_1_113
  - wait_for_trigger:
      - platform: event
        event_type: kodi_call_method_result
        event_data:
          result_ok: true
          input:
            method: GUI.GetProperties
    timeout:
      hours: 0
      minutes: 0
      seconds: 2
      milliseconds: 0
    continue_on_timeout: false
    enabled: true
  - if:
      - condition: template
        value_template: "{{ wait.trigger.event.data.result.currentwindow.id == 12005 }}"
    then:
      - service: kodi.call_method
        target:
          entity_id:
            - media_player.192_168_1_113
        data:
          method: Player.Seek
          playerid: 1
          value:
            step: smallbackward
    else:
      - service: kodi.call_method
        target:
          entity_id:
            - media_player.192_168_1_113
        data:
          method: Input.Left
    enabled: true
mode: single

Why not just use?

 - if:
     - condition: state
       entity_id: media_player.libreelec
       state: 'playing'

Also why are you controlling two media players at the same time?

    then:
      - service: kodi.call_method
        target:
          entity_id:
            - media_player.libreelec
            - media_player.192_168_1_113

thx for the input.
however the video is able to play in the background while you might navigate the menu that’s why I’m looking for the currentwindow.id

And sorry about the two media players I fixed this now.

Ah, that makes sense.

I tried calling the service for my kodi box and monitoring the event. Everything you have looks correct.

Does it work if you use just:

  - wait_for_trigger:
      - platform: event
        event_type: kodi_call_method_result
        event_data:
          result_ok: true

hmm I might have found a solution… Since I’m using HA just for 4 days I’m not sure if this is a “good” way to do it…
The problem was that the when I run the whole script in sequence the kodi_call_method_result is to late to capture the info from kodi.

alias: Kodi left button
sequence:
  - parallel:
      - service: kodi.call_method
        data:
          method: GUI.GetProperties
          properties:
            - currentwindow
        target:
          entity_id:
            - media_player.libreelec
        enabled: true
      - sequence:
          - wait_for_trigger:
              - platform: event
                event_type: kodi_call_method_result
                event_data:
                  result_ok: true
                  input:
                    method: GUI.GetProperties
            timeout:
              hours: 0
              minutes: 0
              seconds: 2
              milliseconds: 0
            continue_on_timeout: false
            enabled: true
          - if:
              - condition: template
                value_template: "{{ wait.trigger.event.data.result.currentwindow.id == 12005 }}"
            then:
              - service: kodi.call_method
                target:
                  entity_id:
                    - media_player.libreelec
                data:
                  method: Player.Seek
                  playerid: 1
                  value:
                    step: smallbackward
            else:
              - service: kodi.call_method
                target:
                  entity_id:
                    - media_player.libreelec
                data:
                  method: Input.Left
            enabled: true
mode: single