Use mqtt_publish to send value of sensor

Hello,
I want to send the value of the sensor by mqtt_publish to my domoticz server. This will very usefull for me.

Now i create a automation with mqtt_publish service and works if I send a number value like this:

payload: '{ "command": "udevice", "idx": 174, "nvalue": 0, "svalue": "59"}'
topic: domoticz/in

If i launch this automation it works great and push the “59” value in my device throught mqtt.

But i want to use the value of a sensor: “sensor.weight”.

How can i do this?? its important respect the quotes or it will not works :frowning:

thanks a lot for the support!

I think you’re looking for the payload_template service data attribute.
Take a look here:

1 Like
payload_template: '{ "command": "udevice", "idx": 174, "nvalue": 0, "svalue": "{{states('sensor.weight')}}"}'
topic: domoticz/in
1 Like

wow, this is my fault!. I use the payload and not the “payload_template”.
thanks a lot for this!!! i will try this night!

the solution you say to me @123 not works but this one yes:

payload_template: '{ "command": "udevice", "idx": 174, "nvalue": 0, "svalue": "{{ states.sensor.weight.state }}"}'

thanks a lot again

What is the error message?

These two are equivalent:

{{ states('sensor.weight') }}
{{ states.sensor.weight.state }}

Here’s an example in the Template Editor. Notice that both forms produce the same result (94).

The primary difference is the first one is a function that will return unknown if the entity does not exist. The second one will produce an error message if the entity doesn’t exist.

1 Like

in the first i think the problem is the ’ character.
than closes the first of the sentence

in the second, not apears this ’ and works fine.

Thanks a lot, its work like a charm and allow to me to integrate the both systems!