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:
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
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.
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
@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.
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.
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.
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.
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.
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?
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?