[Sofabaton X2] Trigger any command on the X2 hub, from Home Assistant

If you use the pattern I showed you before, you don’t have to make an automation for each button. You can have it all in a single automation.
Like this:

alias: X2 -> HA command handling
description: ""
triggers:
  - trigger: mqtt
    options:
      topic: FCXXAABBSDSD/up
conditions: []
actions:
  - variables:
      device_id: "{{ trigger.payload_json.device_id }}"
      key_id: "{{ trigger.payload_json.key_id }}"
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ device_id == 2 and key_id == 1 }}"
        sequence:
          - action: light.toggle
            metadata: {}
            target:
              entity_id: light.office
            data: {}
      - conditions:
          - condition: template
            value_template: "{{ device_id == 2 and key_id == 2 }}"
        sequence:
          - action: light.toggle
            metadata: {}
            target:
              entity_id: light.living_room
            data: {}

What this YAML says:

  • Trigger the automation on every update of the [MAC]/up MQTT topic.
  • Parse device_id and key_id from the MQTT trigger and put them into variables. For the rest of the automation, we can use these variables whenever we need them.
  • Uses choose to construct an if / then pattern. Within all elements placed inside a choose, only 1 will be chosen. The one that is chosen is the first one to return true in its condition. Here a condition of the type template is used. This allows us to use arbitrary templating to return either true or false
      - conditions:
          - condition: template
            value_template: "{{ device_id == 2 and key_id == 1 }}"
        sequence:
          - action: light.toggle
            metadata: {}
            target:
              entity_id: light.office
            data: {}

So with this YAML the lights in the office are toggled but only if device_id equals 2 and key_id equals 1. Just keep adding these for every ‘button’ that you made, changing key_id (and potentially device_id) as you go.

Thanks this is great so I have everything setup, item I’m wondering now is went into HA and the Sofabaton Hub Custom Card is now showing activities but has this 101 in it for some reason.

Any thoughts where the 101 is coming from?

Should also mention that the XBox 360 is first in my Activities and the Shield second so not sure if it’s sorting in the pulldown.

The hub uses internal IDs for all Devices, Activities, commands etc. The IDs for Activities start at 101, so fairly sure that this is where the number is coming from. Are you missing any Activities, or do you just have the 2? This issue will go away for sure if you do any of these things:

  • rename your Activities
  • change order of your Activities
  • add some more Activities
  • reboot the hub
  • reload the X2 integration

Also try this card to see how well that works for you (it works with the Sofabaton Hub integration)

Useful to know:

  • Receiving commands from the hub is NOT a feature of the Sofabaton Hub integration. It’s a feature of the hub’s MQTT support in combination with HA’s MQTT integration. Even if you removed the Sofabaton Hub integration completely, receiving button presses will continue to work as long as your MQTT broker and MQTT integration are in place.
  • The Sofabaton Hub integration is only there to send commands to the hub. It does this by adding a remote.x2_hub entity to Home Assistant. All other features of the Sofabaton Hub integration (like the UI stuff) are derived from the remote entity. So one good thing to do is to look at that remote entity directly to have a better understanding of what’s happening.
    If you go to Settings → Developer tools → States and then find your remote.x2_hub, you will see the metadata the remote is currently exposing, including a list of your Activities. While you change Activities using your X2 remote (or app), refresh the Developer Tools/States view to see how the remote entity changes when you do that.

Here’s a template sensor I find helpful in my automations. I sometimes want to tell within HA when the Sofabaton has switched to a different activity or have things in HA behave differently based on the current activity.

This template sensor uses the remote’s attributes to make a friendlier current status sensor. Note that the states will change if you rename your activities. Change remote.sofabaton_x2_hub' to match your remote’s entity.

- sensor:
    - name: "Current SofaBaton Activity Name"
      default_entity_id: sensor.sofabaton_activity
      unique_id: sofabaton_activity
      state: >
        {% set activity_id = state_attr('remote.sofabaton_x2_hub', 'current_activity_id') %}
        {% set activities = state_attr('remote.sofabaton_x2_hub', 'activities') %}
        {% if activity_id and activities %}
          {{ (activities | selectattr('id', 'eq', activity_id) | list | first).name }}
        {% else %}
          Power Off
        {% endif %}
      icon: mdi:remote
1 Like

@m3tac0de Just want to say thanks for that keyscraper script. That’s been the most helpful thing I’ve found while setting up my automations that used to send via Harmony. Copy/pasted the resulting notifications and I have a super-handy way to grab the code for sending a remote key. Thanks so much for this.

1 Like

I do only have the two. Funny you should ask about the virtual remote. Seems neat but has a bug. So I see it in HA on the phone however on my Windows laptop when I save everything it goes away.

If I edit then it shows up

JR

That’s not good @jriker1, i’d like to fix it. I imagine that it has to do with the incorrect Activity state the Sofabaton Hub integration is showing in your screenshots (the “101” makes no sense).

Have you been able to resolve that issue, does that Activity dropdown now show the right Activities? If the Virtual Remote card is still not working, please press F12 on your keyboard when the card is in a faulty state. This will open the developer tools of your browser and towards the bottom it will show you the console. I would like to see a screenshot of that.

OK let me add it back in. So when I try and add that card I can’t select the hub which I had that issue last time.

When i try and “click” on it it doesn’t like accept what I clicked on and stays with the full pulldown. I have to go to show code editor and manually enter it.

As you see it’s still showing the 101 but the other two are there in the pulldown.

I add the card now and I have the Shield running at the time. It still says 101 but shows the Shield Activity is on.

Also going to share some errors in my logs. They may be normal or may be more of them if I download the log and view it vs the graphical logs:

Logger: custom_components.sofabaton_hub.coordinator
Source: custom_components/sofabaton_hub/coordinator.py:159
integration: Sofabaton Hub (documentation, issues)
First occurred: 9:18:48 AM (1 occurrence)
Last logged: 9:18:48 AM

Timeout waiting for activity list for 206EF12413B8 (waited 10 seconds)

Logger: custom_components.sofabaton_hub.coordinator
Source: custom_components/sofabaton_hub/coordinator.py:200
integration: Sofabaton Hub (documentation, issues)
First occurred: 9:18:53 AM (1 occurrence)
Last logged: 9:18:53 AM

Basic data request timeout for 206EF12413B8

These warnings may be temporary. I did have another one before where it was complaining about 101 and 102 that it couldn’t find them but not seeing it right now.

Some more info on what I mentioned before about the 101 and 102 errors. I have a script that in theory would turn off anything running on the Sofabaton Hub.

sequence:
  - action: remote.turn_off
    metadata: {}
    target:
      device_id: 
    data: {}
alias: "Sofabaton: Turn Off"
description: ""

Once in a while this works and everything turns off. Frequently it does not. When it fails I get this error in HA

Log details (WARNING)

This error originated from a custom integration.

Logger: custom_components.sofabaton_hub.coordinator
Source: custom_components/sofabaton_hub/coordinator.py:675
integration: Sofabaton Hub ([documentation](https://github.com/yomonpet/ha-sofabaton-hub), [issues](https://github.com/yomonpet/ha-sofabaton-hub/issues))
First occurred: April 6, 2026 at 6:04:43 AM (3 occurrences)
Last logged: April 6, 2026 at 6:24:35 PM

* Received unknown activity_id: 101
* Received unknown activity_id: 102

So maybe thinking it’s confused by the numbers of the activity assigned to each activity?

Note I found someone else posting issues with remote turn_off and their resolution was a bit more than this but I changed my script to:

sequence:
  - parallel:
      - action: remote.turn_off
        metadata: {}
        target:
          entity_id: remote.x2_hub
        data: {}
      - action: remote.turn_off
        metadata: {}
        target:
          device_id: 
        data: {}
alias: "Sofabaton: Turn Off"
description: ""

So far, knock on wood, it seems to have helped with the turn off portion of things. Not sure why running two commands at the same time would make a difference but how they did it. Possible I guess using the device_id for this doesn’t work right?


This is kind of stupid but forum won’t let me add to this because no one is posting anything so have to keep editing an unrelated one. Anyway,

Looks like replies may have dropped off however I know at some point, maybe a Sofabaton update in HA not sure, a script that did work and also worked thru Alexa just stopped local or otherwise. It’s basically:

sequence:
  - parallel:
      - action: remote.turn_off
        metadata: {}
        target:
          entity_id: remote.x2_hub
        data: {}
      - action: remote.turn_off
        metadata: {}
        target:
          device_id: <obscure>
        data: {}
alias: "Sofabaton: Turn Off"
description: ""

Anyone know why it just stopped working? remote.x2_hub is still a valid entity.

Wonderful instructions, thanks. However, I can't seem to find the key codes for the numeric virtual keys (1,2,3,4, etc) that my TiVo activity uses. The Sofabaton device's virtual keypad doesn't include the numeric keys, so I can't select 1, 2, 3 to see what the code is in the logs.

try this @vahighland

It's a blueprint for a script that when you run it returns all ids for a device or activity.

Thx, I’ll try that

Has anyone installed this offical integration recently and got it working?
I’m making the switch from harmony elite - which worked fine in HA
I have MQTT installed, the integration installed, but the official sofabaton card doesnt seem to work properly
when setting up the new card, I can see my hub in the drop down entity list but it wont allow me to select it.
If I enter the hub entity in the card YAML then it populates the card dropdown with my activities but I am also unable to select an activity - if I click on a dropdown option it will not register as selected
If however I find the activity entity through settings and flip the switch, it works fine
So there appears to be something weird going on with the sofabaton card.
Unfortunately there does not seem to be much development activity on the official integration.
Any help appreciated
cheers

Not really an answer to your question, but when I set up my X2 in Home Assistant, I found the SofaBaton X2 Library Scraper blueprint to be super handy. When you run it, it’ll generate persistent notifications with the activity IDs, device IDs and key IDs for everything. Copy that into a text file and keep it handy when you build automations/scripts.

Hello @wazza_c12. Are there any errors in the Home Assistant log?

There are some issues with the MQTT implementation on the hub and with the integration itself, but those issues can be worked around for the most part.

  • The hub frequently fires its MQTT “activity changed” update BEFORE the internal state of the hub has actually changed. When the integration immediately responds to the changed update by retrieving a fresh list of activities, while the hub is still in an intermediate state, state corruption can occur (the integration is showing you hub state that doesn’t match actual state)
  • The integration has 2 triggers for retrieving fresh information from the hub. In certain edge cases, these compete (a race condition) and may deliver incorrect data to the user.
  • The hub is unable to return larger datasets over MQTT, consistently. Additionally, it appears that each time it fails, there is some type of residual effect that progressively impacts the performance of the hub.

Things to do:

  • Reboot your hub and once its back up restart Home Assistant. This may resolve your immediate issue.
  • As we wait for official updates to firmware/integration, I have a fork of the official integration sitting in my repo that addresses and works around some of these issues (it cannot fix the large dataset issue). The fork is here.
  • You could potentially try this alternative remote card for your X2 hub and see if you get better/different results.
  • You could potentially try this alternative integration that works with your X2 hub. It can co-exist with the official integration.