Help please - using variables between webhook, automation and script

Hi,

Hoping someone can assist me with this

What I want to do is after my morning alarm is dismissed, Tasker sends a random YouTube video ID to an automation which then calls a script to play the video on my TV via Kodi.

Thanks to this thread and @Tinkerer, I have a webhook setup for Tasker, and I have a script which plays the YT video. What I am missing, and can’t get to work is the variable for the video ID coming from Tasker and passing that into the script. Here is my code for each component:

scripts.yaml

# Play Workout Video
kodi_start_workout:
  alias: Kodi Start Workout
  sequence:
    - service: shell_command.tv_on
    - service: kodi.call_method
      data:
        entity_id: media_player.kodi
        method: Player.Open
        data_template: >
        item:
          file: "plugin://plugin.video.youtube/?action=play_video&videoid={{videoid}}"

automations.yaml

- initial_state: 'on'
  alias: Initialize Tasker webhook
  trigger:
  - platform: webhook
    webhook_id: thisisatest
  action:
  - event: tasker_webhook
    event_data_template:
      who: "{{ trigger.json.who }}"
      what: "{{ trigger.json.what }}"
 

- initial_state: 'on'
  alias: Send random YouTube video id to Home Assistant from Tasker when alarm dismissed
  trigger:
  - platform: event
    event_type: tasker_webhook
    event_data:
      who: harpdogg
      what: video_id
  action:
    - service: script.kodi_start_workout
      data_template:
        videoid: "{{ trigger.json.what }}"

Thanks for any suggestions.

videoid: "{{ trigger.event.data.what }}"

Thanks @petro, but that doesn’t work.

I figured it out:

Formatting of scripts.yaml was wrong, it should look like:

# Play Workout Video
kodi_start_workout:
  alias: Kodi Start Workout
  sequence:
    - service: shell_command.tv_on
    - service: kodi.call_method
      data_template:
        entity_id: media_player.kodi
        method: Player.Open
        item:
          file: "plugin://plugin.video.youtube/?action=play_video&videoid={{ videoid }}"

I condensed the automations.yaml to be:

- initial_state: 'on'
  alias: Initialize Tasker webhook
  trigger:
  - platform: webhook
    webhook_id: thisisatest
  action:
  - event: tasker_webhook
    event_data_template:
      who: "{{ trigger.json.who }}"
      what: "{{ trigger.json.what }}"
  - service: script.kodi_start_workout
    data_template:
      videoid: >
        {{ trigger.json.what }}

Hope this helps someone else…