1-Wire interface

1-Wire is a device communications bus system designed by Dallas Semiconductor Corp.

What is a 1-wire bus ?

The most popular use of 1-wire bus is to use the Dallas DS18B20 temperature sensors. The image below illustrates how to wire it on the screw terminals available on the CM3-Home board. It is possible to wire more than one sensor.

The 1-wire data line in CM3-Home is interfaced through a dedicated buffer in order to allow a more robust bus, therefore it doesn’t require a pullup.

The example supplied reads the temperature value returned by the sensor and shows it on the UI .


Classic UI or mobile App

Basic UI

Once defined, the item is part of the OpenHAB environment and can be used as shown in a single panel or integrated in a more complex dashboard that collects the values from other sensors, with different technologies.

OpenHAB and 1-Wire

This article describes how to OpenHAB can read a Dallas DS18B20 temperature sensor directly attached to the dedicated socket of the CM3-Home.

To read the sensor value we are going to use the binding that allows to execute periodically a script.

Install the Exec Binding

Install and configure the sensor, note the ID of your sensor.


Create the file


with the following content:

wert=`cat /sys/bus/w1/devices/$1/w1_slave | tail -n1 | cut -d '=' -f2`
wert2=`echo "scale=3; $wert/1000" | bc`
echo $wert2

give it the execute rights:

sudo chmod +x onewiretemp.sh

test the script executing the command

./onewiretemp.sh sensorID

add things to the Exec binding (Inbox > Exec Binding > Choose Thing > Configure Command) with the command:

/etc/openhab2/scripts/onewiretemp.sh sensorID

get the output thing string (Configuration > Things > Command):


Create the file


add the following line using the thing definition previously got:

String Temp1Wire "Temperature [%s °C]"{channel="exec:command:onewire:output"}

Add the sensor to the sitemaps/cm3home.sitemap to show the value on Basic, Classic and mobile App UI:

Frame label="1-wire"
  Text label="Temperature" icon=temperature
     Text item=Temp1Wire

To use the item value in a widget to show in an habpanel, it needs another step. Because the value read from the sensor is a string, it must be converted to a float value before being used in a knob widget.

Add a number item:


String Temp1Wire "1-Wire Temp [%s °C]"  {channel="exec:command:1wire:output"}
Number Temp1WireValue "1-Wire Temp [%.1f °C]"

and create a rule to convert the string in a float:


rule "StringToInt"
  Item Temp1Wire changed
  var Temp = Temp1Wire.state.toString
  val TempFloat = Float::parseFloat(Temp)

When the string value changes the rule is triggered converting it in the float variable Temp1WireValue, to be used in the widget.