Or, how to control your A/C from your phone
You may have seen my earlier post about my new home automation setup. Well I just upgraded it! I just finished testing out a new infrared remote control send and receive capability and it is pure awesome. Here’s what I can do now from within home-assistant:
- Turn on and off my new DeLonghi portable air conditioner from Costco, and set the temperature to whatever
- Turn on and off the TV and press any buttons from its remote control
- Turn on and off the stereo and virtually press any buttons from its remote control (which I never even had!)
- Use an old random blueray remote control to set scenes, turn lights on and off, etc. (basically do anything under home-assistant’s control)
This post is about how I did it on my Raspberry Pi.
Update: A video!
Setting up LIRC and learning the A/C remote
LIRC is a linux library to interface with infrared (IR) remotes. Setting it up, including schematics for hooking the IR receiver and emitter to the GPIO ports of the Pi are well-described here. So following those instructions is the first step.
Then I had to teach LIRC about my equipment. The one I was most worried about was my DeLonghi “Pinguino” portable air conditioning unit from Costco (AN125HPEK). I was able to successfully learn the commands from the remote using LIRC in raw-capture mode. This post was very useful in figuring it out. A/C units send full packets, including information about what mode it’s in, what numerical temperature it’s set to (not just up and down), etc. Here’s what I did:
- I recorded a bunch of raw data and remember the order of buttons you pressed. For example, first I had the remote at the maximum temperature and then after I started recording I pressed “decrease temperature” a bunch of times until I was at the minimum:
begin remote name DELONGHI flags RAW_CODES eps 30 aeps 100 gap 183413 begin raw_codes name OFF 8941 4531 505 1699 506 1697 510 621 508 … name AC_23 ... end raw_codes end remote
3. Then I used irrecord in analyze mode to process the raw signals and extract the hex codes:
irsend SEND_ONCE DELONGHI FAN_LOW
blew my mind when it worked. Yay. Excellent progress. I used irrecord in its normal learn mode to learn my Sony remote and it just asks you to name each key before you press it. That worked great. The codes I recorded for this A/C are available here.
Writing a new home-assistant component for lirc
With what I had up to this point, I could use home-assistant as is and use the shell_command component to control things around my house. This was what was recommended last time a lirc component was requested. I tried it out and it worked great:
shell_command: ac_on: irsend SEND_ONCE DELONGHI AC_25 ac_off: irsend SEND_ONCE DELONGHI OFF stereo_on: irsend SEND_ONCE STR-DE205 KEY_POWER stereo_video1: irsend SEND_ONCE STR-DE205 KEY_VIDEO1 stereo_off: irsend SEND_ONCE STR-DE205 KEY_POWER stereo_video2: irsend SEND_ONCE STR-DE205 KEY_VIDEO2
But then I got thinking that it’d be cool if I could have a IR remote control various aspects in home-assistant. My wife sometimes complains that she has to go find a phone to turn on the lights. If I had a remote laying on the table it’d be really easy to select scenes and whatnot. So I thought I’d write a lirc component.
Conveniently, there’s a python-lirc package in pip that brings lirc capabilities into Python3. So making a component was just a matter of interfacing between that package and home-assistant. I whipped up a component and tested it out by having KEY_1 turn on a scene and KEY_0 turn all lights off. It works! SO AWESOME!
I will open a pull request and try to get this feature into home-assistant for all to enjoy.
Now I can make rules that, you know, turn on my tv, my stereo, and put up a fireplace video like this:
lirc: automation: - alias: Full fire sequence trigger: platform: event event_type: ir_command_received event_data: button_name: X_KEY_NETFLIX action: service: script.fire_sequence script: - fire_sequence: alias: Fire Sequence sequence: - service: shell_command.fire - delay: seconds: 1 - service: shell_command.tv_power - delay: seconds: 1 - service: shell_command.stereo_line_in # turns on stereo
So awesome. I have submitted the code as PR 2139 and maybe it will go in the next release.
I’ve started toying with the shell_command to allow it to build the command from slider input so I can set the A/C to any value I want. Will open another PR if this guys doesn’t.