Saturday 20 June 2015

Control the air conditioner with openhab



you want to turn on the air conditioner and you can't find the remote control, or in case you find it it, the batteries hasn't enough power. Yes, is so frustating.
Anyway, if you don't have any of this problems is a good idea to have only real universal remote control, one you have all the time with you, your cell phone!!.


With openhab, raspberry and arduino you can do it. First of all you have to install the domotic server in a raspberry as it was explained in the last post.
The tutorial consist in four steps
  1. record the ir signal with your arduino
  2. create the emitter in your raspberry
  3. create the item in openhab
  4. enjoy your confort

Record Arduino signal 

you can record the signal with the raspberry, but it was easier for me is to use the arduino for this task. The circuit is very similar but with the raspberry you must record with the lirc library, i use this library for send the signal but it is not the best way to receive, in my opinion, of course.
Lirc has a big database with ir signals for brands like samsung, lg, mitsubishi, etc. In my case i have an AUX air conditioner, wich doesn't exists in the lirc's database. so i have no other way than to record the signals by myself. If you have a known brand for lirc you don' t have to record with the arduino, you can skip this step.

Requirements

  1. Arduino, it can be any version, y i used the uno
  2. vs1838B , ir receiver
    http://www.amazon.com/gp/product/B008GS4E28?psc=1&redirect=true&ref_=oh_aui_detailpage_o03_s01.
  3. Wires

to record the infrared (ir) signal you have to buy the ir receiver,  I use the vs1838B it is a very cheap piece.
about the arduino there are a lot of cheap versions ,in my case i bought one from aliexpress, this is the link http://www.aliexpress.com/snapshot/6660856587.html?orderId=67207253926866. And only cost $3.88!!!

Once you have all the required pieces you have to build the circuit like this


arduino ir receiver
the best way to record the signal is with the shirriff' s library, you can download the library from this link https://github.com/shirriff/Arduino-IRremote/releases. It is very easy to use.
For the air conditioner you need the raw signal, there are a lot of numbers and you can' t receive/send it with the NEC protocol. To receive the raw signal i used the IRrecvDump example from the library.

The output is something like that for a command

219DBA7D
Unknown encoding: 219DBA7D (32 bits)
Raw (212): 18398, 8850, -4500, 500, -1750, 450, -1750, 450, -600, 500, -600, 500, -600, 500, -600, 450, -1750, 450, -1750, 450, -1750, 450, -1750, 450, -1750, 450, -1750, 500, -1700, 500, -1700, 500, -1700, 500, -600, 450, -650, 450, -600, 500, -600, 500, -600, 500, -600, 450, -600, 500, -600, 500, -600, 500, -600, 450, -600, 500, -600, 500, -600, 500, -600, 450, -650, 450, -600, 500, -600, 500, -600, 450, -650, 450, -600, 500, -600, 500, -600, 500, -1700, 500, -600, 450, -600, 500, -600, 500, -600, 500, -600, 450, -650, 450, -600, 500, -600, 500, -1700, 500, -600, 450, -650, 450, -600, 500, -600, 500, -600, 500, -600, 450, -600, 500, -600, 500, -1700, 500, -600, 500, -600, 450, -650, 450, -600, 500, -600, 500, -600, 450, -650, 450, -600, 450, -650, 500, -600, 500, -600, 450, -600, 500, -600, 500, -600, 500, -600, 450, -600, 500, -600, 500, -600, 500, -600, 450, -650, 450, -600, 500, -1700, 500, -600, 500, -600, 450, -650, 450, -600, 500, -600, 500, -600, 500, -600, 450, -600, 500, -600, 500, -600, 500, -1700, 500, -600, 450, -1750, 500, -550, 500, -600, 500, -600, 500, -600, 500, -600, 450, -1750, 450, -1750, 450, -1750, 450, -650, 450, -600, 500, -600, 500, -1700, 500, -600, 500, 


We have to work in this output,remove the first number (18398 in this example), the minus symbol and the commas. The result is like that.

8850 4500 500 1750 450 1750 450 600 500 600 500 600 500 600 450 1750 450 1750 450 1750 450 1750 450 1750 450 1750 500 1700 500 1700 500 1700 500 600 450 650 450 600 500 600 500 600 500 600 450 600 500 600 500 600 500 600 450 600 500 600 500 600 500 600 450 650 450 600 500 600 500 600 450 650 450 600 500 600 500 600 500 1700 500 600 450 600 500 600 500 600 500 600 450 650 450 600 500 600 500 1700 500 600 450 650 450 600 500 600 500 600 500 600 450 600 500 600 500 1700 500 600 500 600 450 650 450 600 500 600 500 600 450 650 450 600 450 650 500 600 500 600 450 600 500 600 500 600 500 600 450 600 500 600 500 600 500 600 450 650 450 600 500 1700 500 600 500 600 450 650 450 600 500 600 500 600 500 600 450 600 500 600 500 600 500 1700 500 600 450 1750 500 550 500 600 500 600 500 600 500 600 450 1750 450 1750 450 1750 450 650 450 600 500 600 500 1700 500 600 500 

Now is ready for copy the command in the lirc file, you have to do this procedure for each button. You can hack the signal and interpret it. If you send me the interpretation of the signal i will be very grateful :). It is a very annoying task. if the value less than thousand (450,500,600,etc) the value is 0 and 1 in the other case (1700,1650,1500,etc). This is the way, i was boring viewing the signal in a excel so i decided only to keep the signals i really care.

create the emitter in your raspberry

Requirements

  1. Raspberry pi, any version , i used raspberry pi b+
    http://www.amazon.com/Raspberry-Pi-Model-Plus-512MB/dp/B00LPESRUK/ref=sr_1_1?ie=UTF8&qid=1434827021&sr=8-1&keywords=raspberry+pi+b
  2. Ir Sender
    http://www.amazon.com/gp/product/B00A1BSD8O?psc=1&redirect=true&ref_=oh_aui_detailpage_o00_s00
First of all you have to build the circuit

raspberry pi with ir emitter

Easy, don't you think?, now you have to install the lirc service, follow the instructions in the next link http://alexba.in/blog/2013/01/06/setting-up-lirc-on-the-raspberrypi/, take care that you are using the pin 18 for the emitter and
you don' t have a receiver installed in the raspberry.
The file /etc/lircd.conf is something like that

# Please make this file available to others
# by sending it to <lirc@bartelmus.de>
#
# this config file was automatically generated
# using lirc-0.9.0-pre1(default) on Tue Jan  6 10:41:06 2015
#
# contributed by
#
# brand:                       /home/pi/lircd.conf.conf
# model no. of remote control:
# devices being controlled by this remote:
#

begin remote

  name  air
  flags RAW_CODES
  eps 30
  aeps 100

  ptrail 0
  repeat 0 0
  gap 40991

begin raw_codes
name TURN_OFF
8900 4550 550 1700 550 1700 550 550 550 550 550 550 550 550 550 1700 550 1700 550 1700 550 1700 550 1700 550 1700 550 1700 550 1700 550 1700 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 1700 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 1700 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 1700 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 1700 550 550 550 1700 550 550 550 550 550 550 550 550 550 550 550 1700 550 1700 550 1700 550 550 550 550 550 1700 550 550 550 550 550
name TURN_ON_COLD_23
8900 4400 550 1700 550 1700 550 550 550 550 550 550 550 550 550 1700 550 1700 550 1700 550 1700 550 1700 550 1700 550 1700 550 1700 550 1700 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 1700 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 1700 550 550 550 550 550 550 550 550 550 550 550 550 550 1700 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 1700 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 550 1700 550 550 550 1550 550 550 550 550 550 550 550 550 550 550 550 1700 550 1700 550 1700 550 550 550 550 550 1700 550 1700 550 1700 550
end raw_codes
end remote


In the example there are only two commands, you must add all the commands that you want to execute. To execute the command by command line you have to type

irsend SEND_ONCE air TURN_OFF

being TURN_OFF the command defined in the lircd.conf.
Now you can use the air conditioner from the raspberry, the only step left is to create the user interface in openhab

create the item in openhab

 I don' t record all the commands of the re

I don't record all the commands of the remote control, only those i really often use. I control the temperature, if i want cold/heat mode, switch on/off the timer and switch on/off the screen.
Remember i am using openhab so i can make rules like if the house reach some temperature and i am in home the air conditioner auto start or switch off the air conditioner if i left my home.
I have the server with no-ip so if i am arriving home and it is cold i can switch on the air conditioner before i arrive.
An important Hint!!, lirc have a problem in the raspberry, you have to restart the lirc service once the raspberry  finished the startup. To do that you can do it in the Init rule (using System started).

demo.items

Switch Air_Conditioner "Aire Condicionado"  <air_conditioner> (Appliance)
String Air_Conditioner_Mode "Modo"  <settings> (Appliance)
String Air_Conditioner_Temperature "Temperatura"  <temperature> (Appliance)
Switch Air_Conditioner_Timer "Timer"  <clock> (Appliance)
Switch Air_Conditioner_Screen "Display"  <display> (Appliance)

demo.rules


//*******************************************************************
//AIRE CONDITIONER
//*******************************************************************
rule "Air Conditioner"
    when
        Item Air_Conditioner received command
    then
        logInfo("Air Conditioner",receivedCommand + "" +Air_Conditioner_Mode )
        var String command;
      
        if(receivedCommand == ON){
            sendCommand(Notifications, "Prendiendo Aire Condicionado")
            if ((Air_Conditioner_Mode.state+"") == "1")    command = "irsend SEND_ONCE air TURN_ON_COLD_" + Air_Conditioner_Temperature.state;
            if ((Air_Conditioner_Mode.state+"") == "2")    command = "irsend SEND_ONCE air TURN_ON_HOT_" + Air_Conditioner_Temperature.state;
        }
        else{
            sendCommand(Notifications, "Apagando Aire Condicionado")
            command = "irsend SEND_ONCE air TURN_OFF";
        }
        logInfo("Air Conditioner",command)
         executeCommandLine(command);
      
end

rule "Air Conditioner Screen"
    when
        Item Air_Conditioner_Screen received command
    then
        logInfo("Air Conditioner Screen",receivedCommand + "")
        var String command;
        command = "irsend SEND_ONCE air SCREEN_" +Air_Conditioner_Temperature.state;
        if(receivedCommand == ON){
            sendCommand(Notifications, "Prendiendo display del aire")
        }
        else{
            sendCommand(Notifications, "Apagando display del aire")
        }
        executeCommandLine(command);
end

rule "Air Conditioner Timer"
    when
        Item Air_Conditioner_Timer received command
    then
        logInfo("Air Conditioner Timer",receivedCommand + "")
        var String command;
      
        if(receivedCommand == ON){
            sendCommand(Notifications, "Prendiendo Timer del aire")
            if ((Air_Conditioner_Mode.state+"") == "1")    command = "irsend SEND_ONCE air TIMER_ON_COLD_" + Air_Conditioner_Temperature.state;
            if ((Air_Conditioner_Mode.state+"") == "2")    command = "irsend SEND_ONCE air TIMER_ON_HOT_" + Air_Conditioner_Temperature.state;
        }
        else{
            sendCommand(Notifications, "Apagando Timer del aire")
            if ((Air_Conditioner_Mode.state+"") == "1")    command = "irsend SEND_ONCE air TIMER_OFF_COLD_" + Air_Conditioner_Temperature.state;
            if ((Air_Conditioner_Mode.state+"") == "2")    command = "irsend SEND_ONCE air TIMER_OFF_HOT_" + Air_Conditioner_Temperature.state;
        }
        logInfo("Air Conditioner Timer",command)
         executeCommandLine(command);
      
end

demo.sitemap

Text item=Air_Conditioner label="Aire Condicionado" {
            Frame {
                Switch item=Air_Conditioner 
                Selection item=Air_Conditioner_Mode   mappings=[1='Frío', 2='Calor']
                Selection item=Air_Conditioner_Temperature  mappings=[21='21', 23='23', 25='25']
                Switch item=Air_Conditioner_Timer
                Switch item=Air_Conditioner_Screen 
               
            }
        }

35 comments:

  1. Hello,
    I have found your project via Google.
    I'd like to command a roomba cleaner using rpi and ir led. I have the same led as you have.
    I can send commands to roomba but the range is about 1 meter.
    Did you get a better range ?
    Any advice to improve it ?
    Regards

    ReplyDelete
  2. Mod a roomba remote, and use a relay to close connections on the remote (assuming the roomba remote has better range). It wouldn't be too aesthetically pleasing, but I would 100% work.

    ReplyDelete
  3. Very nice idea about Control the air conditioner with open hab. thanks for shearing with us.
    air handling units

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete

  5. Heating and Cooling Etobicoke



    Great tips..The summers are getting hotter and cruel, so it is very important that you know how to deal with small issues of AC's yourself and i hope your visit this website

    ReplyDelete
  6. Wooo man that was a great article. Well I am not a electronics person so these things are getting harder for me.

    Heating and Cooling Hamilton

    ReplyDelete
  7. Hi! Very nice tutorial. I'm trying to do sth similar. Can you please explain how did choose what parameters to put in conf file? i mean these ---> " eps 30, aeps 100, ptrail 0, repeat 0 0, gap 40991 "

    ReplyDelete
  8. Hi
    I have managed to record the remote.
    But when i run the irsend command I get this error:
    irsend: command failed: SEND_ONCE KM09D KEY_POWER
    irsend: transmission failed

    I get the samme error on alle commands/key

    ReplyDelete
  9. While choosing an air conditioner for your home look for some of these features — sleep settings, filter alerts, remote controls, energy-saving options, timers and noise insulation. Room air conditioners which match Btu requirements to room size are best because the rooms won't cool efficiently if the Btu rating is too low or too high for the size of the room.
    http://www.airmart.com.au/products/commercial-solutions/central-ducted-refrigerative-system/

    ReplyDelete
  10. I'm much happy after reading this blogspot. Specially this article kept lot of information.

    Heating and Cooling Scarborough

    ReplyDelete
  11. Very excellent information. Thank you for sharing.
    air duct cleaning services

    ReplyDelete
  12. Thanks for sharing article on panasonic Air Conditioner. It's really helpful for who looking to know/buy, keep sharing... :)

    ReplyDelete
  13. Hi there! Do you know if they make any plugins to help with Search Engine Optimization? I'm trying to get my blog to rank for some targeted keywords but I'm not seeing very good success. If you know of any please share. Appreciate it! air conditioner installation cost

    ReplyDelete
  14. Hmm it looks like your website ate my first comment (it was super long) so I guess I'll just sum it up what I had written and say, I'm thoroughly enjoying your blog. I as well am an aspiring blog writer but I'm still new to the whole thing. Do you have any helpful hints for inexperienced blog writers? I'd definitely appreciate it. ducted air con

    ReplyDelete
  15. شركة تركيب اثاث ايكيا بالرياض
    فني تركيب اثاث ايكيا بالرياض
    طريقة تركيب اثاث ايكيا
    عامل تركيب اثاث ايكيا بالرياض
    شركة تركيب ستائر بالرياض
    عامل تركيب ستائر بالرياض
    فني تركيب ستائر بالرياض
    شركة تركيب غرف نوم بالرياض
    فني تركيب غرف نوم بالرياض
    طريقة تركيب غرف النوم الصيني
    شركة تركيب باركية بالرياض
    ارخص تركيب باركية بالرياض
    شركة تركيب عفش بالرياض
    شركة تنظيف مكيفات بالرياض
    عملائنا الكرام اذا كنت تبحث عن افضل واقوي شركة تركيب اثاث فى هذا المجال كما انها تتميز بالصدارة بين الكثير من الشركات المتواجدة في الرياض
    شركة تركيب اثاث ايكيا بالرياض
    كما اننا نتميز عن باقي الشركات بأننا لدينا افضل الطرق وافضل الادوات والمعدات فى تركيب غرف النوم الصيني
    كما اننا متقدمين عملائنا الكرام بتقديم افضل خدمات تركيب اثاث ايكيا بالرياض مع توفير امهر الفنيين في تركيب اثاث ايكيا كما اننا نعلم جيدا تعدد حاجات عملائنا من احتياج الفنيين والمتخصصين في عمليات فك وتركيب اثاث ايكيا بالرياض واحتاجهم لتواجد المساعدين لانجاز مهامهم بدقة وعلي اكمل وجة ممكن
    كما اننا نقدم العديد من الديكورات المختلفة والتصميمات الساحرة واحدث الالوان العصرية التي لن تجدوها الا من خلال خبراء المملكة لتركيب الاثاث كما اننانوفرها بأحدث الموديلات التي تتناسب مع احتياجات جميع عملائنا
    فأننا نحيط علمكم اذا كنت تريد تركيب اي اثاث في منزلك فلديك خبراء المملكة

    ReplyDelete
  16. This is the most important part of having air conditioning in your home. The system is supposed to monitor the temperature of your home and go on and off according to that temperature. If the temperature starts to climb to high it Ac repair mt kisco on and delivers cool, crisp air to cool things down.

    ReplyDelete
  17. Really very useful tips are provided here.thank you so much.Keep up the good works.
    Heating and Cooling mississauga

    ReplyDelete
  18. very nice post. thanks for sharing this article
    Commercial Heating Services Paramus

    ReplyDelete
  19. اسرع طرق فى التنظيف
    التنظيف من الاشياء التى لابد من ان ننظر اليها على انها من الاشياء الاساسية الهامه فى حياتنا ولا يتم الاستغناء عنها و ذلك إلى جانب اهميتها العالية فى تغير نظرته الى ما يتعامل معه باستمرارية، إذ تظهر على نفسيته الراحه والاطمئنان والسعاده بحيث يصير أكثر قدره على البذل والعطاء والعمل والإنتاج.
    شركة تنظيف شقق بالبكيرية
    شركة تنظيف فلل بالبكيرية
    شركة تنظيف منازل بالبكيرية
    شركة مكافحة حشرات بالبكيرية

    ReplyDelete
  20. What a really awesome post this is. Truly, one of the best posts I've ever witnessed to see in my whole life. Wow, just keep it up. Airco

    ReplyDelete
  21. What a really awesome post this is. Truly, one of the best posts I've ever witnessed to see in my whole life. Wow, just keep it up. Airco

    ReplyDelete
  22. What a really awesome post this is. Truly, one of the best posts I've ever witnessed to see in my whole life. Wow, just keep it up. Airco

    ReplyDelete
  23. I see some amazingly important and kept up to length of your strength searching for in your on the site Airco

    ReplyDelete
  24. Nice post! This is a very nice blog that I will definitively come back to more times this year! Thanks for informative post. Airconditioning

    ReplyDelete
  25. There is nothing like coming home from the hot weather of a summer afternoon and turning on the air conditioning unit to cool down. Luckily air conditioning machines have also come a long way in the last decade. Much advancement has made for more enjoyable conditions in homes, business offices, hospitals and countless other places. Not only that, but they can also save people money with more efficient methods that are being used for cooling. For those that love to be extra chilly, no matter what time of the year it is, here are 11 awesome improvements in air conditioning technology in the last 10 years. mitsubishi ducted air conditioning

    ReplyDelete
  26. There is nothing like coming home from the hot weather of a summer afternoon and turning on the air conditioning unit to cool down. Luckily air conditioning machines have also come a long way in the last decade. Much advancement has made for more enjoyable conditions in homes, business offices, hospitals and countless other places. Not only that, but they can also save people money with more efficient methods that are being used for cooling. For those that love to be extra chilly, no matter what time of the year it is, here are 11 awesome improvements in air conditioning technology in the last 10 years. ac maintenance dubai

    ReplyDelete
  27. Most business ac repair pharr tx , especially factories, display metal pipes or tunnels usually at the top of the building. These tunnels are the air conditioning ducts that transport air throughout the whole establishment. The first thing to remember about these air ducts is that they only work with central air units, and not with split systems.

    ReplyDelete
  28. This particular papers fabulous, and My spouse and i enjoy each of the perform that you have placed into this. I’m sure that you will be making a really useful place. I has been additionally pleased. Good perform! dirty air ducts

    ReplyDelete
  29. There is nothing like coming home from the hot weather of a summer afternoon and turning on the air conditioning unit to cool down. Luckily air conditioning machines have also come a long way in the last decade. Much advancement has made for more enjoyable conditions in homes, business offices, hospitals and countless other places. Not only that, but they can also save people money with more efficient methods that are being used for cooling. For those that love to be extra chilly, no matter what time of the year it is, here are 11 awesome improvements in air conditioning technology in the last 10 years. split system installation

    ReplyDelete