Extract attribute from declared mqtt switch

I’ve a swith declared as mqtt:

switch:
  - platform: mqtt
    name: valve_1_front_garden
    state_topic: "stat/sonoff4chpro_one/POWER1"
    command_topic: "cmnd/sonoff4chpro_one/POWER1"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    retain: false

Now I’ve a script where I need to retrieve the value from state_topic ( in my case example: sonoff4chpro_one ) to create a valid message to publish.
Any idea how to extract this value from my switch? How to get attribute state_topic?

My goal is to have a topic variable: cmnd/sonoff4chpro_one/pulsetime

the value valve_1_front_garden in {% set switch = ‘valve_1_front_garden’ %} is hardcoded only for example purpose. In the real environment is it passed as variable

script:
  my_script_1:
    sequence:
      - service: mqtt.publish
        data_template:
          topic: >
            {% set switch = 'valve_1_front_garden' %}
            # i need here to get value: sonoff4chpro_one and put in variable: device_name
            {% set topic = 'cmnd/[SWITCH_NAME]/pulsetime' %}
            {{ topic | replace('[SWITCH_NAME]', device_name)  }}

          payload: 200