How to: Use an old Android phone as an IR Remote with Home Assistant

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

  1. Set up Android phone to run the IR remote automatically
  2. 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

  1. 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

  1. Remove password/pin lock from your phone
  2. Enable developer mode and USB debugging (follow these instructions)
  3. Download Android SDK Manager Platform-Tools
  4. Plug your phone into your computer - in my case, I’m using a Mac
  5. Open up the command line on your PC/terminal on a Mac
  6. Set the current directory to the Platform-Tools folder with this command cd /Users/name/Downloads/platform-tools
  7. Tell your phone to bypass the lock screen upon waking ./adb shell settings put secure lockscreen.disabled
  8. Reboot your phone ./adb reboot
  9. 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

  1. 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
  2. Open the macro in MacroDroid and tap on the Trigger “Shake Device” then delete it.
  3. Tap the “+” in the Triggers section
  4. Tap on the search icon, then enter “Webhook” and select “Webhook (Url)”
  5. Enter an identifier
  6. Take note of the URL it gives you, as you’ll need this for Home Assistant
  7. 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

  1. Open the configuration YAML file in your text editor of choice
  2. Enter the following into the config file, then save it
#MacroDroid Command

rest_command:
  bose_soundbar:
    url: "MacroDroid_url_goes_here"
  1. Open Developer Tools in HA then click “Check Configuration” and, if all is good, click Restart
  2. After restart, go to Settings > Automations > Create Automation
  3. Enter any Trigger you’d like - mine looks for the power consumption of my projector to go above 25W
  4. 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)
  5. Click “Save” and give the automation a name

Congrats! :partying_face:

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 :slightly_smiling_face:

1 Like

Need a new link please!

Sorry I don’t have a copy of the macro file anymore :disappointed_relieved:

Not only that - the MiRemote you named does have full camera access, microphone access and full internet access :camera_flash: :studio_microphone: :globe_with_meridians:

But indeed MacroDroid even worse with 6 trackers and wanting all(?) 108 permissions that a device can offer - probably can’t expose a device more :put_litter_in_its_place:

While I’m very much for using old hardware and give them a second or third life this application here might be the worse IR remote in terms of privacy. I don’t want to fear that my IR blaster records audio and video and send that to strangers over the world wide web :no_good_man:

That said an invest of only a few dollars for a esp based IR blaster running esphome might be a good invest if privacy matters :bulb:

1 Like

I couldn’t agree more :slight_smile: ESP is absolutely the way to go and I actually swapped out the phone for an ESP IR module a while back