Using an old Android phone as an IR Remote with Home Assistant
Hey everyone! After a lot of head scratching and drawing blanks searching for a ready-to-use solution that allowed me to use my old phone as an IR remote together with Home Assistant, I decided to work it out and put together my own guide.
Problem:
I have a Bose TV Speaker (soundbar) connected to a Google TV 4K with Chromecast via Bluetooth. When I turn the projector on, I want the soundbar to turn on at the same time, but because itâs connected through Bluetooth, thereâs no way to implement CEC controls or similar. When I turn the projector on, I currently have to use a separate remote to turn on the speakers.
Solution:
I have a POCO M3 lying around, and the device happens to have an IR led built-in on its top edge, near the 3.5mm headphone port. Rather than ordering a dedicated IR blaster, Iâm going to use the M3 to turn on/off my soundbar whenever the projector turns on.
A Quick Heads Up:
I am brand new to Home Assistant, and although I like to work my way around technical problems by emulating the steps others have taken, I am absolutely not an expert in HA or any of the tools or languages used to make things happen in home automation.
Please feel free to make suggestions around how I put my IR remote together, and donât hesitate to tell me this guide is crap if thereâs a better solution available.
Assumptions
- You have a spare Android phone with an IR blaster built-in
- You have a Mac (although this can also be done with Windows/Linux)
- You have an IR controlled soundbar or other IR controlled device
Steps
- Set up Android phone to run the IR remote automatically
- Add configuration to Home Assistant
Android Phone Setup
Youâll need to download a couple of apps: An IR remote app of your choice (I used MiRemote) and MacroDroid. Youâll find both in the Google Play Store
Set up your IR remote app and make sure youâre able to turn on/off your speakers using the power button in the app. Once youâve done that, get MacroDroid installed and running and enable all the system options it needs such as: turning off battery management for the app, allowing it to run in the background, accessibility settings to allow it to control the screen etc.
Youâll be giving pretty wide sweeping access to MacroDroid to control your phone, so this is a good time to say that this guide is intended only for those who are setting up a phone that will be used pretty much exclusively to control IR elements of their media system.
Part 1: MIRemote
- Install MIRemote and set it up to work with your speakers of choice
The macro I made and shared below only turns on/off the power function within MiRemote, but it should be pretty easy to add extra functions if youâd like to do that.
Part 1: Phone Settings
- Remove password/pin lock from your phone
- Enable developer mode and USB debugging (follow these instructions)
- Download Android SDK Manager Platform-Tools
- Plug your phone into your computer - in my case, Iâm using a Mac
- Open up the command line on your PC/terminal on a Mac
- Set the current directory to the Platform-Tools folder with this command
cd /Users/name/Downloads/platform-tools
- Tell your phone to bypass the lock screen upon waking
./adb shell settings put secure lockscreen.disabled
- Reboot your phone
./adb reboot
- If all went correctly, your phone should reboot straight to the home screen, bypassing the lock screen. If this doesnât happen, first check that you removed your pin/password lock in system settings, then try the above steps again.
Part 2: MacroDroid
- Download my pre-configured MacroDroid macro here - this link will expire in a yearâs time (today is May 4th 2023) so feel free to say if you need a copy
- Open the macro in MacroDroid and tap on the Trigger âShake Deviceâ then delete it.
- Tap the â+â in the Triggers section
- Tap on the search icon, then enter âWebhookâ and select âWebhook (Url)â
- Enter an identifier
- Take note of the URL it gives you, as youâll need this for Home Assistant
- Save any changes and enable the macro. Youâll know itâs enabled when the slider across from the macro name is set to the âonâ position on the menu screen
Summary of the macro: It wakes the phone, opens MIRemote, taps on the on/off button of your emulated IR remote, then puts the phone back to sleep
Part 3: Home Assistant Setup
- Open the configuration YAML file in your text editor of choice
- Enter the following into the config file, then save it
#MacroDroid Command
rest_command:
bose_soundbar:
url: "MacroDroid_url_goes_here"
- Open Developer Tools in HA then click âCheck Configurationâ and, if all is good, click Restart
- After restart, go to Settings > Automations > Create Automation
- Enter any Trigger youâd like - mine looks for the power consumption of my projector to go above 25W
- Click âAdd Actionâ then âCall Serviceâ and look for âRESTful Command: bose_soundbarâ (or whatever you chose to name the command in your YAML file)
- Click âSaveâ and give the automation a name
Congrats!
When your automation is triggered, your phone will now launch MIRemote and turn on/off your speaker.
Feel free to set up another automation, that calls the same RESTful Command service, to turn your speaker off when youâve finished watching TV.
N.b. As a new user of the HA Community, I could only post 2 links in the guide. Android SDK Platform-Tools can be found easily online, and MIRemote is in the Google Play Store