Smart Home – openHAB 2 Enigma2 Integration
This post all about the openHAB 2 Enigma2 integration. It explains how to integrate Enigma2 boxes like for example a VU, Octagon, Xtrend or Gigablue in openHAB 2 by using the HTTP Binding and a Regex Transformation. You will receive step by step instructions how to send commands like mute or others to the Enigma box. Furthermore, you will learn how current information is shown, like the current station or program. You will also learn how to send a message to the box to immediately receive important information from your Smart Home as another integration. The only prerequisite for the box is a system operating with openWebIf. I use openATV 6.2 on my box.
Smart Home – openHAB 2 Enigma2 Hardware
As I’ve mentioned already, you can practically control any Enigma 2 box. A little while ago, I searched for a good Enigma 2 box. Please keep in mind to pick the correct receiver like DCB-S2, DVB-C/T2.
There are lot of good ones, but I have gone for the Gigablue HD Quad.
openHAB 2 Enigma2 – Paper UI Binding and Transformation
openHAB 2 Enigma2 Configuration – HTTP Binding
First, you install the HTTP binding through the Paper UI. Call up extensions and bindings.
http://localhost:8080/ui/index.html#/extensions
After that, install the binding with a click to ‘install’ right next to the binding. If everything worked, you will see the following.
openHAB 2 Enigma2 Configuration – RegEx Transformation
Now click on transformations and install the RegEx transformation.
openHAB 2 Enigma2 Configuration – SmartHome Designer
To control everything with openHAB 2 we now need the relevant items, the adaptation of the sitemap and the rules.
openHAB 2 Enigma2 – SmartHome Designer Item
It’s best if you create a group in your items configuration to bundle the functions.
Group Gigablue
Following that, you define the items. The first two items retrieve the information from OpenWebIf via HTTP request and RegEx transformation. There are loads of possibilities to access the information on the Enigma2 box. You will find a useful reference to the web interface with this link. Referenz zum Webinterface. The second item triggers a rule, which will be explained later.
/* Gigablue HD Quad */ String GB_Sendung "Actual Streaming [%s]" <projector_benq> ( Gigablue ) { http="<[http://<ENIGMA_BOX_IP>:<PORT>/web/getcurrent:3000:REGEX(.*?<e2eventname>(.*?)</e2eventname>.*)]" } String GB_Kanal "Channel [%s]" <projector_benq> ( Gigablue ) { http="<[http://<ENIGMA_BOX_IP>:<PORT>/web/getcurrent:3000:REGEX(.*?<e2servicename>(.*?)</e2servicename>.*)]" } Switch GB_sendMute "Mute" <soundvolume_mute> ( Gigablue )
So what is happening with these first two items?
- The first part is the HTTP request via the HTTP binding { http=”<[]” }. It executes the HTTP binding and delivers the value (<) of the URL in the square brackets back to the item.
- http://<ENIGMA_BOX_IP>:<PORT>/web/getcurrent is the original URL, which retrieves a XML formatted text from OpenWebIf.
- The following part “:3000:REGEX(.*?<e2eventname>(.*?)</e2eventname>.*)” is very cryptic at first glance and not self-explanatory. This passage takes care that the relevant content is extracted from the XML via RegEx transformation, passing it on to the item as a value.
<?xml version="1.0" encoding="utf-8"?> <e2volume> <e2result>True</e2result> <e2resulttext>state</e2resulttext> <e2current>5</e2current> <e2ismuted>False</e2ismuted> </e2volume>
You now have the chance to extract the value from this XML structure. For that, the text from the element is read by entering the relevant syntax. For example, if we want the status “mute” to show on openHAB, we would use the following syntax.
<e2ismuted>(.*?)</e2ismuted>
This implies that all the content between <e2ismuted> and </e2ismuted> is being read. The syntax isn’t exactly simple, but it is logical. I can recommend the following aid. If you would like to now about Regex, read this Regex tutorial. The site RegEx 101 contains a very useful tool for testing your queries. There are also examples.
Use the tool as follows.
- On the right choose python under flavor. This will save you the use of the so-called escape characters, which you have to use for the slash in the example above if you don’t change it.
- Enter the RegEx expression, in our case:
<e2ismuted>(.*?)</e2ismuted>
- Enter the RegEx text, from which you want to read.
<?xml version="1.0" encoding="utf-8"?> <e2volume> <e2result>True</e2result> <e2resulttext>state</e2resulttext> <e2current>5</e2current> <e2ismuted>False</e2ismuted> </e2volume><br>
- Check the results. Here you see the result in the brackets as Group 1. In this case, the Engima2 box would not be mute (ismuted = False).
Full match 148-176 `<e2ismuted>False</e2ismuted>` Group 1. 159-164 `False`
openHAB 2 Enigma2 – SmartHome Designer Sitemap
Now integrate the group into a frame on your sitemap.
Group item=Gigablue label="Gigablue" icon="projector_benq"
As soon as you have done this, you will see the items within the group with their relevant values, if your Enigma2 box is switched on.
openHAB 2 Enigma2 – SmartHome Designer Rule
In the next two chapters, we will define a rule for sending a command and for sending a message.
openHAB 2 Enigma2 Rule – Send a Command
Below you see the rule for the third item GB_sendMute. Whenever this item receives a command, the rule will be executed. If the command is ON (case ON 🙂 or OFF (case OFF :), the HTTP request sendHttpGetRequest(“http://192.168.0.219:219/web/vol?set=mute”) is sent. This will take care of muting your Enigma2 box. In both cases it is the same HTTP request. This way it is switched back and forth between mute / not mute as soon as the switch is activated.
rule "GB_Mute" when Item GB_sendMute received command then switch(receivedCommand) { case ON : sendHttpGetRequest("http://192.168.0.219:219/web/vol?set=mute") case OFF : sendHttpGetRequest("http://192.168.0.219:219/web/vol?set=mute") } end
openHAB 2 Enigma2 Rule – Voice Control
Althoughit is in german the following video demonstrates the control of various commands via voice control. How to realize the voice control, you can read in the post KNX Speech Recognition.
To control the Enigma2 box via voice openHAB uses the following item, for example.
Switch gb_erstes "Das Erste" <soundvolume_mute> ( gEGWZ ) [ "Lighting" ]
Now enter the relevant rule.
rule "DasErste" when Item gb_erstes received command then switch(receivedCommand) { case ON : sendHttpGetRequest("http://<IP_ENGIMA_BOX>:<PORT>/web/remotecontrol?command=2") } end
As soon as this item receives a command, the rule will be executed. If the command ON is received, I switch on the box with an HTTP request. That way you can control your box solely by voice.
http://root:passwort@192.168.xxx.xxx:80/…
openHAB 2 Enigma2 Rule – Send a Message
We also use a rule for sending a message. I have thought of the following. If I’m sitting in front of the TV, relaxed and absorbed, I don’t notice if someone comes to visit. Which is why I want to check if the motion sensor in my driveway is detecting motion. If this is the case, I send the relevant message to the box and can see it on my TV. With the aid of my webcam I can then decide whether the visitor is worth getting up for. =)
rule "GB_Nachricht_Besuch_kommt" when Item BWM_Einfahrt received update then sendHttpGetRequest("http://192.168.0.219:219/web/message?text=Es%20kommt%20Besuch!&type=1&timeout=3") end
Whar are your projects and ideas about using the HTTP Binding?
openHAB 2 Enigma 2 – Ressource
I showed only an extract of what is possible. If you would like what is possible please check the resources.