Pass a variable (wildcard) from a sentence to an automation

Hello, I am new on this forum, could someone support me in solving my problem? :slight_smile:

For last two weeks I’m trying to create automation with wildcard from sentence as input for field in automation passed to a script - unfortunately, there is something wrong with my code. I would like to say to Assist “increase the amplifier’s volume 3 times” (in Polish “wzmacniacz głośniej 3 razy”) and the number 3 as wildcard
in sentence trigger should be put into field of automation. That value should then be passed to called script as number of repeat action. As result in the script, the called service “volume up for amp” should be repeated X times.
I searched guidelines on the HA website, on internet forums, but till now my automation is not working correctly.

My present result:

  1. Reading a wildcard from a sentence - I think is correct
  2. Passing a value from wildcard to field in an automation - it is not working for me
  3. Passing that variable (as additional field) from an automation to called script - it is working (when that field is filled with some number).

My current code:

Automation:

alias: wzmacniacz głośniej automatyzacja razy
description: ""
triggers:
  - trigger: conversation
    command:
      - wzmacniacz głośniej {razy1} razy
conditions: []
actions:
  - action: script.wzmacniacz_glosniej_x_razy
    metadata: {}
    data:
      razy: 3 # it is working correctly, when field "razy" is filled with a number
#      razy: "{{  razy1  }}" # I need to set field "razy" to value of wildcard "razy1" - what is the proper form of writing? 
#      razy: "{{  razy1|int  }}" # another try, but also not working
mode: single

And script (called by above action with additional field) - this script is working ok (when field “razy” is a number in above automation):

alias: wzmacniacz głośniej skrypt razy
sequence:
  - repeat:
      count: "{{ razy }}"
      sequence:
        - action: denonavr.get_command
          metadata: {}
          data:
            command: /goform/formiPhoneAppDirect.xml?MVUP
          target:
            entity_id: media_player.denon_x3800h
mode: single
icon: mdi:volume-plus
description: ""
fields:
  razy:
    selector:
      number:
        min: 1
        max: 10
        step: 1
    name: razy
    default: 1
    required: true

Could someone help mi in finding proper form of setting the field “razy” with the value of wildcard “razy1”? There is something wrong with:

razy: "{{  razy1  }}"

The general method would be:

alias: wzmacniacz głośniej automatyzacja razy
description: ""
triggers:
  - trigger: conversation
    command:
      - wzmacniacz głośniej {razy1} razy
conditions: []
actions:
  - action: script.wzmacniacz_glosniej_x_razy
    metadata: {}
    data:
      razy: "{{ trigger.slots.razy1 }}"
mode: single

But you may need to figure out a way to translate the value from a number string to a numeral if it’s not being returned as a numeral already. I made a macro to handle this in English that you may be able to use as a guide to build one for yourself.

1 Like

Perfect! It works! Many many thanks :slight_smile: