openHAB co-existing with Asterisk & FreePBX on Raspberry Pi 3B

I have an Intel SSD and bought this case

I used the 2.5A power supply that came in my Pi kit. This would be the one.

1 Like

Well I took Bruce’s advice and bought a Pi 4 but thought in for a penny in for a £, so went for 4GB (extra £10), PSU, USB HD adapter, SHIM Fan, Header boost and another Pi Zero with p&p came to £87 (Pimoroni) - don’t tell my other half :wink:

Then I found the old 2.5" hard disk is IDE :frowning: so bought a new 500GB SATA HD for £15 of the bay but I shall use a 240GB SSD in the Pi and the 500GB in the desktop.

With 4MB and logs in memory and no cache it should limit the read/writes to the SSD.

I’ve now read about Docker (Youtube, Andreas Spiess, the guy with the Swiss accent) so could run openHAB, Asterisk/FreePBX and Mosquitto in separate containers. Seems useful but downside is more initial complexity, muddies resolving of issues and both the pre-built openHAB and Asterisk/FreePBX are not official releases and so reliant on quality of the amateur builds.

Any thoughts on using Docker or should I go for the original plan of Rasbian+openHAB image and then install Asterisk/FreePBx. This will be a challenge for me as well as previously I used a Rasbian+Asterisk/FreePBx image.

Alan

IO know @rlkoshakwould recommend Docker and I think that may be wise on a Pi 4.

openHAB maybe Docker friendly but this post https://community.freepbx.org/t/future-docker-work/52597/9 says it’s near impossible to run Asterisk/FreePBX in a Docker container. I now also recall that installing Asterisk from scratch is for experts only and others are recommended to use the images. So that would mean Rasbian+Asterisk/FreePBX image followed by openHAB install.

The reference above suggests virtualisation using LXC is an alternative and better solution. Each container then gets its own IP address. I’ll look at that next. It LXC seems viable it’s a good job I bought the 4GB PI4 !

Or you could still run OpenHAB in a Docker container to keep it somewhat isolated from the other applications.

Thought I would bring this uptodate with my experience.

I installed the Rasbian+Asterisk/FreePBX image from RasPBX images based on Raspbian 10 Buster and this went well. I started FreePBX OK but have yet to configure it and run it for real.

I then followed this guide Installing Docker and Docker Compose on the Raspberry Pi in 5 Simple Steps changing python and python-pip to version 3 mixing it with this extra steps in this guide Happy Pi Day with Docker and Raspberry Pi. but ignoring the swarm section. All went well.

Next I installed Portainer just the Quick Start section - 2 lines! Portainer is a web based front end to Docker.

Next I tried to install openHAB but ran out of space. I didn’t realise the Raspbian+Asterisk+FreePBX image is 4GB so it only filled 25% of my micro SD card. Anyway I had planned to utilise a 230GB SSD drive so followed this How to Run Raspberry Pi 4 or 3 Off an SSD or Flash Drive splitting the drive into 3 thirds circa 75GB each.

Next I installed openHAB following this guide https://community.openhab.org/t/running-openhab-2-in-docker/14267. It’s a bit dated and I stopped before " Create the openHAB conf, userdata, and addon directories" as I was unsure where to create them.

I found that Portainer had created a folder in var/lib/docker/volumes/ so I created a folder openhab_data as well and modified the docker run command -v lines to read:

        -v /var/lib/docker/volumes/openhab_data/openhab_addons:/openhab/addons \
        -v /var/lib/docker/volumes/openhab_data/openhab_conf:/openhab/conf \
        -v /var/lib/docker/volumes/openhab_data/openhab_userdata:/openhab/userdata \

I ran this command and created a openhab container that was listed in Portainer (after reloading the page).

I then followed OpenHAB Docker Containers from section “Running from compose-file.yml” part 2 “for use with Docker Volumes” and created a compose file “openhab-compose-file.yml” in my openhab_data folder

version: '2.2'

services:
  openhab:
    image: "openhab/openhab:2.4.0"
    restart: always
    network_mode: host
    volumes:
      - "/etc/localtime:/etc/localtime:ro"
      - "/etc/timezone:/etc/timezone:ro"
      - "/var/lib/docker/volumes/openhab_data/openhab_addons:/openhab/addons"
      - "/var/lib/docker/volumes/openhab_data/openhab_conf:/openhab/conf"
      - "/var/lib/docker/volumes/openhab_data/openhab_userdata:/openhab/userdata"
    environment:
      OPENHAB_HTTP_PORT: "8080"
      OPENHAB_HTTPS_PORT: "8443"
      EXTRA_JAVA_OPTS: "-Duser.timezone=Europe/London"

volumes:
  openhab_addons:
    driver: local
  openhab_conf:
    driver: local
  openhab_userdata:
    driver: local

In Portainer I removed the openhab container and then ran this compose script with “docker-compose -f openhab-compose-file.yml up -d”

Only problem is that this creates a container called “openhab_data_openhab_1” which is a bit messy. Still trying to figure out why the run command creates a container named “openhab” but the compose script creates a container named “openhab_data_openhab_1”

Help appreciated.
Alan

Docker is definitely the way to go. Haven’t tried Asterisk in it, but I never did do anything with it since I last tried it (still haven’t gotten voip service).

Openhab definitely has official container builds, for all of the release levels too. Stable, milestone, and snapshot.

You need to set the name in your docker compose file. It may be helpful to read through the compose file documentation.

Docker is definitely the way to go. Haven’t tried Asterisk in it, but I never did do anything with it since I last tried it (still haven’t gotten voip service).

I’ve not got VOIP either. I’m using it to filter PSTN calls (linked to Obi110) and to record voice mail which are then forward to my mobile as email. I hope to announce over a speaker who is calling so my wife can pick up her own calls!

You need to set the name in your docker compose file. It may be helpful to read through the compose file documentation.

Just found how to name it:

    container_name: "openhab"

Though when I reran the compose file the Portainer crashed and I had to rebuild it.

Next step is to install Mosquito in a container

That’s odd that it crashed. Maybe because of a name conflict since you already had one called openhab?
I don’t actually use portainer, but I think I might start.

Mosquitto has a container, I’m using that too. Just on my phone now, but it might be done by the Linux Server group.

Also, how slow is all of that running? I quickly moved openhab off the Pi I started with because it was way too slow even when it was the only thing running.

More progress. Installed Mosquitto. Could not see a compose script at the Mosquitto site so found this posting HoTo mqtt with docker 2nd posting by 123 Taras - Example 4. I then heavily modified it.

Created folder /var/lib/docker/volumes/mosquitto_data and moved to it and within folder created: nano mosquitto-compose-file.yml

version: '2.2'

services:
  mqtt:
    image: "arm32v6/eclipse-mosquitto:1.6"
    container_name: "mosquitto"
    restart: always
    ports:
      - 1883:1883
      - 9001:9001
    volumes:
      - "/etc/localtime:/etc/localtime:ro"
      - "/etc/timezone:/etc/timezone:ro"
      - /var/lib/docker/volumes/mosquitto_data/data:/mosquitto/data
      - /var/lib/docker/volumes/mosquitto_data/config:/mosquitto/config
      - /var/lib/docker/volumes/mosquitto_data/log:/mosquitto/log
    network_mode: "host"
    environment:
      - TZ=Europe/London

This started but was none responsive. A docker ps showed it was continuously restarting. Solution was an empty file mosquitto.conf in the config sub-folder. Now running.

Tested first by running in Putty window: docker exec -it mosquitto mosquitto_sub -d -t exampleTopic

Then opened another Putty windows and ran: docker exec -it mosquitto mosquitto_pub -d -t exampleTopic -m “Hello world!” and the first window shows: “Hello World”. Ctrl-C ends the sessions.

Then installed MQTT.fx client in Windows and connected and tested OK. Always apprehensive about installing s/w but this program is heavily mentioned and the link is to the author’s site. Lots of open issues but it worked for me.

Now to try to configure OpenHAB. I’m hoping (presuming!) I can monitor GPIO pins.

Too early to say but this is a Pi 4 with 4GB and an SSD. Moving all the 4GB files from the SD card to the SSD went I recall in under a minute. Feels as responsive as my 3.4Ghz / 8GB desktop PC.

Ah yes, the Pi 4 was not out when I was starting with openhab, I was running a Pi 3B+ off the SD card.

I’ve seen a lot of people with issues getting the GPIO binding to work, and I don’t know how the docker container will affect that. You might want to try my MQTTany software. You’d have to run it directly on the Pi though, no docker container. It is also able to control GPIOs on remote Pis if you need to (which is why I made it).

Many thanks Michael. It did cross my mind that I might need to have a separate app communicating via mqtt, in the same way as when I used a sonoff esp8266 with tasmota. Or alternatively use NodeRed (I’m sure I’ve seen refs to NodeRed under OpenHAB ) as I know NodeRed can reference GPIO pins via node-red-node-pi-gpio

MQTTany looks very useful. Do you have a link to a page with examples?

No examples, but each module’s page shows the available options. I’ll add some examples soon, as you aren’t the first to ask. Message me on Gitter (link on the github repo page) if you need a hand setting it up.

1 Like

Not so good progress over the last 24 hours. First I decided to install Eclipse as my editor of the configuration files. I think I mistakenly installed the OH developers add-ins. It was 3.4GB of data and took hours! I then found out I should have installed Eclipse Smart Home Designer but while hunting for the download page discovered it was End of Life. So instead installed Visual Studio Code. I try to avoid being tied too much to MS but I must say installing VSC and the openhab extensions was quick and smooth.

Now I have a problem getting Windows access to the config files which of course with containers are in the Volumes directory and no Samba shares are automatically set up. I found this OH installation page and modified the Samba conf file to add/change:

# Changed from workgroup = WORKGROUP to
workgroup = XXXXXX
# Added after workgroup
wins support = yes
# Changed from valid users = %$ to
valid users = pi, openhab
# Added at end
[openHAB2]
  comment=openHAB2
  path=/var/lib/docker/volumes/openhab_data
  browseable=Yes
  writeable=Yes
  only guest=no
  public=no
  create mask=0777
  directory mask=0777

This was followed by

sudo service smbd restart
sudo smbpasswd -a openhab
sudo smbpasswd -a pi
sudo chown -hR openhab:openhab /var/lib/docker/volumes/openhab_data/

When I enter my local IP address for the Rasp Pi into Windows Network I get icons for
- OpenHAB share (cannot access) - this icon comes and goes
- OpenHAB2 share (get Windows you do not have permission to access)
- pi share (can access folder of system files e.g .bash_history)

Before installing openHAB in a container I
sudo useradd -r -s /sbin/nologin openhab
sudo usermod -a -G openhab pi

and the stat command shows openhab user and group does have access to /var/lib/docker/volumes/openhab_data/

the Volumes folder has sub-folders of metadata.db mosquitto_data openhab_data portainer_data

Suggestions welcome please

Ok I don’t have time right now to dig into your config but it seems like you aren’t doing volumes right. I will post my openhab and mqtt docker-compose files below, hopefully you can use them as a starting point as you seem to be understanding all of this as you work through it.

Your adding the openhab user to the pi user’s group is not going to work, and also I recommend against it, it’s a security hole. It won’t work because the user named openhab in raspbian is not going to have the same UID as the user named openhab in the container. You need to tell the container the UID and GID of the host’s user named openhab. Remove openhab from the pi group and only add it to groups it needs access to.

My network setup is almost entirely docker’s internal network and NGINX routes all requests from the outside, even for local traffic on my LAN. Your network setup may not be so in-depth.

So here is my file structure and docker-compose files for openhab and mosquitto containers:

srv
 |- openhab2
 |   |- docker-compose.yml
 |   |- addons/
 |   |- conf/
 |   |- cont-init.d/
 |   |- userdata/
 |
 |- mqtt
     |- docker-compose.yml
     |- config/
     |- data/
     |- log/
version: '3.6'

networks:
  nginx_alfred:
    external: true

services:
  openhab:
#    image: openhab/openhab:latest
#    image: openhab/openhab:milestone
    image: openhab/openhab:snapshot
    container_name: openhab
    restart: always

    networks:
      - nginx_alfred

    ports:
      - 8080:8080
      - 8443:8443
      - 8101:8101
      - 5007:5007

    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /etc/timezone:/etc/timezone:ro
      - /srv/openhab2/cont-init.d:/etc/cont-init.d
      - /srv/openhab2/conf:/openhab/conf
      - /srv/openhab2/userdata:/openhab/userdata
      - /srv/openhab2/addons:/openhab/addons

    environment:
      - USER_ID=xx
      - GROUP_ID=xx
version: '3.6'

networks:
  nginx_alfred:
    external: true

services:
  mqtt:
    image: eclipse-mosquitto:latest
    container_name: mqtt
    restart: always

    networks:
      - nginx_alfred

    ports:
      - '1883:1883'

    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /etc/timezone:/etc/timezone:ro
      - /srv/mqtt/data:/mosquitto/data
      - /srv/mqtt/config:/mosquitto/config
      - /srv/mqtt/log:/mosquitto/log
1 Like

Many thanks Michael. Always good to be able to study a working system. I will certainly take your advice and remove the pi account from the openhab group.

Looking at your reply I think I have mistakenly thought the user/group openhab outside the container and having ownership of the Volumes directories was the same as the user/group openhab inside the container. As Docker creates and synchronises the Volumes directories I presumed it would open those directories up.

I will add the environment: USER_ID & GROUP_ID and hopefully that will solve the issue.

That should work for permissions. I don’t know how docker handles the volumes that you are working with, but I think those are meant to be managed only by docker and not you. Notice how all my volumes are in custom locations and mounted differently than yours.

After many more hours I solved the problem myself. I checked the whole path permissions folder by folder until:

  1. ls -l /var/lib/docker
  2. drwx------ 5 root root 4096 Dec 3 12:42 volumes

According to Linux rules (as I understand them) the whole path needs Execute permissions in order to access a sub-folder, including accessing from a Samba share. So I changed volumes to

  1. cd /var/lib/docker
  2. chmod g=x volumes
  3. chmod o=x volumes
  4. drwx–x--x 5 root root 4096 Dec 3 12:42 volumes

In the process I did alter the Samba file so the changes from stock now reads:

  1. workgroup = —my workgroup—
    wins support = yes
    [openHAB2]
    comment=openHAB2
    path=/var/lib/docker/volumes/openhab_data
    browseable=Yes
    writeable=Yes
    only guest=no
    public=no
    create mask=0777
    directory mask=0777
    force group = openhab
    valid users = pi

My Docker-Compose script says

      - "/var/lib/docker/volumes/openhab_data/openhab_addons:/openhab/addons"
      - "/var/lib/docker/volumes/openhab_data/openhab_conf:/openhab/conf"
      - "/var/lib/docker/volumes/openhab_data/openhab_userdata:/openhab/userdata"

The other folders are OK

cd /var/lib/docker/volumes
ls -l
drwxr-xr-x 5 openhab openhab  4096 Dec  3 23:20 openhab_data
cd openhab_data
ls -l
drwxrwxr-x  2 openhab openhab 4096 Nov 30 21:38 openhab_addons
etc

I also had to add write permissions to the openhab_data folder and sub-folders

  1. chmod g=rwx -R openhab_data

Note that pi was defined as a member of the openhab group (as recommended in the
openHAB 2 inside a Docker Container

I can now access the share from Windows. In fact I have 3 folders in Windows Network:

  1. openHAB Share - cannot access - who knows why this was created!
  2. openHAB2 Share - can access
  3. pi Share - can access - pi’s Home

Onwards and upwards as they say. I shall now take a break and focus on some soldering of the hardware, linking inputs and outputs to my Pi and test with some simple python before incorporating into openHAB.

Hi Michael. As you can see from my other post I solved my access problem :slight_smile:

My understanding is that as openHAB runs in a container, Docker sets up symbolic links to the configuration folders so that the folders are then accessible outside the container.

According to some youtube videos and openHAB Configuring you Smart Home guidelines Paper UI has limitations and therefore some changes need to be done by editing Configuration files. Unfortunately Paper UI definitions are held separately so they recommend using Paper UI OR Configuration files for different aspects. All a bit messy if you ask me. I read it will all change in OpenHAB3 - let’s hope there are migration tools.

My folders are also in a custom locations: /var/lib/docker/volumes/openhab_data whereas the openHAB guide uses opt/openhab/ . I based mine on another user written guide. Putting the openhab_data under /var/lib/docker/volumes/ along with other data folders (e.g. mosquitto_data) seems more logical to me.