I have a MQTT topic that returns a JSON:
{
"state": {
"reported": {
"ts": 1759810164000,
"239": 1,
"240": 1,
"80": 5,
"21": 4,
"200": 0,
"69": 1,
"383": 3,
"30": 0,
"31": 0,
"32": 71,
"37": 76,
"50": 101,
"53": 11,
"181": 9,
"182": 6,
"66": 14750,
"24": 75,
"206": 4210,
"67": 3944,
"68": 0,
"17": 2,
"18": -60,
"19": 39,
"15": 1000,
"36": 1462,
"42": 834,
"43": 0,
"49": 53266,
"51": 14640,
"241": 24491,
"199": 9006,
"16": 7859331,
"449": 0,
"636": 36734486,
"389": 352056,
"390": 442,
}
}
}
I can read paramter “390” and get the raw 442 value which is Fuel remaining, but it needs to be divided by 10 to get it into 44.2 liters.
This is the configuration for the capability
"measure_content_volume": {
"capability": "measure_content_volume",
"stateTopic": "car/data",
"setTopic": "",
"valueTemplate": " (value) => { return value.state.reported[\"390\"]/10) }",
"outputTemplate": "",
"displayName": "Fuel remaining"
}
$.state.reported["390"]" returns the raw value fine, but doing MathJS on that directly fails and returns always 0.
Then I tried
(value) => { return (JSON.parse(value).state.reported[\"390\"] / 10 ) }
but that also always returns 0
and now I tried also
(value) => { return value.state.reported[\"390\"]/10) }
and that too returns 0.
What should be the proper way to do the math on the value?