Wiki source code of openHAB

Last modified by Normann P. Nielsen on 2025/12/12 15:15

Show last authors
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
18 = Topics =
19
20 {{toc/}}
21
22 = Screenshots =
23
24 {{velocity}}
25 #set ($attachments = $doc.attachmentList)
26 #if ($attachments.size() > 0)
27 {{gallery}}
28 #foreach($attachment in $attachments)
29 #if($attachment.isImage())
30 [[image:$attachment.filename]]
31 #end
32 #end
33 {{/gallery}}
34 #end
35 {{/velocity}}
36
37 = Docker =
38
39 [[https://www.openhab.org/docs/installation/docker.html]]
40
41 Very easy to start and configure.
42
43
44 {{code}}
45 docker run \
46 --name openhab \
47 --net=host \
48 -v /etc/localtime:/etc/localtime:ro \
49 -v /etc/timezone:/etc/timezone:ro \
50 -v /opt/openhab/conf:/openhab/conf \
51 -v /opt/openhab/userdata:/openhab/userdata \
52 -v /opt/openhab/addons:/openhab/addons \
53 -d \
54 -e USER_ID=1003 \
55 -e GROUP_ID=9001 \
56 --restart=always \
57 openhab/openhab
58 {{/code}}
59
60 = Backup =
61
62 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]]
63 {{success}}Also, do review the latter [[openHAB Backup>>Main.information-technology.openhab-backup]]{{/success}}
64
65
66
67 {{code}}
68 sudo apt-get install zip
69 sudo vi /etc/crontab
70
71 0 22 * * * /opt/openhab/bin/backup
72 {{/code}}
73
74 If You run the backup job manually one time, the location of the backup file(s) are shown:
75
76
77 {{code}}
78 root@homeassist:/opt/openhab/bin# ./backup
79
80 #########################################
81 openHAB 2.x.x backup script
82 #########################################
83
84 Using '/etc/openhab2' as conf folder...
85 Using '/var/lib/openhab2' as userdata folder...
86 Using '/usr/share/openhab2/runtime' as runtime folder...
87 Using '/var/lib/openhab2/backups' as backup folder...
88 Writing to '/var/lib/openhab2/backups/openhab2-backup-18_12_22-11_44_32.zip'...
89 Making Temporary Directory if it is not already there
90 Using /tmp/openhab2/backup as TempDir
91 Copying configuration to temporary folder...
92 Removing unnecessary files...
93 Backup Directory is inside userdata, not including in this backup!
94 Zipping folder...
95 Removing temporary files...
96 Success! Backup made in /var/lib/openhab2/backups/openhab2-backup-18_12_22-11_44_32.zip
97
98 root@homeassist:/usr/share/openhab2/runtime/bin#
99 {{/code}}
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
109 = Security =
110
111 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]]
112
113 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]]
114
115
116
117 = Things on Tabs =
118
119 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:
120
121 [[image:Screenshot 2018-12-22 at 11.51.49.png||width="562"||height="250"]] . [[image:Screenshot 2018-12-22 at 11.52.03.png||width="349"||height="250"]]
122
123 = Camera Binding =
124
125 I use [[https://github.com/Skinah/IpCamera]] for my HIKVisions, but only with images currently. It works okay.
126
127 [[>>ipcamera15-12-2018.zip]]
128
129
130
131 = MQTT Server =
132
133 Install the MQTT Service - this in an Internal MQTT Broker (Server)
134
135 [[image:Screenshot 2019-01-04 at 17.49.10.png||width="300"]]
136
137 Configure the broker.
138
139 = MQTT Bindings and Channels =
140
141 Install the MQTT Binding
142
143 [[image:Screenshot 2019-01-04 at 17.48.47.png||width="300"]]
144
145 Then Create Things and Channels:
146
147 [[image:Screenshot 2019-01-04 at 17.50.40.png||width="504"||height="250"]]
148
149 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.
150
151 Pressing "+" for adding a channel gives the options.
152
153 Define the Channel - typically where to send the command, and where to read the state:
154
155 [[image:Screenshot 2019-01-04 at 17.54.16.png||width="600"]]
156 {{success}}Notice [[The Homie convention>>https://homieiot.github.io/]], when deciding MQTT Topics{{/success}}
157
158
159
160
161 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):
162
163
164 {{code language="mqtt.items"}}
165 Switch mqtt_test "Test switch" {channel="mqtt:topic:61a4bec6:mqtt_test"}
166 {{/code}}
167
168 Now we have an item that can be used on a  [[Sitemap>>https://www.openhab.org/docs/configuration/sitemaps.html]]
169
170
171
172 = MQTT Demo Video =
173
174 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.
175
176 Notice that the Sitemap does not alway update instantly, no clue why currently.
177
178 {{video url="http://youtube.com/watch?v=mvOPmIOABkY" /}}
179
180 = Links =
181
182 {{include reference="Main.information-technology.openhab.openhab-links-collection.WebHome"/}}