OpenHAB on an Android TV box running Armbian (Setting it up)

Please see this NEW article for a quicker and better setup! Armbian has been updated hugely and the setup is now much much quicker.


OLD ARTICLE BELOW

Ive recently installed OpenHAB 2.2 on a MeCool M8S Pro W box, with Armbian OS (Ubuntu for ARM processors) and managed to record all my steps so thought Id make it into a Tutorial, from start to finish.

The limitations at this time of running that OS on an MeCool M8S Pro W is that the Sound, Bluetooth and Wireless don’t work. This is because there aren’t driver files currently available for that unit, however, its possible there will be in future (keep an eye on the Armbian forums TV boxes - Armbian Community Forums) or other TV boxes may fully work, so you would need to do your research on that forum (For example, I think the standard M8S Pro does all work with WiFI, Bluetooth etc).

I will be installing an OpenHAB system to control/manage/connect to:

Hardware you will need:

  • MeCool M8S Pro W (or box of your choice…after researching which ones work).
  • A Cat 5 LAN cable to plug it into your Router/Switch/Network port.
  • A micro SD card (16GB or larger recommended. I bought this one SDSQUAR-032G-GN6MA)
  • A way to plug that SD card into your Windows computer to image the Armbian OS onto it.

I chose the MeCool box, because it has an Amlogic ARM processor (which is supported by Armbian). These MeCool boxes WILL boot as standard off a USB memory stick or SD card, without having to change any settings on the box, and it has 4 processor cores and 2GB of RAM, which I figured would be enough grunt for what I wanted to do with OpenHAB (more than a raspberry pi, but about the same cost), but you may want a more powerful box. Mine is using about 6% of processor on average, 5GB of the SD card and about 700MB of the RAM.

In my case I downloaded:

Steps to get Armbian Installed (from a Windows PC):

  1. Download the above files.
  2. Unzip/Extract with Armbain image file (Use WinRAR or 7Zip).
  3. Install Win32DiskImager.
  4. Insert your micro SD card into your PC.
  5. Run Win32DiskImager as an Administrator.
  6. In Win32DiskImager, click the folder Icon and point it at your extracted Image file.
  7. Check the Device field is pointing at your SD card you just inserted and click the Write button.
  8. Wait about 5 minutes while the SD card is imaged.
  9. When the SD card is imaged, close Win32DiskImager and go open the SD card partition called BOOT.
  10. In here you will find a couple of folders, and specifically in the one called dtb, you will find about 20 files. These files are effectively a driver file to load the correct drivers for your TV Box. They are labelled things like gxl_p212_2g.dtb. You need to copy the file that matches your hardware the best to the root of the *BOOT drive on the SD card and rename it to dtb.img. The dtb.img file is the one loaded when booting Armbian to correctly load up the drivers. As my MeCool has 2GB of RAM, I used the 2g file. You may need to try multiple files from the dtb folder to find which works best, or research on the internet or Armbian forums.
  11. When you have setup your dtb.img file as per step 10, put the SD card into your MeCool box’s SD card slot, plug in a monitor, network cable to your switch/router, keyboard and mouse and then the power.
  12. Your Armbian box should now boot and will prompt you at a text command prompt to type in the Username and Password. root and 1234. After this is done, it will ask you once again to type in the root password 1234 and create a new user.
  13. To keep things simple for the OpenHAB setup and to match the standard OpenHAB configuration, create a user called openhab (lower case) with a password of habopen (lowercase). For the “Name” you can call it openhab, ignore the other questions, leaving them blank and when asked if this is correct, say Y and press enter.
  14. The box will now reboot and you will arrive at a grey login screen, asking you for the password of openhab.
  15. Before logging in, at the top right of the screen, you will see a page icon with a spanner on it. Click on that and choose the interface of Mate. (I had options of Kodi and Mate). If you DON’T do this, mine didn’t log in to an interface.
  16. If all has gone correctly, you should now be at a Ubuntu desktop.

From here, I wanted to get my box configured to do a couple of things:

  • Have a text editor.
  • Connect to SMB shares and have a permanat mapping to the share.
  • Install a MQTT broker for OpenHAB.
  • Install OpenHAB.
  • Setup RDP connections from Windows for remote control.
  • Setup other base requirements for OpenHAB to be able to operate on Armbian (it doesn’t install everything a standard Ubuntu seems to)

Here are my steps to get a basic OpenHAB setup working:

  1. At the top the screen click System > Preferences > Hardware > Keyboards > Layout. Now add the correct keyboard layout for your keyboard and remove the English US (if you aren’t in the USA). Close that window.
  2. As the box is using DHCP and you will want it on a fixed IP address, the simplest method for this will be to add a static entry in your router to hand out a fixed IP address, so that your devices on your network that use MQTT are always connecting to the same IP. I would suggest doing this now and rebooting your Armbian box. System > Shutdown > Reboot.
  3. When your system has rebooted, log in again to the desktop.
  4. At the top of the screen click Applications > System Tools > Mate Terminal which will open a terminal window. In here you can literally copy/paste out the commands on this guide into the Mate Terminal. Some of the commands will need Y pressing to approve the command running (an on screen prompt will appear). Also, the first time you run a sudo command in THIS window, you will be asked for the password of openhab, which, as we set earlier was habopen.
  5. All the following commands will happen in the Mate Terminal unless specified. Copy/Paste from this guide.

Update the repositories

sudo apt-get update

Install SMB client and Samba for connecting to network shares:

sudo apt-get install smbclient
sudo apt-get install samba samba-common-bin
sudo apt-get install cifs-utils

(OPTIONAL) Remove VNC or any existing setup

sudo apt-get remove xrdp vnc4server tightvncserver

A bit more setting up repositories

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 0x219BD9C9
sudo apt-add-repository 'deb http://repos.azulsystems.com/ubuntu stable main'
wget -qO - 'https://bintray.com/user/downloadSubjectPublicKey?username=openhab' | sudo apt-key add –
sudo apt-get install apt-transport-https
echo 'deb https://dl.bintray.com/openhab/apt-repo2 stable main' | sudo tee /etc/apt/sources.list.d/openhab2.list
sudo apt-get update

Install Java

sudo apt-get install zulu-embedded-8

(OPTIONAL) Install XRDP and TighVNC for RDP access

sudo apt-get install tightvncserver xrdp

Install Zip capability

sudo apt-get install zip

Install Genie text file editor and also Gedit (for simple text editing)

sudo apt-get install geany
sudo apt install gedit

Check the OpenHAB account has certain permissions (it should already have them)

sudo adduser openhab dialout
sudo adduser openhab tty
sudo adduser openhab audio

Install XFCE Terminal (required for the Armbian config utility)

sudo apt-get install xfce4-terminal

Install mosquito MQTT Broker

sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa
sudo apt-get update
sudo apt-get mosquitto

Install OpenHAB and confirm its set to auto start

sudo apt-get install openhab2 
sudo apt-get install openhab2-addons
sudo systemctl start openhab2.service
sudo systemctl status openhab2.service
sudo systemctl daemon-reload
sudo systemctl enable openhab2.service

Ensure that the openhab account is used for accessing network shares and that account has permission to access the network shares we will create on the OpenHAB server for accessing your configuration files.

sudo smbpasswd -a openhab
sudo chown -hR openhab:openhab /etc/openhab2 /var/lib/openhab2
sudo systemctl restart smbd
  1. At this point we will need to text edit some files. The files will need root (administrator) permission to edit them, so you will need to **sudo geany ** so that it has permission to save the files. You need to close geany after editing the files, to be able to use your Mate terminal window again.
sudo geany
  1. In Geany File > Open > Select “File System” > /etc/samba/smb.conf. At the bottom of the file you want need to add the following to create network share on your OpenHAB server that you can access across the network:
[openHAB2-userdata]
comment=openHAB2 userdata
path=/var/lib/openhab2
browseable=Yes
writeable=Yes
only guest=no
public=no
create mask=0777
directory mask=0777

[openHAB2-conf]
comment=openHAB2 site configuration
path=/etc/openhab2
browseable=Yes
writeable=Yes
only guest=no
public=no
create mask=0777
directory mask=0777

Save your file.

  1. Some SMB Windows shares need to use a different format to send logon permissions, such as my network share. To do this in Geany File > Open > Select “File System” > /etc/samba/smb.conf. Add the following JUST BELOW [global] and save the file.
client use spnego = no
  1. (OPTIONAL) I wanted to map a permanent link to my NAS network share, so that I could easily perform backups to it. On my OpenHAB Server, my NAS network share mount point (or mapped drive letter if youre a windows user) will be in /media folder and called openhabbackup.
sudo mkdir /media/openhabbackup
gedit ~/.smbcredentials

In Gedit, Enter your NAS network share username and password to access the share in the file, save it and close Gedit:

username=openhab
password=habopen
  1. (OPTIONAL) Now we will set the permissions on that file to keep your login details secure:
chmod 600 ~/.smbcredentials
  1. (OPTIONAL) And we need to setup the mapping. My NAS SMB share is on a device called dsl-ac68u-4700 and the share on that device is called openhabbackup. So to do this we need to edit a file called fstab with root permissions.
sudo gedit

File > Open > /etc/fstab and add the following line, then save the file and close Gedit.

//dsl-ac68u-4700/openhabbackup /media/openhabbackup cifs credentials=/home/openhab/.smbcredentials,iocharset=utf8,sec=ntlm 0 0
  1. We also need to add a few permissions for the openhab account to be able to sudo commands from within the OpenHAB services (in my case anyway, as I wanted to create an manual backup button in my sitemap within OpenHAB). To do this, type the following:
sudo visudo -f /etc/sudoers.d/010_pi-nopasswd

and then we want to add the following to the file:

openhab ALL=(ALL) NOPASSWD: /usr/share/openhab2/runtime/bin/backup

Then save the file (Ctrl+O) and remove the *.tmp off the end of the filename, Y to overwrite and Ctrl+X to exit.

  1. (OPTIONAL) You can now backup your OpenHAB configuration manually with a command like:
sudo -u openhab sudo /usr/share/openhab2/runtime/bin/backup /media/openhabbackup/mybackup.zip

and if you want to actually create a manual backup button in the sitemap, you do need to have manually run the above command once.

  1. Finally, we need UDEV to work correctly:
sudo mkdir /lib/linux-arm
sudo apt-get install libudev1:armhf
sudo ln -s /lib/arm-linux-gnueabihf/ /lib/linux-arm
sudo ln -s /lib/linux-arm/libudev.so.1 /lib/linux-arm/libudev.so

And we need to edit the Openahb2 configuration file, so that JAVA is fully working:
(ADDING THIS DOESNT APPEAR TO BE NEEDED NOW AND CRASHES MY BOOT… SO YOU MAY WISH TO CHECK JAVA WORKS WITHOUT THIS CHANGE… JUMP TO STEP 15)

sudo  gedit

File > Open > /etc/default/openhab2

Replace EXTRA_JAVA_OPTS=“”

With EXTRA_JAVA_OPTS=“-Djna.library.path=/lib/arm-linux-gnueabihf/”

Save the file and exit Gedit.

  1. I wanted to rename my boxes network name to OpenHAB. To do this, on the Ubuntu desktop click System > Preferences > Hardware > Armbian Config which will ask you for your password habopenopen a blue screen interface. In here BE CAREFUL*, but select Personal > Hostname and change the hostname to your liking. Click Ok and exit back out of this app press the escape button. You will need to restart the system for the name to take effect.

  2. (OPTIONAL) Finally, for me, I wanted to install PS4-Waker for later use.

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo apt install npm
sudo npm i ps4-waker –g

setup instructions from there can be found on the PS4-Waker github site, but you must perform initial setup as the openhab account.

You should now have a working OpenHAB2 Server on an Android TV box, with a blank config, ready for you to create your rules/sitemap/items etc.

You should be able to connect to it on http://ipaddress:8080 or http://name:8080 in my case, as I renamed my server to openhab http://openhab:8080

From there, you can go to PaperUI and start adding bindings/devices/items etc and follow the main tutorials on this site. https://docs.openhab.org/configuration/index.html

Obviously you may wish to further configure security on things such as mosquitto etc, but this guide will have you at a base working condition.

P.S. If you RDP to the box, on the 1st attempt it may say error connecting. This is a issue with XRDP needing a delay setting in its config file, but I cannot remember the setting atm. As such, if you re-type in your password, it will log in the 2nd time.

I hope someone finds this helpful (and that Ive not made any spelling mistakes) :slight_smile:

Thanks

4 Likes

Great tutorial. I can only add that if one wanted to avoid a lot of the manual installation and configuration steps one could follow the Manual Installation for openHABian. I’ve successfully done so on a Banana Pi M2 Zero running Armbian.

Thanks!

Im not overly Linux or Android TV box savvy, but thought it would be nice to have an all in one step-by-step guide for those like me who are starting out and want something different (or more grunt) than a Pi, but dont want to splash out on a NUC or similar (and I couldnt find anyone really talking about doing it this way).

Orange Pis, Pine 64s and Banana Pis are used by a lot of users on this forum, all of which hit this in between spot. And while I was not successful running OH on the BPi M2 Zero because of overheating, it probably would work with a good heat sink and would definitely run well on their bigger SBCs. Though by the time you pay shipping and for a case I’m not sure they end being any cheaper than the MeCool box you got…

Yeah, the model of Android TV Box I bought is heat-sinked and I guess most of them would be, as they are designed to transcode/output 4k video. The other nice possibility is that for another $10 to $15 on top of what I paid, you can get and 8 Core CPU model, with 4GB (I think 8GB was also an option)… and Im not sure if there are Pi’s currently available on 8 core or with that much RAM? :thinking: but again could be a nice jump up in cpu/ram if needed.

As you say though, its that in-between spot between something cheap, vs jumping up to a NUC or similar.

Not RPis but I do think Orange Pi and Banana Pi offer models with similar specs. The Banana Pi M2 Zero they sent me has four cores. It doesn’t have enough RAM IMHO and it needs a heat sink but otherwise, it is a very impressive amount of power in something the same size and shape as a RPi Zero.

for anyone whom is curious… I did end up trying to rebuild my android box one day with openHABian. I tried multiple times, though something within the install caused my box to stop working each time I tried it.

The base install without selecting every add-on seemed ok, but when adding in various other options during the install, it caused issues with the box booting (I believe it may be down to 3rd party packages that are installed and not directly openHABian).

Because its a drawn out process to wipe/reinstall the OS each time this occurred… I wasnt able to spend time diagnosing exactly what caused the issue… and it may be that whatever 3rd party app that caused it had a bug that is now resolved… Im just not sure.

I can say that I ended up going back to my initial method at the top of this post and that got me back to a working place.