Influxdb, persist values conversion

openhabian (i.e. RaspberryPi)
openHAB 2.5.0~S1507-1 (Build #1507)

I mqtt.things:

Bridge mqtt:broker:redpi_mqtt_broker [ host="****", secure="AUTO", username="***", password="***" ]
{
    Thing topic thermostat1 "Thermostat 1" {
    Channels:
        Type string : temperature1  "Temperature One"   [ stateTopic="tstat1/temperature"]
        Type string : setpoint  "Set point"   [ commandTopic="tstat1/setpoint"]
        Type string : humidity1  "Humidity One"   [ stateTopic="tstat1/humidity"]
        Type string : request "tstat request"   [ stateTopic="tstat1/request"]
    }

And .items:

String mqtt_tstat1_temp     "[%s]"   {channel="mqtt:topic:redpi_mqtt_broker:thermostat1:temperature1"}
Number:Temperature ms6_temperature "MS6 Temperature [%.1f °F]" {channel="zwave:device:16500637f6a:node17:sensor_temperature"}
Number:Temperature ms6_temp_short  "Stuff1 [%.1f]" (roomtemps)  {channel="zwave:device:16500637f6a:node17:sensor_temperature"}

mqtt_tstat1_temp and ms6_temp_short are presisted in influxdb.

I have not been able to get mqtt_tstat1_temp to show in a Grafana chart.
I’m guessing because it is persisted as a string.

There may be a way to do the conversion in grafana…but, I’m not savy grafana.

I’m thinking the right way is to make an item that is the number represented by the mqtt_tstat1_temp string and persist it instead.

I tried adding another item:

String mqtt_tstat1_temp    "[%s]"   {channel="mqtt:topic:redpi_mqtt_broker:thermostat1:temperature1"}
Number mqtt_tstat1_tempnum "[%.1f]" {channel="mqtt:topic:redpi_mqtt_broker:thermostat1:temperature1"}

But that didn’t seem to populate…

I could do it with a rule and every time mqtt_tstat1_temp changed postUpdate to a simple number item.

But, is that the best way?

Do you get errors in the log when the data arrives?

Also, keep in mind that the type is defined by the Channel. You can’t just link a string Channel to a Number Item. You must create a Number Channel to link to a Number Item.

I’ve been curious about the channel definitions.

Is this, for example, valid:

Thing topic thermostat1 "Thermostat 1" {
    Channels:
        Type string : temperature1  "Temperature One"   [ stateTopic="tstat1/temperature"]
        Type number : temperature1num  "Temperature One"   [ stateTopic="tstat1/temperature"]
    }

Can it do both and is it smart enough to covert the string (for example “62.5” which the mqtt is transmitting as ascii characters) to a number?

I only use PaperUI to create MQTT Things so I can’t really answer.

This I can answer. Yes, as long as the string doesn’t have any stray leading or trailing spaces or extra characters like units, it is smart enough so convert the string “62.5” to the number 62.5. The majority of my MQTT sensor topics work exactly like this.

Ok, I tried the example and it apparently is valid.

It populates both when the mqtt publish is received.