MQTT publish number

Hi group,

I made a sprinkler controller, it listens to my MQTT Broker and when I publish the json {“fd_target_bar”:3.5} I can make the waterpump to provide 3.5 Bar water pressure.

All working fine, but I can’t figure out how I can arrange in mqtt.yaml

below is working fine, switch the 230V mains to the frequency drive ON and OFF

 - switch
    # switch ON the freq. drive
    - name: "sprinkler_fd_mains"
      command_topic: "sprinkler/sprinkler_command"
      value_template: '{{ value_json.state }}'  
      payload_on: '{"fd_mains":"on"}'
      payload_off: '{"fd_mains":"off"}'
      device_class: switch

For sending the pressure I did try under “numbers”

  - number
  # sprinkler send numbers
     - name: "sprinkler_target_bar"
       command_topic: "sprinkler/sprinkler_command"
       value_template: ?????

But I couldn’t find a method to make it work…

Many thanks for each tip…

turned out using automations did make it more simple

in settings => Devices & Services => Helpers I defined
input_number.sprinkler_bar, from 1.0 to 4.0, step 0.5

in settings => automations & Scenes => Automations I created a new automation
trigger type => state
entity => the above input_number.sprinkler_bar
edit in YAML, the below code.

This was working as expected…

service: mqtt.publish
data:
  topic: sprinkler/sprinkler_command
  qos: "1"
  payload_template: "{\"fd_target_bar\": {{ states('input_number.Sprinkler_Bar') }} }"