I’ve always loved the IR Remote feature of my old HTC One. It felt like a superpower to be able to mess with random tvs at random locations.
After switching to a Pixel 2 and now an iPhone it laid around for a long time in my drawers until a friend of mine borrowed it for the IR Remote Function and just now has given it back to me.
At that moment I was thinking a lot about how to be as lazy as possible and thought about how to use the phone to automate things in my room.
The idea that came to mind would be to run a HTTP Server on the HTC One to which I could send IR commands to control my projector or other IR devices.
HTTP means that I could for example create a shortcut on my iPhone which I start via Siri to start my projector. Which would save a lot of kinectic energy for me and would fit my “be as lazy as possible” life theme.
I had no idea what I was getting myself into.
Fitting into my “be as lazy as possible” theme. I was first researching if someone had already solved my problem or parts of my problem.
I found multiple IR libraries and an older project which implemented a webserver to which I could send IR commands.
With it I should be able to do this: http://your-ip-here:8080/sendIRcmd/your-ir-cmd-goes-here
Every odd number is the amount of time in μs the light is on and every odd is the amount of time the light is off.
Awesome, right? I should be almost done?
I cloned the repository with Android Studio and because it was a older project first had to adjust a few parameters so I would be able to build and install it on my HTC One.
I was able to now run it on my phone, but where to get the IR Codes from?
After some more research I found https://sourceforge.net/p/lirc-remotes/code/ci/master/tree/remotes/ a repository with a lot of strange .conf files to apparently control various devices via IR.
A .conf file looks like this:
# Please make this file available to others
# by sending it to <email@example.com>
# this config file was automatically generated
# using lirc-0.9.0-pre1(default) on Wed Jan 11 16:41:33 2017
# contributed by mxhs
# brand: Sanyo
# model no. of remote control: CXWY
# devices being controlled by this remote: projector PLV-Z2000
header 8984 4432
one 600 1626
zero 600 527
repeat 8986 2212
KEY_DELETE 0x9867 # -> reset
KEY_VIDEO 0xBC43 # -> video input
KEY_S 0x7C83 # -> s-video input
KEY_C 0xC13E # -> component1 input
KEY_2 0x817E # -> component2 input
KEY_H 0xEC13 # -> hdmi1 input
KEY_FN_2 0xC837 # -> hdmi2 input
KEY_PC 0x1CE3 # -> computer input
KEY_L 0x18E7 # -> lamp
KEY_LOGOFF 0x3CC3 # -> logo
KEY_F 0xC23D # -> freeze
KEY_BRIGHTNESS_CYCLE 0x0CF3 # -> bright
KEY_CONFIG 0x8C73 # -> contrast
KEY_T 0xA857 # -> c.temp
KEY_C 0x4CB3 # -> color
KEY_S 0x28D7 # -> sharp
KEY_P 0x708F # -> preset
KEY_U 0xB04F # -> user
Now this doesn’t look like the format I’d like to send it in?
So I searched for the specification for this configuration file, which can be found here: http://winlirc.sourceforge.net/technicaldetails.html
After reading it and unsuccessfully seraching for a usuable convertor, I tried implementing my own parser.
In retrospektiv, I should have made sure that the .conf file I was using was the right one, because my convertor works with the right .conf file. At this moment I didn’t know I was using the wrong one.
My convertor can be found here and should work: https://gist.github.com/nahakiole/b506eae3313fffc46219d28f7b16f0b5
So I didn’t know I was using the wrong .conf file and also was thinking that maybe the app itself didn’t work. Now because I never got a working usecase out of it, I tried to start over and just wanted to see if there were more open source IR Remote apps where I could see what’s happening under the hood.
I found https://www.rcoid.de/ which also had support for my projector. And I was able to start the projector with the app by downloading the right .conf file from their repository.
A major success.
Now I had proof that this .conf file should work. However I lost some confidence in my convertor, so I researched if there was a “professional” convertor that worked for sure.
After a bit more of googling and reading forums I found http://www.harctoolbox.org/IrScrutinizer.html. With this tool I could import the .conf file and export it as a readable .txt file which I can use to put together the on/off string for the app.
In the repository I’ve put instructions how to get to the final url from the .conf file with the tool: https://github.com/nahakiole/Java-Infrared-REST-API-Server-for-Android
0000 006D 0022 0002 0155 00A8 0017 003E 0017 003E 0017 0014 0017 0014 0017 003E 0017 003E 0017 0014 0017 0014 0017 0014 0017 0014 0017 0014 0017 0014 0017 0014 0017 0014 0017 0014 0017 0014 0017 0014 0017 0014 0017 0014 0017 0014 0017 0014 0017 0014 0017 0014 0017 0014 0017 003E 0017 003E 0017 003E 0017 003E 0017 003E 0017 003E 0017 003E 0017 003E 0017 068B 0155 0054 0017 0E2F
+8984 -4432 +600 -1626 +600 -1626 +600 -527 +600 -527 +600 -1626 +600 -1626 +600 -527 +600 -527 +600 -527 +600 -527 +600 -527 +600 -527 +600 -527 +600 -527 +600 -527 +600 -527 +600 -527 +600 -527 +600 -527 +600 -527 +600 -527 +600 -527 +600 -527 +600 -527 +600 -1626 +600 -1626 +600 -1626 +600 -1626 +600 -1626 +600 -1626 +600 -1626 +600 -1626 +598 -44083
+8986 -2212 +598 -95553
900A 006C 0000 0001 3300 00FF
This worked and now I was able to turn my projector on and off using a GET Request.
I hid my HTC under my speakers, facing the IR sensor towards the projector, and plugged it into a power source so the phone won’t die.
Now I added a shortcut for turning on and one for turning off my projector by using the network block in the shortcuts app.
And voilà, now I can start and stop my projector with Siri.