openHAB 4 on Termux on Android

With openHAB 4 and its support for Java 17 a new hardware platform became available: Android

openHAB 4 server runs on Termux on Android.
(just in case people want to run their home automation on their Android tablet)
Don’t forget the Termux-wake-lock.

Lenovo Tab M10 here.

openhab> shell:info
Karaf
  Karaf version               4.4.3
  Karaf home                  /data/data/com.termux/files/home/openhab-4/runtime
  Karaf base                  /data/data/com.termux/files/home/openhab-4/userdata
  OSGi Framework              org.eclipse.osgi-3.18.0.v20220516-2155

JVM
  Java Virtual Machine        OpenJDK 64-Bit Server VM version 17-internal+0-adhoc..src
  Version                     17-internal
  Vendor                      Oracle Corporation
  Pid                         14430
  Uptime                      7 minutes
  Process CPU time            8 minutes
  Process CPU load            -1.00
  System CPU load             -1.00
  Open file descriptors       185
  Max file descriptors        32,768
  Total compile time          5 minutes
Threads
  Live threads                119
  Daemon threads              50
  Peak                        136
  Total started               766
Memory
  Current heap size           139,942 kbytes
  Maximum heap size           976,896 kbytes
  Committed heap size         267,264 kbytes
  Pending objects             0
  Garbage collector           Name = 'G1 Young Generation', Collections = 64, Time = 2.483 seconds
  Garbage collector           Name = 'G1 Old Generation', Collections = 0, Time = 0.000 seconds
Classes
  Current classes loaded      19,299
  Total classes loaded        19,367
  Total classes unloaded      68
Operating system
  Name                        Linux version 4.9.190+
  Architecture                aarch64
  Processors                  8
  Total physical memory       3,905,968 kbytes
  Free physical memory        669,096 kbytes

2 Likes

Cool. What’s the real-world performance like?

I just played a bit, the browser Gui felt fast as usual, startup feels pi 3.
A current phone should be faster.

The wake lock is crucial, else sockets go down. I tried an MQTT Bridge, without wake lock it went down after a few minutes.

Neither did I try an USB hub, guess a zigbee stick wouldn’t work, only IP based connections.

This is interesting! Could you provide a little more detail on how you installed openHAB? Did you simply add the apt repositories into termux, and then install?

I zip installed as I always do: unzip -d openhab-4 openhab-4.0.0-SNAPSHOT.zip

Java installed with Termux’s packet manager pkg.

Termux has an sshd, set up your keys as in Linux, and you’re good to ssh and scp.

Important: install Termux from F-Droid, not from Playstore.

It would be great if you could provide a brief tutorial. I’ve got an old Galaxy S8 that I could try this out on, but I’ve never used Termux or done a zip install of OH.

This could be a nice way to reuse old Android devices.

The hardest part is to install F-Droid, as it has to be installed via the .apk (Side-loaded)
From the browser on your Android device get the F-Droid.apk from [F-Droid - Free and Open Source Android App Repository] (the blue download button).

google how to side-load for your device.
for my Lenovo it is : find the .apk from Androids File Manager with settings - Memory - Files - Open with Files
You might have to allow install .apks.

See also the The Termux Wiki.

When the F-Droid is running search for Termux and install it. Then run the termux app.

Select AQUIRE WAKELOCK from the Termux notification panel from the top of your screen.

You are in bash now, the rest works as in Linux, but no need for root.

pkg upgrade
pkg install openssh curl unzip openjdk-17

sshd

ifconfig

curl -O https://openhab.jfrog.io/openhab/libs-milestone-local/org/openhab/distro/openhab/4.0.0.M2/openhab-4.0.0.M2.zip

unzip -d openhab-4 openhab-4.0.0.M2.zip

cd openhab-4 && ./start.sh

After the ifconfig you have the IP of your device and you can ssh in from a computer with a keyboard:
ssh -p 8022 IP

you might also install the Termux:API app and get goodies like

termux-tts-speak "hello openHAB"

and this can be ssh’ed from an openHAB rule …
executeCommandLine(“/usr/bin/ssh”, “nexus9”, “termux-tts-speak hello”)

1 Like

Does this mean that this setup wouldn’t survive restarts? If the device restarts, you must start the termux app again, and restart openHAB again?

(Forgive me - I’ve got no experience in this field!)

Termux supports boot time scripts: Termux:Boot which can be used to start the crond, sshd …

There are people who code in Termux:

https://www.youtube.com/results?search_query=code+in+termux

2 Likes

Thanks for the details. I might spin it up on my old S8 and then use the Remote openHAB binding to control my existing server.

Looks like it would be tricky to get a Z-Wave USB controller working, but I suppose that could be offloaded to an RPi3 running openHAB (just for Z-Wave devices) or ZWaveJS.

my problems

ssh login problems
login - connection refused

http://localhost:8080 or 127.0.0.1:8080
ok administration panel

does java -version work and give 17 ?

You should try openhab 4.0.2

for ssh see Remote Access - Termux Wiki
Mind that the ssh port is 8022

Stable version?

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
wget https://github.com/openhab/openhab-distro/releases/download/4.0.3/openhab-4.0.3.zip -not work (permission deined problem)
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Yes install openjdk-17 termux (version 17.0.???)

termux not openjdk 17.0.5 to openhab required

Thank you for sharing your great experience,
so we can install Openhab server and dashboard on the same android device, right?

Yes, it’s possible. I have just done it.

Does homekit add on work with termux , and i am also having problem running mosquitto broker for termux , if anyone can help thanks in advance

And how to find the uuid for openhab cloud
Thanks for any help

On the web there are several tutorials for mosquitto under Termux.

Note that mosquitto by default only listens on localhost.

Remember to set the wake lock else Android will kill a server after some time.

2 Likes

Done the wakelock thing and openhab is working fine . But i want to use openhab cloud and i can’t find the uuid and secret!!

cloud addon is installed?

1 Like

Yes found uuid and secret

For uuid

nano userdata/uuid

For secret

nano userdata/openhabcloud/secret