Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
1-Wire is a device communications bus system designed by Dallas Semiconductor Corp. that provides low-speed data, signaling, and power over a single signal.
This article will explain how to integrate 1-Wire sensors into OpenRemote 2.1 system. You will need following to finish the integration:
- 1-Wire sensors + controller working on your system
- owserver from OWFS project configured to work with your network
- OpenRemote Online Designer account
- Latest OpenRemote controller (currently 2.1-DeveloperSnapshot)
To avoid confusion, whenever OWFS will be typed in all upper case, it refers to OWFS as whole project and suite of programs (such as owfs, owserver, owhttpd). Every time owfs or owserver will be typed in italic, it refers to specific program.
1-wire can be used for identification and authentication, sensing (popular is the 1-wire temperature sensor) and controlling for example lights through relays.
Implementation of 1-Wire support in OpenRemote allows read and write access to 1-Wire network. In general, if you can read value from 1-Wire device via OWFS, you can access this value via sensor in OpenRemote. Write commands are executed via buttons, switches or sliders. This will, for example, allow users to control external system via relays.
The functionalities of the following products are supported by OpenRemote. Certified products are extensively tested in combination with Professional Designer and supported by OpenRemote certified Integrators.
Configuration of System
Because OpenRemote uses owserver to communicate with physical 1-wire devices, we need to have this part configured and working first. You can find both the software and guide how to configure owfs/owserver on the homepage of the OWFS project.
Most typical usage pattern of OWFS is to use it as a filesystem. This is very nice and useful access method to 1-wire that provide easy way to test all the devices. In the examples you can find on the net, you will often see owfs connecting directly to your 1-wire hardware. This is fine for initial tests of 1-wire configuration, but for OpenRemote we have to use owserver as an intermediate layer. This will allow us to "share" 1-wire network access between many different applications (one of them will be our OpenRemote Controller and other still may be owfs or owhttpd). As you will find on OWFS project page, parameters for owfs and owserver are almost the same, so after you find best settings for your 1-wire network with owfs, you can use the same settings with owserver. This tutorial will not go into details about how to install OWFS on your system, but you can find plenty of information on links you can find at the bottom of this tutorial.
Let's assume you successfully installed OWFS and know how to connect to 1-Wire hardware. First, we will start owserver:
/opt/owfs/bin/owserver --device=/dev/ttyUSB0 -p 4304
This will start owserver that will access 1-wire controller on serial port /dev/ttyUSB0 and owserver will listen on port 4304 (this is default port, you can change it to whatever you need).
If your 1-wire network contains more sensors, it may be convenient to assign aliases to your devices. To do this, create new file that will contain mapping between device address and alias, for example:
28.25E9E3010000 = OW1_Kitchen 28.B9DFE3010000 = OW1_Attic 26.8A75E7000000 = OW2_Bathroom 26.D076E7000000 = OW2_Exterior 1F.E9E803000000 = Channel1
(Optional) If you want to still have access to 1-Wire via filesystem (owfs), you can start it this way:
/opt/owfs/bin/owfs --allow_other --mountpoint=/var/1-Wire -s localhost:4304
"-s localhost:4304" is important here, since instead of direct access to hardwire, owfs is instructed to access 1-Wire via owserver that we started on port 4304.
(Optional) It may be convinient to start owhttpd that allows you to browse your 1-wire network in web browser:
/opt/owfs/bin/owhttpd -s localhost:4304 -p 18888
In this example, owhttpd will listen on port 18888.
Before you proceed to OpenRemote configuration, check if you can access your 1-wire devices via owfs or owhttpd. This way, you can verify paths to devices and attributes of these devices.
##Importing devices in the Designer - Building Modeler Now, let's create some screen in OpenRemote Designer. Online Designer already supports 1-Wire protocol, so all you need is account to log into it.
Our task will be to access temperature and humidity sensor values as well as creating a switch based on a 1-Wire relay module (e.g. DS2413).
Create new Device
In "Building Modeler", create new device (New>New Device)
Still in "Building Modeler", select device that was created in step 1 and click on New>New Command Specify name and select "1-Wire Protocol" as protocol. The following pictures shows the settings needed for the command which is used for the temperature sensor.
1-Wire specific settings:
- Hostname - ip address or hostname of owserver
- Port - port where owserver is listening
- Device Address - path to target 1-Wire device. For example, if we can access our device via owfs as /var/1-Wire/OW1_Kitchen/ (where owfs mountpoint is set to /var/1-Wire) then path to our device is "/OW1_Kitchen". If you have owhttpd running you can easily use a browser to find the device address.
- Sensor attribute - name of attribute of 1-Wire device that we want to read. For thermometer, value is most usually "temperature", for humidity sensors it is "humidity".
- Temp.scale - For temperature attributes here you can define how owserver should scale the value. See owserver documentation for more.
- Polling interval - to avoid hammering of the 1-Wire network with too many requests, sensors are only updated based on this interval.
- Data to send - This is not used for read commands
_Sensor attribute may point to any filename that you can see in owfs. For example, thermometer DS18B20 has (among others) following files in its directory: "temperature","temperature9","temperature10","temperature11",... you can use any of these as source for your command/sensor. You can find meaning of these files in OWFS documentation for DS18B20. Similarly, you can find there documentation for other device types. _
Since we are going to configure second command that will read humidity, click on "Submit and continue". This will store our current settings, but preserve filled-in values. We can then easily update settings without the need to re-enter all the values again.
In this command, we access device "OW2_Exterior" and it's attribute "humidity". We don't need to specify a temp. scale since that is only needed for temperature attributes.
To control the 1-Wire relay through our switch widget, we need three more commands. One to turn the relay on, one for off and one to read the relay status.
The possibility to send data is only available in the 2.1-DeveloperSnapshot and the entry field in the designer is currently only in the pro designer.
The "Data to send" field is needed to send '1' to the relay board. The "Polling interval" is not used for write commands but it's defined as mandatory in the moment, so just enter something.
Here we send '0' to turn the relay off.
To determine the current relay status we read the same attribute with a polling interval of 1 second.
Since we are not going to add any other command, click on "Submit".
Now we will create sensor, that will use previously created commands to access values of our 1-Wire devices. Click on "New>New Sensor"
We will call our first sensor "KitchenTemperature". Select command "GetKitchenTemperature" and choose Type "custom". The temperature is give as floating point value like "21.34" and we don't have a sensor type for that in the moment. So we have to use a custom sensor which is able to just return the value as string. Therefor we don't need and state items.
Click on "Submit" to save sensor.
Again, click on "New>New Sensor" to create sensor for exterior humidity.
Name of second sensor will be "KitchenTemperature". Command to get value from 1-Wire network is set to be "GetExteriorHumidity". Type of sensor is also custom with no state items. Submit this dialog to save the sensor.
Again, click on "New>New Sensor" to create sensor for the relay.
Since 1-Wire relay modules return the relay state as "0" and "1" we need to map those to "on" and "off". The OpenRemote switch objects can only handle sensor values "on" and "off".
Create the switch object
For the switch to be used on the UI designer we need to create a switch object that users our "on" and "off" commands and also the switch sensor.
Click on "New>New Switch" to create the switch object.
We use the created commands for "on" and "off" and also the switch sensor.
Specific Designer Remarks - UI Designer
Now we have configured everything necessary to use the sensors and the switch in UI Designer. To display sensor value, you can create Label and select sensor "KitchenTemperature" or "ExteriorHumidity". For the switch create a switch and select switch "OW_switch"
(If you have any article that helped YOU to get 1-Wire up and running, please share it with others!)