Script in automation triggered by a sensor

I created a sensor in my configuration,yaml:

sensor:
   - platform: mqtt
     state_topic: "/MyTopic/Action001"
     name: "My Topic Action 001"
     value_template: "{{ value_json.state }}"

and an automation.yaml:

- id: mqtt-mytopic-action-001
  alias: MQTT My Topic Action 001
      trigger:
      - entity_id: sensor.my_topic_action_001
        platform: state
        to: 'ON'
      action:
      - service: script.runthisscript

and a script.yaml:

runthisscript:
  alias: Run this script
  sequence:
    - service: mqtt.publish
      data:
        payload: '{"state":"ON"}'
        topic: /MyTopic/Action002
        qos: 2
        retain: true
    - service: timer.start
      data:
        entity_id: timer.mytimer
    - service: mqtt.publish
      data:
        payload: '{"state":"BLINK", "delay":300}'
        topic: //MyTopic/Action003
        qos: 2
        retain: true

When I run the script directly from the UI the entire sequence is executed.
When I use the sensor, I can see in the homeassistan.log that the script is executed, but the mqtt messages are not send !?!?

What’s am I doing wrong?

regards, Barry

Try:

- id: mqtt-mytopic-action-001
  alias: MQTT My Topic Action 001
      trigger:
      - entity_id: sensor.my_topic_action_001
        platform: state
        to: 'ON'
      action:
      - service: script.turn_on
        entity_id: script.runthisscript

oriolism, thank you for your response!

I have changed the action as you suggested.
Now when the sensor triggers, I can see in the homeassisant.log that the script is executed:
‘Running script’ - and 4 times ‘Executing step call service’. In one of the steps the mqtt message is send:

[homeassistant.components.mqtt] Transmitting message on /MyTopic/Action002: {“state”:“ON”}

The thing is that the two messages are not received by my iot device and the timer is not started.

Now, when I start the script directly from the UI, All messages are received and I see additional lines in the log:

[homeassistant.components.websocket_api.http.connection.548320384224] Sending {‘id’: 16, ‘type’: ‘result’, ‘success’: True, ‘result’: None}

regards Barry