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.