Obtaining temperature values from a String in Node RED

Tags: #<Tag:0x00007f6177e426d8> #<Tag:0x00007f6177e42610>

Using the current version of OpenHAB (2.5.4) and Node RED, I’m trying to set a rule whereby a device is commanded ON when a temperature drops below a set temperature and is commanded OFF when temperature hits a higher limit, acting as a basic domestic thermostat.
I’m using the DS18B20 Temperature Sensor and onewire binding on a Raspberry Pi 3, using GPIO pin:4.
The Items file looks like:

Number:Temperature Testbench_Temperature_Sensor1 “Temperature (Sensor 1) [%.1f]” { channel=“onewiregpio:sensor:Measured_Temperature_Sensor1:temperature” }

The Thing file looks like:

Thing onewiregpio:sensor:Measured_Temperature_Sensor1 “Testbench Temperature 1” [gpio_bus_file="/sys/bus/w1/devices/28-031760490dff/w1_slave",refresh_time=30,precision=1]

Screen Shot 2020-05-19 at 12.00.14
When using the “openhab in” node, I am unable to extract a value from the generated strings (from either the Top Channel or Bottom Channel), in order execute the if statements required for the thermostatic control.

Example output from Top Channel:

21.8 ?C

Example output from Bottom Channel:

{“topic”:“smarthome/items/Testbench_Temperature_Sensor1/state”,“payload”:{“type”:“Quantity”,“value”:“21.8 °C”},“type”:“ItemStateEvent”}

Please help me find a simple solution to this issue?
I’ve searched online, on lots of forums, for finding a solution, but no where else is data generated when the value is so embedded within a string.

Many Thanks

is node red on the pi that the ds is connected to ?
if so why don’t you use the ds18b20 node to read the temp and then write it from node red to openhab ?

on my setup i run a raspberry pi in the db room where i have a ds18 conected to gpio4 tat i use node red to read the temp and send that via mqtt to my openhab server . but you can also use the node red to write to openhab via a openhab node ?

is node red on the pi that the ds is connected to ?

Yes, it is. I will, in my final set-up, have about 10x OneWire DS18B20 Temperature sensors connected.

if so why don’t you use the ds18b20 node to read the temp and then write it from node red to openhab ?

There’s a DS18B20 node??!?!! Could you assist in helping me to find that?

I wish to do the same as you (but with multiple sensors), in getting the temperature to OpenHAB so I can use the temperature for heating control. However to do the temperature check, I need a value from the generated data. I just cant seem to determine a way of extracting the temperature value from openhab in node.

here is the link for the DS18B20 node :slight_smile:

will export myne then you can have a look.

[{"id":"96de8f79.828f","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"4add4c8e.cd01dc","type":"sensor-ds18b20","z":"96de8f79.828f","name":"OpenHAB-DB/TEMP","topic":"","sensorid":"28-03168a915eff","timer":"10","repeat":true,"x":120,"y":80,"wires":[["5ade8565.2ed0e4","5ebc6662.bd7c18"]]},{"id":"5ade8565.2ed0e4","type":"mqtt out","z":"96de8f79.828f","name":"DB-TEMP","topic":"OpenHAB-DB/TEMP","qos":"2","retain":"false","broker":"d7d44fb3.3406d8","x":515.5,"y":87,"wires":[]},{"id":"5ebc6662.bd7c18","type":"debug","z":"96de8f79.828f","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":148,"y":139,"wires":[]},{"id":"d7d44fb3.3406d8","type":"mqtt-broker","z":"","name":"OpenHAB-MQTT","broker":"","port":"1883","clientid":"OpenHAB-db","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","closeTopic":"","closeQos":"0","closeRetain":"false","closePayload":"","willTopic":"","willQos":"0","willRetain":"false","willPayload":""}]

you just import it in to node red once you have installed the node.


Thank you so much. You have sorted this problem (that took up most of my day, yesterday) in one simple step.
You are a star. :star2:
To be honest with you, I did search for a specific node late last night, but must of misspelt it.

Kind Regards,

it’s a pleasure . glad i could help.
i use my node red mostly for monitoring . i am building DB’s with raspberry pi’s
and this specific one monitors my alarm status and to arm / disarm my alarm. with that it also monitors the temperature in the cubical as i have some equipment in the cubical.
so node red mostly only reads the raspberry pi Gpio and sends statuses to mqtt.
and use mqtt messages to controll the relays connected to the raspberry Gpio.
if you want i can share some info with you on how i did that…

Very similar to me, using node red for setting rules, mqtt for comms and RPi/OpenHAB for I/O control. My project is a complete hoe automation. My temperature sensors are down, under the floor installed when we put in the Underfloor heating pipework. I’m also planning to use the (non-waterproof) DS18B20 sensors for room temperature sensing.
I would be very interested to hear how you log all the data as I would like to, when up and running, compare room temp vs underfloor temp vs boiler temp vs manifold temp, which I will be sensing. Logging all this and studying the effects of different settings/timings is something I’m not sure how I’m going to do yet.

I will be trying to use node red for all my rules, once I’ve created all my ‘Things’. The openhab nodes are very useful in their mqtt friendliness and auto-thing-finding.

Thanks again. Let me know

I will send you a layout of my system . Will pm you

Kind regards / vriendelijke groeten

Africa AVC

For other devices without own nodes you can use a function node to convert the message payload from a string to a number.

   var temp = new Object(msg.payload);
   msg.payload = Number(temp);
1 Like

Welcome to OpenHAB.
yes that is one way. you can also shorten it a bit.

msg.payload = Number(msg.payload);
return msg;

I suppose you could make a more sophisticated version that actually took account of the units that openHAB supplies. Does Node RED support the idea of quantity types? Else you could convert if necessary to some default units, e.g. degrees C to F

you can have node red ad the 'C of 'F with adding it to the string.