Trying to trigger mqtt message with the payload the value of input_number

I try to send an mqtt message with as payload the value of an input_number.
Tried a lot but nothing works.

  • alias: trigger_mqtt_t1
    initial_state: 'on'    
    trigger:
      platform: state
      entity_id: input_number.hc1_low   
    action:
      service: mqtt.publish
      data:
          topic: "cmnd/switch/hc1/t1"
          payload_template: {{states.input_number.hc1_low.state}}

To get the code formatted correctly for the forum paste the code in
the edit box, leaving a blank line at the start and end, then select
the code and click the </> button in the small menu bar at the top of
the edit box.

Try data_template: as opposed to data: and try adding single quotes round the template :slight_smile:

thanks learned finally how to format ;-). The data_template looks even more complex for me because then I need to format the topic and the payload and I don’t even manage it to just the payload.
I don’t have experience with the template syntax and couldn’t find good examples.
It looks like the topic works fine but that is just text. The payload should be related to the input_number.
I also don’t get why I can’t just use :

  • payload: states.input_number.hc1_low.state

Add (single) quotes:

      payload_template: '{{states.input_number.hc1_low.state}}'

You don’t need data_template when using payload_template

Thanks, works fine.
Not sure what I did wrong with previous test. Fat fingers or so.
Bedankt BOB van NL :wink:

1 Like

Graag gedaan landgenoot :wink:

Moet je teleurstellen is rnest van BE

Taalgenoot dan :wink: