Correct template code

Hi All,
I’m trying to get a value from an input slider, to a sensor in an irragation intergration.
I have a button which, when pressed" calls MQTT service to set the “Hose-Orchard_failsafe_duration” value.
It works when use this code extract:

........
    type: button
    tap_action:
      action: call-service
      service: mqtt.publish
      data:
        topic: homeassistant/water_duration
        payload: '{"id":"e9454121004b1200","duration":25}'
      target: {}
.........

But with this code:

.........
    type: button
    tap_action:
      action: call-service
      service: mqtt.publish
      data:
        topic: homeassistant/water_duration
        payload: >-
          {"id":"e9454121004b1200","duration":""{
          states('input_number.hose_orchard_water_duration') | int }}"
      target: {}
.........

I get no success. I have checked the logs and there are no errors.
I have tried many variations on the above template section, but with no results.
The input slider is setting to the correct value - checked in dev tools
If anyone can shed light on the correct code, I would really appreciate it.

thanks in advance!

Most core cards do not support templates.

You will have to use a third party card that does or this:

1 Like

Another way to achieve what you’re trying to do would be to create a script to call the service, this can accept templates. Then call the script with your button.

1 Like

@eggman a script is the current way I have it setup - but @tom_l , I am (was) using a custom card, and saw the option for an “on press” event so thought I would look into making the whole thing more straight forward. Will have a look at theLovelace templates link - looks great, but am trying to walk before I fall over run :slight_smile:
thanks for your answers - very much appreciated!

Ok, some custom cards support templating (mushroom, custom-button etc…) but you posted code for the core button card. This does not support templates.