NaN problem with displaying voltage from ADC

I’ve had OpenHAB 2 running for months without any problems.
One device is a nodemcu with a DS18B20 reading temperature and a voltage divider on ADC input A0 reading the voltage of a 18650 battery.
A couple of days ago I upgrade the nodemcu firmware to Tasmota 9.3.1.1 and now the voltage shows NaN (Not a Number). I rolled back to my previous version of Tasmota but still get NaN.
My voltage is displayed by the following line in my sitemap.
Text item=nodemcu3Voltage label=“Battery Voltage [JS(mV2V.js):%s]” icon=“battery”
As you can see it is text not a number.
It’s been a long time since I did this and can’t remember who gave me the information for this line.
Can someone suggest where I’m going wrong.
PS. I just checked the item and it is defined as a Number there.

Can you share the ITEM

Its because the incoming data into the item is NaN nothing to do with text on sitemap

As @denominator asks please share your Item definition, and also the:

  • Contents of mV2V.js
  • Definition of any Thing and its Channel related to this Item.
1 Like

hafniumzinc,

mV2V.js was supplied by you back in November '20 when I first set this up.

(function(x) {
    return (parseInt(x)/1000).toFixed(1) + " V";
})(input)

This is my Thing

Thing mqtt:topic:nodemcu3 "nodemcu3" @ "myHome/Spa"

    {

        Channels:

            Type number : temperature "Temperature" [

                stateTopic="tele/nodemcu3/SENSOR",

                transformationPattern="JSONPATH:$.DS18B20.Temperature"

                ]

            Type number : voltage "Voltage" [

                stateTopic="tele/nodemcu3/SENSOR",

                transformationPattern="JSONPATH:$.ANALOG.Range"

                ]

And this is my Item;

Number nodemcu3Voltage "Battery Voltage [JS(mV2V.js):%s]" { channel="mqtt:topic:nodemcu3:range" }

None of this has been changed since it was working.
All I’ve done is upgrade the Tasmota version. I’ve wound Tasmota back to 9.1.0 but I still get NaN.

Your Item is hooked up to a Channel called range, but your Things configuration has a Channel called voltage.

Where is the range Channel? I would change your Item definition so it points to the voltage Channel and see what happens…

This is my tele line from the console on my Tasmitised nodemcu.

tele/nodemcu3/SENSOR = {"Time":"2021-02-27T17:26:23","ANALOG":{"Range":4097},"DS18B20":{"Id":"3C01B5562EE1","Temperature":27.9},"TempUnit":"C"}

There is no reference to voltage only range hence the “range” in the channel.

Right, which is why you have

in your openHAB Channel definition. But your openHAB Channel itself is called voltage

and openHAB Items only interface with other openHAB elements, not directly with external stuff. So you need to change your link in your Item definition to

channel="mqtt:topic:nodemcu3:voltage

Note that if I capitalise Thing, Item, Channel etc I’m taking about the an openHAB Thing, Item or Channel.

Thanks hafniumzinc,

That fixed it but what I don’t understand is why it was working before and all I did was upgraded Tasmota and it turned to NaN.
I’ll try upgrading Tasmota again and see what happens.