Connecting CBus to Alexa via openHAB

I’ve had Clipsal CBus in my house for a long time, and after my interest in home automation dwindling some 8 years ago, I’ve had some fresh enthusiasm after upgrading one of my Sonos speakers to a model with Alexa built in, and installing new automation capable blinds.

So I’ve been banging my head against openHAB for most of the day, working my way through the not unexpected outdated forum posts or just plain missing documentation, but finally got through 90% of way.

Hopefully someone out there can help me get the last 10%!

For the benefit of any else following later, I’ll be rather verbose about what I’ve done so far.

Firstly, relevant components of my environment:

  • Linux Debian (x64) headless server. This runs my Plex server, NextCloud, OpenKM, Samba, amongst other services
  • Clipsal CBus lighting, consisting of 44 devices (switches, relays, dimmers, fan control, CNI, PCI, PAC) and 46 lighting groups

Step 1 - Install OpenHAB
Pretty easy, just installed using apt. Change port config due to something else already running on 8080.

Step 2 - Install CGate
It’s been a while since I’ve connected to my CBus network, so first thing was to install C-Gate on my linux box. Downloaded CGate, configured /dev/ttyUSB0 to connect to it.
Next installed CBus Toolkit on my windows box, and connected to the remote CGate. Confirmed all working.

Step 3 - Install C-Bus Binding
In PaperUI, Add-Ons > Bindings > CBus Binding. Installed v2.5.8
After configuring the CGate binding, I tried to manually add the CBus Network binding, but this just didn’t work. The CGate connection seemed to be a bit flaky, dropping in and out. But at some stage through uninstalling/reinstalling/stopping/starting etc it seems to have settled down.

Step 4 - Add some Things and Items
Before getting too carried away, I’ve just added 3 or 4 lights by:
Going to Inbox, and selecting a light to add it as a Thing.
Then select either the Light Channel (relay) or Level Channel (dimmer) to add a new item.
At this stage, going to Control and toggling the light or adjusting the slider turns on/off my lights.

Step 5 - Connect MyOpenHAB
This is where things slowed down A LOT! It would be great if the openHAB Alex skill page had more information or at least pointers as to where to go! Or the myOpenHAB login page.
So I found my uuid (/var/lib/openhab/uuid) and secret (/var/lib/openhab/openhabcloud/secret) and created an account.

Then I ran into what seems the common issue of the wrong version of java. But it wasn’t because I had an old version of java 8 (version 1.8.xxx), it was because I only had java 11 installed (version 11.0.8). Most of openHAB seems to work fine with java11, but not the myopenhab integration.

Now installing a java8 debian package on buster is something I’ve fought with before, and didn’t really want to fight with again. Until my searching found that Amazon now distribute their own version of java8 and java11 (https://aws.amazon.com/corretto/). I downloaded the tarball version of their java8, and unpacked it /usr/local/

Then edited /etc/default/openhab2 to add the following two lines under the JAVA OPTIONS section to force openHAB to use java8
JAVA_HOME=/usr/local/amazon-corretto-8.265.01.1-linux-x64
JAVA=/usr/local/amazon-corretto-8.265.01.1-linux-x64/jre/bin/java
Then restart. At tat point myopenhab finally showed Online

Step 6 - Connect Alexa
Now I could get back to installing the Alexa skill, but searching for devices found nothing. After chasing down a dozen searches, this is what I needed to do:

  1. Install Add-Ons > User Interfaces > REST Documentation
  2. Browse to /doc/index.html
  3. Select PUT /items/{itemname}/tags/{tag}, and input my itemname and a tag of Lighting (Needed to be Capital L)
    Now discovering devices in Alexa found the devices that I had tagged with Lighting!

… but they did not turn on or off :frowning:

Step 7 - Now I’m stuck!
Quick recap.
If I use the Control page of PaperUI via my http://linuxserver:8082/paperui, I can successfully control my lights.
If I adjust the lighting level using the CBus Toolkit or physical light switch, refreshing the PaperUI Control page will show the correct dimmer value.
If I get the status of my items from https://myopenhab.org/rest/items, it accurately reflects the status of all devices, regardless whether they were set using physical switch, CBus Toolkit, or PaperUI Control
The reverse is also true - If I use Control page via myopenhab.org, I can also successfully control my lights, and the local REST API accurately reflects the status.

… BUT … I cannot control the lights through the REST API
ie,
GET /items/lights_study
will retrieve the item details
POST /items/lights_study
will return successfully, but will not adjust the physical lights. A subsequent GET, will show the “state” value as set by the POST command.

I hope I’ve given enough information about where I’m at, for someone to point out the bleeding obvious step that I’ve missed to make it all work!

POST /items/lights_study
will return successfully, but will not adjust the physical lights. A subsequent GET, will show the “state” value as set by the POST command

In the rest api did you put a command in the body of the message like ON

It looks like you are using Paper ui to configure everything like items. If this is try you need to add metadata to your items

In your rest docs add like this

Thanks for your response. I started writing up all the REST calls I was making, and how everything seemed to be working on the surface, but just didn’t actually control the lights, when I added another lighting Thing and corresponding Item, and that one just worked.

Seems that in my previous efforts of adding and removing Things and Item something went awry and the binding got lost. I removed all the previous Things and Items again, and re-added them, and all seems to be working as expected now.

No alexa meta data required.

Yeah eather way will work.

When you move to openhab3 it will be meta tags and lots of work has been done on the UI. The dev team have done a great job.