Automation with input to change service call

Hello,

I am trying to make a pretty simple automation change based on a numbered input and I cannot get it to work. Appreciate any help/input, thanks!

I want the automation to call a service, and change one part of the “params” field of the “service data”.

This is the basic automation that works fine:

- alias: Clean Kitchen
  trigger:
  action:
    - service: vacuum.send_command
      data:
        entity_id: vacuum.xiaomi_vacuum_cleaner
        command: app_zoned_clean
        params: [[27500, 28000, 30200, 30000, 1]]

Now I want to change the last number in the params, from 1 to 5 and this is what I have tried to do:

    - alias: Clean Kitchen Times
      trigger:
        platform: state
        entity_id: input_number.clean_times_kitchen
      action:
        - service: vacuum.send_command
          data_template:
            entity_id: vacuum.xiaomi_vacuum_cleaner
            command: app_zoned_clean
            params: "[[27500, 28000, 30200, 30000, {{ trigger.to_state.state | int }}]]"

This is my input_number in the configuration.yaml file:

    input_number:
      clean_times_kitchen:
        name: Clean Kitchen
        initial: 1
        min: 1
        max: 5
        step: 1

The automation does trigger, but the params dont seem to work as they should. (No zone is drawn in the application like it is when the first automation is called)

Thanks!

Try:

            params: [[27500, 28000, 30200, 30000, "{{ trigger.to_state.state | int }}"]]

But even that might not work. I seem to recall trying to help someone else with this some time ago. The problem may be that the xiaomi_vacuum_cleaner code may need a number, and Jinja templates can only result in strings, even if they are string representations of numbers. But give it a try anyway.