[Fine tuning] TTS speech commands to my mediaplayer with Node-RED/MQTT

Tags: #<Tag:0x00007fc3f0a11e20> #<Tag:0x00007fc3f0a11ce0> #<Tag:0x00007fc3f0a11c18>

I use Node Red to send TTS speech commands to Home Assistant, using MQTT. I managed it get to work, but I need some fine tuning.

What I have so far:
Node Red

Home Assistant:
sensor.yaml

  - platform: mqtt
    state_topic: "/HomeAssistant/Say"
    name: "Spraak"
    icon: mdi:message-alert-outline

automations.yaml

- id: '1547996179779'
  alias: Spraakmelding
  trigger:
  - entity_id: sensor.spraak
    platform: state
  condition: []
  action:
  - entity_id: media_player.squeezebox_radio
    service: media_player.turn_on
  - data_template:
      cache: false
      message: '{{states(''sensor.spraak'')}}'
    entity_id: media_player.squeezebox_radio
    service: tts.google_say

This working beautifully. I can send any text to the MQTT topic and my Logitech Squeeze Radio is pronouncing it.

So far, so good…

I want to automate it something more. I want to have something that when music is played, the speech command is executed, and when done, start the music again when the speech command is finished.

Can anyone help me with that? I’m absolutely no Home Assistant Guru (just starting to explore for 2 months or so).

Thank you in advance!