MQTT number conversion - MQTT result in Millivolts want to display Volts in sensor!

Working on the Home Assistant to OH conversion. I couldn’t find anything in search…

So my MQTT publishes a state for a Voltage sensor. But its display is given in mV.

IE: 14000

I’d like to add an MQTT thing or equivalent to display the reading conversion of: 14.00v in the GUI display.

Any pointers?


There are lots of ways you can do this but you don’t provide much information like:

  • what version of OH you are running?
  • is it only display that you care about?
  • what have you tried?

Keep in mind you likely will not find a step by step tutorial that shows exactly what you want to do. You will find several small and focused tutorials (e.g. how to set up an MQTT thing, how to transform a state’s representation in it’s label, etc.). There is a whole lot of OH you need to know and understand from receiving a message on MQTT and displaying it on a sitemap. Do you know the basics of it all (Things, Channels, Links, Items, Transformations, Sitemaps)?


one way (not the only) is, you can add another number item holding the calculated value in Volt and update it with a rule. Like this:

Item defintion:

Number:ElectricPotential	BatteryVoltage	"Battery [%.1f V]"

and update it with a rule like:

rule "Sensor Voltage"
    Item Sensor_Voltage changed 
    var Double reading = (Sensor_Voltage.state as DecimalType).doubleValue
    var Double result = reading / 1000
    postUpdate(BatteryVoltage, result)

and then you use this item in your sitemap or HabPanel.

Hope this helps.

1 Like

Will take a look at that, thanks Hortus!
Being originally Home Assistant, I’m getting my head around OpenHab2’s process’.
This does seem like a more configurable system than Home Assistant. I’m really liking it!

(Node-Red screen shot)

For now, seeing as I already use Node-Red for automating a solar power dump and charge process, I’ve simply modified the MQTT reports from the controllers before they hit OpenHab2 (with unit converter and function nodes), then just added the modified topic as a sensor in OH.

[offtopic] (Sorry, couldn’t resist)
without implementing an resistor in the broker it will be hard to calculate from milliamps to volts

1 Like

LMFAO oops yes love it! Typo.
Was gonna use A as an example then got distracted in an edit.

Will edit to save the next cheeky sod pointing it out :laughing:

1 Like

Often it is going to be easiest to “fix” stuff like this at the source. But for sake of completeness, assuming OH 2.5.4 with the 2.5.4 MQTT binding some additional thing you could do:

  • JavaScript transformation on the incoming topic to convert from mV to V
  • the Rule like Roland posted
  • JavaScript transformation on the Item label to convert from mV to V
  • if we were dealing with (supported units)[] (mV is not supported) you could use Units of Measurement with the MQTT Topic (it appears the binding now supports them, woohoo!)

But the best choice depends on lots of details about why you need to convert the value and what/where you want to use the converted value.

Hence my original questions.

1 Like

Volts V is supported, as Number:ElectricPotential type, as per @HortusNanum

It’s an ISO unit, so you do get the factors as well - mV , kV etc.

That wasn’t clear to me. Good to know that you can use m , 'k`, etc with ISO units. Because some of the units seem to have a separate entry with kilo and such in the table I erroneously assumed if it wasn’t in the table with that it wasn’t supported.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.