Fully local Sofabaton X1S Integration

That doesn’t sound good at all! Are you able to:

  • open an issue on this integration’s issue tracker?
  • retrieve the logfile from Home Assistant?

Ideally you open an issue and then upload (relevant parts of) your log to the issue. It’s easier for me to support you there.
Tell me if you need help getting the logfile. If you can’t go on Github let me know as well and we’ll do it here.

btw my initial hunch is that you installed manually, not via HACS.
If that is the case, check the directory name, it’s likely incorrect. The integration code must be in config/custom_components/sofabaton_x1s

As layers of hangover are starting to subside, I have now taken delivery of, and have mostly configured my own X2. Yes baby.

So let’s try to make a thing where if we press the pause button for my Fire TV stick, we turn on the lights in my office.

Please note that this is for the X2 remote, and NOT the X1 or X1S.
Identical functionality can be achieved on all of these remotes, but the methods are going to be different. If you would like to achieve the same but for an X1 or X1S, let me know.

Let’s look at this conceptually first.
If we want to implement this, it means that pressing the pause button now does 2 things, not just one:

  • It actually pauses the content on my FireTV
  • It instructs Home Assistant to turn on the light in my office

Also we must be aware of the fact that the Sofabaton hub is not actually maintaining state on that pause/play state. It does not know you’re playing content, it’s just broadcasting commands. And unless we have some other way of establishing in Home Assistant the actual play-state of the device that is playing our content, we cannot know with certainty what the play/pause state is. We can only ever see the button presses.

From that follows that it’s not impossible for the state of my office light and the play/pause state of the device to go out of sync. If ever my media playback device missed the pause command, but Home Assistant didn’t (or vice/versa), our setup is now out of sync.

So the correct implementation here includes a backup for this scenario; an easy way to get us back in sync.

So here we go:

  • In the Sofabaton app: Add device → Wi-Fi → Home Assistant remote
  • Enter Command Name: Lights On
  • Click the copy buttons next to Topic and Payload and save those somewhere. We will need them later.
  • Click Confirm. Click Next. Give the Home Assistant device a name: Home Assistant. Click Complete.

You’re now back in the list of devices, the new Home Assistant device is last in the list.

  • Click the Edit button, edit the Home Assistant device.
  • Click on Power On/Off Setup. Set it to “No, disable automatic power control”. Click Confirm.
  • Click on Manage Input Sources, select “No need to switch input”. Click OK.
  • Click Edit HA commands list. Click Add a new command.
  • Command Name: Lights Toggle
  • You will note that the Topic here is the same as with the first command, but the Payload is different. Save the payload as you did with the Lights On one. We will need it later. Click Confirm.
  • Click Back. The Home Assistant device is now ready for further use.

Next step, we’re going to make the pause button fire 2 commands. I’m going to assume here that you already have Activities set up.

  • In the Sofabaton app: click Activities, click the Edit button. Click on the Edit button for the Activity where you want the pause button to turn on the light.
  • In the top of the screen here, click on the name of your Activity. Click on Contains. Check the box for our Home Assistant device, so that it’s now included in this Activity. Click Confirm, ignore the warnings, we dealt with this already in previous steps. Click Next, Confirm.
  • Click Macro & Favorite Keys.
  • Click Add Macro.
  • Macro button name: Pause Light On
  • Click Add step
  • Select device: your media playback device, the one that needs to pause playback when we press the button
  • Select command: the pause command from the list of commands. Click Confirm.
  • Click Add step. Device: Home Assistant. Command: Lights On. Click Confirm.
  • Click Save.

We now have a Macro that first pauses playback and then immediately triggers a thing in Home Assistant. Now we want to map this macro to our physical pause button on the remote.

  • In your Activities settings, where you made the macro, click Customize Remote Buttons.
  • Find the Pause button, click it.
  • Click Short press → Macro keys → Pause Light On → Complete the setup
  • Click Long press → Normal keys → Device: Home Assistant → Command: Lights Toggle. Click Confirm and Submit.

Now, when in this Activity, whenever we press the pause button, playback will pause AND Home Assistant is triggered. When we hold the pause button down for longer, a different trigger is sent to Home Assistant but playback is not paused. This is going to be our backup in case we’re ever out of sync.

So now let’s do the Home Assistant part.

  • in Home Assistant, go to Settings → Automations & Scenes
  • Click Create automation → Create new automation
  • Add trigger → MQTT → MQTT message received
  • In the panel on the right, check the Payload checkbox.
  • In the input field for Payload, paste the Payload that we saved for the Lights On command. So you paste in something that looks like this: {"device_id":5,"key_id":1}.
  • In the input field for topic, paste the Topic that we saved earlier. It’s going to look something like this: FC012C39D732/up
  • Click Add action → Light → Turn on
  • In the panel on the right, click Add target → light.office
  • Click Save, Give the automation a name: X2 - Lights On When Pause

Ok, so now when we press the pause button on the physical remote, content is paused and the lights in my office go on.

Now to hook up our backup, the long press on the pause button.

  • in Home Assistant, go to Settings → Automations & Scenes
  • Click Create automation → Create new automation
  • Add trigger → MQTT → MQTT message received
  • In the panel on the right, check the Payload checkbox.
  • In the input field for Payload, paste the Payload that we saved for the Lights Toggle command. So you paste in something that looks like this: {"device_id":5,"key_id":2}. The key_id will be different here.
  • In the input field for topic, paste the Topic that we saved earlier. It’s going to look something like this: FC012C39D732/up, the same one as before.
  • Click Add action → Light → Toggle
  • In the panel on the right, click Add target → light.office
  • Click Save, Give the automation a name: X2 - Lights Toggle When Pause Longpress

That’s it. Now when you press pause, lights go on and content is paused. Whenever things are out of sync, long-press the pause button to toggle the lights.

As i can’t edit the original post anymore, I’ll just leave this here:

This integration now fully supports the X1 and X2 hubs as well. Essentially; this integration supports all hub based Sofabaton remotes.

1 Like

Fantastic and thank you for the amazing work done …esp for x2 support!!

1 Like

Hex @m3tac0de,
i use the Sofabaton X1 (bought via Kickstarter back in the days). until a couple of days ago, it went fine using it via emulated Roku, but for some unknown reason, X1 Hub just can not find the “roku” device anymore. So i found your integration.
The configuration seems to work, but i dont get any events in HA from the Hub.
it says it is offline, not-connected and no keypress recorded…

is there anything i have to do, to connect them?

hello @mkossinna, thankyou for trying the integration!

If the “hub_connected” sensor indicates “not connected”, this means that either:

  • Home Assistant is not able to reach your hub (the integration sends a UDP packet to port 8102 of your hub)
  • Your hub is not able reach your Home Assistant (the hub establishes a TCP connection to the integration, usually on port 8200)

I’ll take a bet and say that whatever is blocking communication between HA and hub is also what is causing your Roku to not work.
Probably if you solve one, you solve both.
Perhaps if you can give some more details about your setup, we can help you get it working again.

@m3tac0de
i found the reason for the connection of the Hub and HA. i did not get it, that i have to activly disconnect my app (not just shutting it down) on my phone. now i have a connection. just have to figure out how to see, which buttons and makros i pressed on my remote to control stuff in HA (like power button of the subwoofer, ambient light, changing app on Smart TV and so on)

:frowning: I was really hoping that the problem was a bit more complicated than that, because unfortunately, on the X1, the Emulated Roku device is the only way to send commands from the X1 hub to Home Assistant.

The integration that is now working for you can only do the other way around, from Home Assistant into the X1 hub. Sorry.

Let’s focus on getting Emulated Roku back online!

  • Have you tried the simple things? (restarting X1 hub, restarting the remote, restarting your WIFI router)
  • Have you tried enabling debug logging for the Emulated Roku integration? Perhaps this provides clarity on why Emulated Roku is no longer working for you. Enable debug logging for the Roku integration and then restart Home Assistant, wait a few minutes and then look at the log.

If you need more help feel free to ask. When sharing logs, be careful with what you’re sharing; there’s potentially a lot of personal information in your logs.

Just commenting here that I pulled the trigger on an X2 because of this thread (and so I can find it back when I inevitably need help setting some things up :wink: )
You should really try to get some money from sofabaton, along with some dev time on the integration from them !

And my first question will be: for a X2 user, what is the benefit of NOT using the official HA integration from sofabaton and instead use the one you have generously shared with the community ?

The hard questions first huh :slight_smile:

Full disclosure: Sofabaton did very kindly provide me with an X2 + R1 bundle. Nothing was asked in return. Probably a “competing” integration was not what they had in mind. I do not have a relationship with them of any kind. Please be assured that the considerations below are fully mine.

The executive summary of what I’m about to say is: if you have an X2, please use the official integration.

Not to write an entire essay on this topic, because i could, but I think in this case, the best way to support Home Assistant is to support the OEM that is making a first-party integration for the platform. I would not want to discourage such investments in any way.
An integration like mine has high potential to confuse new users, and I get a sense from the socials that there are quite a few people getting on board with HA because of the X2.
The essay part is about how we all benefit from HA’s growth, and how initiatives like Sofabaton’s official integration are an important part of that.

It is for this reason that in the current version of “my” integration, discovery of the X2 hub is disabled by default (so the integration will not automatically find the hub). You have to set a flag in configuration.yaml to enable it.

Now, to give an actual answer to your question:

Key differences between the official integration and the “unofficial” one:

  • The X2 hub has a built in MQTT implementation. Devices that supports MQTT relay their state over this protocol and can also receive inbound commands to perform functions. The official integration leverages this mechanism to support bi-directional control over the hub.
  • The unofficial integration on the other hand sustains a TCP connection with the hub, leveraging APIs intended for the Sofabaton app. Networking details explained here.

They both achieve the same things functionally, and that is sending commands to the hub. Receiving commands from the hub is outside the scope of both integrations, and is a function of MQTT and HA’s MQTT Integration.
So you’re deploying an MQTT broker in either scenario. Plus MQTT is easier to secure, because it’s a standard. Long-term support is much more likely from the OEM and community. etc.
Essentially what this boils down to is that across almost any vector that I can think of, the official integration is the better choice.

Except for one thing only, and the reason I ultimately decided on releasing X2 compatibility at all (and honestly, that was supereasy… it’s basically the X1S with some extra buttons): the API intended for the app is much richer than what is exposed via the MQTT interface. There are yet more opportunities to do interesting things with the unofficial integration, and more things to learn about reverse engineering IoT devices.

The X1S and now the X2 are actually great devices that solve real problems, and I’m happy to contribute across whatever integration. I’ve been supporting the official integration with little things like this as well. So let’s see what your second question is :slight_smile:

1 Like

Thanks for the detailed reply !
I will then try to use the official integration first :slight_smile:
If there is something it cannot do, I will come back here and bother you to see if it’s possible to add it to yours :wink: Or contribute some code on your repo to add it if it’s within my capabilities.
Congrats again for the great work.

New to this integration as of just now is a Virtual Remote for your Dashboard!

It’s bundled with the integration as of version 0.4.7.

This card is compatible with the official X2 integration too!
Read more about this new card here: