How to read a number from MQTT-String

I would like to read a part of a string, which I get via MQTT, into a number, which should then be stored in a database. Unfortunately I can’t find anything really suitable.
The string is prepared as follows:

Type string : Temperature "Temperature"      [ stateTopic="tele/sonoff_mini_61/SENSOR", transformationPattern="JSONPATH:$.BMP280.Temperature" ]

I like to get anything like this: “Type number…”

Can someone help me?


Andb this is why I recommend using the UI it REST APai to define Thing. There it is simple and obvious, just select Number for the Channel type… All I can offer is that it’s possible. I couldn’t tell you how.

1 Like

See here it should work

Just do it as you like:

and as Rich said.

I’m using the Thing-Channel in the same way:

Type number : temperature "Temperature"          [ stateTopic="tele/th16_01/SENSOR", transformationPattern="JSONPATH:$.AM2301.Temperature"]

and the corresponding item:

Number    Sonoff_PowerStrip_01_Temp     "Steckdosenleiste 1 Temperatur[%.1f °C]"          <temperature>           (gSonoffs,EG_Kind1,gRtIstI)     { channel="mqtt:topic:hans:TH1601:temperature"}               


as I struggled for hours to find the right expression to compare a number received as MQTT-string-item with another number in a rule, here the final solution:

String FensterkontaktEBatterie  "Batterie"   {channel="mqtt:topic:....
var Warnschwelle = 95
if ( Float::parseFloat(FensterkontaktEBatterie.state.toString) < Warnschwelle )

Hope that saves others some time…