I’ve recently received a Sofatbaton X2 and have now managed to get it working well with Openhab. I thought others might find my discoveries useful.
I wanted to trigger a number of power switches which are Tapo (TP-Link) Wifi devices. However, there is no specific integration with Tapo/TP-Link on the Remote. So I have found a way to do this via Openhab.
There’s no specific integration with Openhab, but I’ve used a combination of the Sofabaton X2 integration with Home Assistant and a few rules in Openhab.
The HA integration is simply using MQTT messages. So to get this to work, you first need to make sure you have installed the MQTT broker binding and have an MQTT broker up and running.
Here’ are the steps I took:
1) Setup the link to your MQTT broker in the Sofabaton App
From the Sofabaton App, choose ‘Me’ in the bottom right, then ‘Connect to Home Assistant’
Confirm you’ve installed the MQTT server, just hit next on the confirmation page
Enter the url and port of your MQTT server, username and password
You should get a confirmation screen saying it’s all setup.
2) Setup a device on your Sofabaton remote
Still in the app, go to the devices screen and hit the + sign to add a new device. Choose ‘Wi-Fi’ control method.
Then choose ‘Home Assistant Remote’
3) Add action buttons to your remote
You now need to add action buttons that will appear on your remote.
Note, that you can only modify the command name - ie, the name that appears on the button. Each button will be assigned a unique button number, there’s no way to change this - it’s allocated by the app.
You’ll see a ‘Topic’ and ‘Payload’ displayed under the command name. These are the important codes you need to copy and use in Openhab.
The topic will always be the same for your remote - this is it’s MAC address followed by /up
The payload is a combination of a device_id and key_id
The device is the device number in your list (ie, for me it was device number 8). The key number is the sequential number of the key. ie, the first button you add will be 1, then 2, 3, etc. As i say,there is no way to change this - you just have to remember which button number responds to your command name.
Hit next, you see the button commands you’ve setup. You can add as many as you like.
Once you’ve created you buttons, you’ll be asked to name the device and the app will download the settings to your remote.
You’ll now see a new device. Here, I created one for all my Tapo plugs called ‘Plugs’:
When i click it, I see the command buttons I’ve setup:
These are also displayed on the screen on the Sofabaton X2.
Now over to Openhab setup steps….
4) Create a Generic MQTT Thing to receive your Sofabaton messages
You need to create a Generic MQTT Thing that receives the MQTT message from the Sofabaton remote (I’m assuming here you’ve already setup your MQTT bridge in Openhab - if not, there’s a lot of posts on how to do that).
Create a new Thing by selecting the MQTT binding and then ‘Generic MQTT Thing’ as the Thing type.
Make sure you select your MQTT bridge when setting up your new Thing. Once you do this, your Thing should show online.
5) Create channels to receive data sent from Sofabaton
Create 2 channels: one for the Device_ID, one for the Key_ID. In both of these, add your ‘topic’ from the Sofabaton command into ‘State Topic’. Remember to add the ‘/up’. So your command should be:
[mac-address-of your remote]/up
You don’t need to enter the command topic. As Sofabaton currently only supports sending commands from the remote to Openhab - ie, it’s state read only.
Now here’s the fun part….
We are going to need to handle the format of the JSON payload coming in from the remote.
Click on ‘Show Advanced’ on your Channel. Enter the incoming Value Transformation as:
JSONPATH:$.device_id
or
JSONPATH:$:key_id
Note: you’ll need to make sure you already have the JSONPATH transformation binding for this to work (I assume you probably do if you are already using MQTT). If not, add it from the bindings add-on store).
6) Create an item for each channel
Create new items for the device_id and key_id. Make them both string types. (I tried point and that didn’t seem to work).
7) Test your commands are being received
You should now be able to press the command buttons you created on your remote, and see those device_id and key_id values changing in Openhab. If you do - well done! you are connected
(maybe not the device_id if you’ve only created 1 device!).
8) Create a rule to manage your Sofabaton commands
You’ll need to create a rule (or rules) to handle the receiving commands and perform your desired actions. You could create one rule for each button directly in the rules UI. To do this, make sure you choose the ‘Was Updated’ trigger:
This gets very messy once you have a few buttons. And if you end up with setting up multiple devices, it’ll be unmanageable.
The better way is to set a text file rule using Switch logic
To do this, you need to create a file in your rules folder with a .rules extension. eg, sofabaton.rules
Here’s the code I created to handle 4 command buttons:
rule "Sofabaton Device #7"
when
Item Sofabaton_Device_ID received update "7"
then
var buttonNumber = Sofabaton_Sofabaton_Key.state
logInfo("Sofabaton","Button {}", Sofabaton_Sofabaton_Key.state)
switch(buttonNumber) {
case 1 : {
AVPowerStrip_Outlet1_Switch.sendCommand(if(AVPowerStrip_Outlet1_Switch.state == ON) OFF else ON)
}
case 2 : {
AVPowerStrip_Outlet2_Switch.sendCommand(if(AVPowerStrip_Outlet2_Switch.state == ON) OFF else ON)
}
case 3 : {
CurveLight.sendCommand(if(CurveLight.state == ON) OFF else ON)
}
case 4 : {
CoffeeLight.sendCommand(ON)
}
}
end
The first three are ‘toggle’ buttons. So turn on if off, and off if on
The 4th just turns the light on all the time, you’ll probably need a separate light off command if you want to do this.
Conclusion
It’s a little fiddly, but once you get the first button done, it’s pretty easy to add new ones. The performance is excellent - instant i would say.
I’m not sure I’d use the sofabaton remote for a home control remote, but for those key on/off switches or light scene switching for movie nite it works really well.
Let me know how you get on!












