Wiki source code of openHAB

Version 3.1 by Normann P. Nielsen on 2026/11/15 15:42

Hide last authors
Normann P. Nielsen 1.1 1 {{success}}openHAB is an alternative to [[Home Assistant>>Main.information-technology.home-assistant]], and somewhat easier to configure. Where [[Home Assistant>>Main.information-technology.home-assistant]] is Python/Yaml based, openHAB is Java.
2
3 Both systems has great capabilities, and differs a lot in the approach, I You like UIs for config - this is a little "better" and the UI configuration is nice.
4
5 One of the parameters for choosing, can be the amount or specific support for devices, its seems to me that [[Home Assistant>>Main.information-technology.home-assistant]] has quite a lot more that openHAB, but also that several of them lacks functionality and are difficult to actually configure/use; I never understood the "media_player" stuff in [[Home Assistant>>Main.information-technology.home-assistant]]. Visit the [[Showcase and How-tos>>https://www.openhab.org/about/showcase.html]] site.
6
7 OpenHAB 2 supports the new [[Eclipse SmartHome APIs>>https://www.eclipse.org/smarthome/documentation/development/bindings/how-to.html]] for bindings, and additional bindings can be found at [[GitHub>>https://github.com/search?p=5&q=openhab+binding&type=Repositories]]
8
9 For the HAPanel in OpenHAB, theres a wide varity of widgets
10
11
12
13 I do use [[Home Assistant>>Main.information-technology.home-assistant]] now a days - I has a more rapid release cycle and getting a lot of UI improvements...{{/success}}
14
15
16
17 = Topics =
18
19 {{toc/}}
20
21 = Screenshots =
22
23 {{velocity}}
24 #set ($attachments = $doc.attachmentList)
25 #if ($attachments.size() > 0)
26 {{gallery}}
27 #foreach($attachment in $attachments)
28 #if($attachment.isImage())
29 [[image:$attachment.filename]]
30 #end
31 #end
32 {{/gallery}}
33 #end
34 {{/velocity}}
35
36 = Docker =
37
38 [[https://www.openhab.org/docs/installation/docker.html]]
39
40 Very easy to start and configure.
41
42
43 {{code}}
44 docker run \
45 --name openhab \
46 --net=host \
47 -v /etc/localtime:/etc/localtime:ro \
48 -v /etc/timezone:/etc/timezone:ro \
49 -v /opt/openhab/conf:/openhab/conf \
50 -v /opt/openhab/userdata:/openhab/userdata \
51 -v /opt/openhab/addons:/openhab/addons \
52 -d \
53 -e USER_ID=1003 \
54 -e GROUP_ID=9001 \
55 --restart=always \
56 openhab/openhab
57 {{/code}}
58
59 = Backup =
60
61 The easiest way is the make a cron job for backup, information on backup and restore are at [[https://www.openhab.org/docs/installation/linux.html#backup-and-restore]]
62
63 {{success}}Also, do review the latter [[openHAB Backup>>Main.information-technology.openhab-backup]]{{/success}}
64
65
66 {{code}}
67 sudo apt-get install zip
68 sudo vi /etc/crontab
69
70 0 22 * * * /opt/openhab/bin/backup
71 {{/code}}
72
73 If You run the backup job manually one time, the location of the backup file(s) are shown:
74
75
76 {{code}}
77 root@homeassist:/opt/openhab/bin# ./backup
78
79 #########################################
80 openHAB 2.x.x backup script
81 #########################################
82
83 Using '/etc/openhab2' as conf folder...
84 Using '/var/lib/openhab2' as userdata folder...
85 Using '/usr/share/openhab2/runtime' as runtime folder...
86 Using '/var/lib/openhab2/backups' as backup folder...
87 Writing to '/var/lib/openhab2/backups/openhab2-backup-18_12_22-11_44_32.zip'...
88 Making Temporary Directory if it is not already there
89 Using /tmp/openhab2/backup as TempDir
90 Copying configuration to temporary folder...
91 Removing unnecessary files...
92 Backup Directory is inside userdata, not including in this backup!
93 Zipping folder...
94 Removing temporary files...
95 Success! Backup made in /var/lib/openhab2/backups/openhab2-backup-18_12_22-11_44_32.zip
96
97 root@homeassist:/usr/share/openhab2/runtime/bin#
98 {{/code}}
99
100 {{error}}A test - moving from one server to a new showed me that the backup is not "complete", as 2 things went wrong:
101
102 * The camera binding that I manually added in the "addon" folder was not in the backup
103 * [[Thing>>https://www.openhab.org/docs/configuration/things.html]]s binded to the camera binding was broken (after the jar file was added, bindings were fine again)
104 * A Thing that was disabled was not disabled after the restore (It actually seems that Disabled is "stateless" and does not survive an openHAB Restart){{/error}}
105
106
107
108 = Security =
109
110 Notice that OpenHAB has no security, and You need to install it in front of openHAB. Do read [[Securing Communication and access to openHAB>>https://www.openhab.org/docs/installation/security.html]]
111
112 Link for setting username password: [[Ngix>>https://www.openhab.org/docs/installation/security.html#nginx-auth]] and [[Apache>>https://www.digitalocean.com/community/tutorials/how-to-set-up-password-authentication-with-apache-on-ubuntu-14-04]]
113
114
115
116 = Things on Tabs =
117
118 For each [[Thing>>https://www.openhab.org/docs/configuration/things.html]], there is a Location field, that represents (at least) a Tab in the Paper UI:
119
120 [[image:Screenshot 2018-12-22 at 11.51.49.png||width="562"||height="250"||alt="Screenshot 2018-12-22 at 11.51.49.png"]] . [[image:Screenshot 2018-12-22 at 11.52.03.png||width="349"||height="250"||alt="Screenshot 2018-12-22 at 11.52.03.png"]]
121
122 = Camera Binding =
123
124 I use [[https://github.com/Skinah/IpCamera]] for my HIKVisions, but only with images currently. It works okay.
125
126 [[ipcamera15-12-2018.zip>>attach:ipcamera15-12-2018.zip]]
127
128
129
130 = MQTT Server =
131
132 Install the MQTT Service - this in an Internal MQTT Broker (Server)
133
134 [[image:Screenshot 2019-01-04 at 17.49.10.png||width="300"||alt="Screenshot 2019-01-04 at 17.49.10.png"]]
135
136 Configure the broker.
137
138 = MQTT Bindings and Channels =
139
140 Install the MQTT Binding
141
142 [[image:Screenshot 2019-01-04 at 17.48.47.png||width="300"||alt="Screenshot 2019-01-04 at 17.48.47.png"]]
143
144 Then Create Things and Channels:
145
146 [[image:Screenshot 2019-01-04 at 17.50.40.png||width="504"||height="250"||alt="Screenshot 2019-01-04 at 17.50.40.png"]]
147
148 The [[Thing>>https://www.openhab.org/docs/configuration/things.html]] is the "physical" device, like a light Switch, and the Channel(s) is the properties the Light switch has - now, a switch has only On/Off, but other [[Things>>https://www.openhab.org/docs/configuration/things.html]] may have several properties, an engine can have On/Off, Temperature, Rounds Per Minute etc.
149
150 Pressing "+" for adding a channel gives the options.
151
152 Define the Channel - typically where to send the command, and where to read the state:
153
154 [[image:Screenshot 2019-01-04 at 17.54.16.png||width="600"||alt="Screenshot 2019-01-04 at 17.54.16.png"]]
155
156 {{success}}Notice [[The Homie convention>>https://homieiot.github.io/]], when deciding MQTT Topics{{/success}}
157
158
159
160 For HABPanel, the Channel can be used instantly, for a [[Sitemap>>https://www.openhab.org/docs/configuration/sitemaps.html]] in the Basic UI, You need to link the Channel to an [[Item>>https://www.openhab.org/docs/configuration/items.html]] in an items file (Notice the Channel name from the screenshot above):
161
162
163 {{code language="mqtt.items"}}
164 Switch mqtt_test "Test switch" {channel="mqtt:topic:61a4bec6:mqtt_test"}
165 {{/code}}
166
167 Now we have an item that can be used on a  [[Sitemap>>https://www.openhab.org/docs/configuration/sitemaps.html]]
168
169
170
171 = MQTT Demo Video =
172
173 This shows the above configuration in action - the Basic UI in upper left, the HABPanel in lower left, an external MQTT Client in upper right and the logging in the Event logfile in lower right.
174
175 Notice that the Sitemap does not alway update instantly, no clue why currently.
176
177 {{embed url="http://youtube.com/watch?v=mvOPmIOABkY" /}}
178
179 = Links =
180
181 {{include reference="Main.information-technology.openhab.openhab-links-collection.WebHome"/}}