Mathematical operation on a json field

Hello,

I’m sending a notification to my phone from an mqtt message whichi payload is :

{ “id”:“1”,“action”:“open”,“vddaMV”:“3031” }

I can display the vddaMV field with this data:
message: 'Your message goes here {{ trigger.payload_json.vddaMV }}mV'

This is a millivolt value and I want to display a volt value. I tried several things
message: 'Your message goes here {{ trigger.payload_json.vddaMV /1000}}mV'

message: 'Your message goes here {{parseInt(trigger.payload_json.vddaMV)/1000}}V'
message: 'Your message goes here {parseInt({trigger.payload_json.vddaMV})/1000}V'
message: 'Your message goes here {{(parseInt(trigger.payload_json.vddaMV)/1000).toString()}}V'
message: 'Your message goes here {(parseInt({trigger.payload_json.vddaMV})/1000).toString()}V'

but none of them is working. How can I do that?
Thanks

try:

message: 'Your message goes here {{ (trigger.payload_json.vddaMV) | int /1000}}mV'

It works. I would never have found this…
Any documentation link on this syntax?

Thanks
Julien

I don’t know of any right off the top of my head for that specific thing but here are some links to basic info:

https://jinja.palletsprojects.com/en/2.10.x/templates/

the biggest things to remember are that states are always strings and templates always return strings. Even if it doesn’t look like a string (‘1’ =/= 1)

So any operation that you want to perform on a template result that requires anything other than strings you need to convert the data type.

and when in doubt…convert.

1 Like