How to create an MQTT slider?

I want to add a slider to the GUI that sends MQTT messages when being dragged. From the docs I added the following code to the configuration file:

input_number:
  myslider:
    name: myslider
    initial: 30
    min: -20
    max: 35
    step: 1
    
automation:
  - alias: "Temp slider moved"
    trigger:
      platform: state
      entity_id: input_number.myslider
    action:
      service: mqtt.publish
      data:
        topic: "setTemperature"
        retain: true
        payload: "{{ states('input_number.target_temp') | int }}"

Now I can add “myslider” to the GUI. But dragging it around triggers no MQTT message at all.
What could be the issue?

Did you solve it?

My guess, there is input_number.target_temp in payload, but the slider is named myslider.

sorry for digging this topic out of the grave, but i tried the same but without succes.

here is my code:

automation:
  - alias: "Temp slider moved"
    trigger:
      platform: state
      entity_id: input_number.myslider
    action:
      service: mqtt.publish
      data:
        topic: "setTemperature"
        retain: true
        payload: "{{ states('input_number.myslider') | int }}"

configuration:

input_number:
  myslider:
    name: myslider
    initial: 30
    min: -20
    max: 35
    step: 1
    

I can move the slider and also see that Homeassistant recognizes some changes. but i dont see any message posted on my MQTT broker.

Any idea whats wrong?
Thanks for helping