giovedì 23 novembre 2017

Control your air conditioner with a Telegram bot

I have a Mitsubishi SRK 258 CENF-R air conditioner with its RKS502A502A remote control.
I can not set a timer to switch it on and/or off at a specific time but I can just switch the air conditioner on and then to switch it off after n hours or I can set the switching on into n hours but I can only to switch it off later manually, always with the remote control.
So I looked for a solution to this problem.

I bought the USB IR Toy v2 by Dangerous Prototypes, a nice device that is able to receive and to send IR signals using a USB port.
I searched on the internet the way to use it at his best but, as usual, I found standard procedures that work for everyone but not for me.
For example I tried to follow the instructions described here to use IRToy with Lirc but the command:
irrecord -n -H irman -d /dev/ttyACM0 RemoteXXX.conf
did not work. Maybe it's my fault and I did something wrong, but at last it did not work for me.
One of the possible causes is that, like usually the air conditioners' remote controls of do, the RKS502A502A remote control does not send a train of pulses and spaces while the button is pushed, but when a button is pushed, it sends a limited-duration (more or less 180 ms) sequence of pulses and spaces.
In this sequence is every time reported the whole configuration of the air conditioner: working mode, fan speed, temperature, etc. etc.
So irrecord does not receive the signal for a time long enough to learn it.

Thanks to the IRToy software that you can download here, and particularly to its Perl scripts, I could read the signal transmitted by my remote control and I was also able to graphically show it using one of those scripts.

Signal analysis


Let's analyze in detail the signal generated by the Mitsubishi RKS502A502A remote control to switch on the air conditioner by pressing the ON button with all the other default parameters (FAN SPEED=AUTO, MODE=AUTO, AIR FLOW=AUTO, TEMP=0)

Here we don't use the timer settings because our purpose is to switch on and off the air conditioner with an external tool. By the way the complete signal description including timer management will be soon provided here.
The RKS502A502A uses a slight variation of the NEC protocol that you find described in the network (e.g. here).

It's transmitted with a carrier frequency of 38 kHz (26.3 μs wavelength). Somewhere it's written that it best behaves with a carrier frequency os 38220 Hz.
In my tests I noticed no different behaviour. Maybe with some professional test equipment someone could note some differences.

The logical bits are transmitted as follows:
'0' → a burst having a duration of 490 μs followed by a space of 1450 μs
'1' → a burst having a duration of 490 μs followed by a space of 3455 μs

The following sequence is transmitted:
  • an initial pulse of about 6 ms
  • a space of about 7.5 ms
  • 8 bits of data
  • 8 bits that are the logical inverse of the previous 8
  • 8 bits of data
  • 8 bits that are the logical inverse of the previous 8
  • the 8-bit fixed sequence "01010100"
  • 8 bits that are the logical inverse of the previous 8 ("10101011")
  • a final pulse of about 7.5 ms indicating the end of the signal

When bytes are transmitted, the least significant bit is sent first.

In the following picture we see how the signal detected on IRToy's IRRX pin appears in xoscope:




In absence of signal the output on the IRRX pin is 1 (carrier signal missing). When a pulse is detected, the logic value on IRRX is 0 (carrier signal present).

Using acbot with IrToy

You can use IrToy both with a PC and Raspberry Pi to send the infrared signal to your air conditioner (or another device, if you like).
You just need a USB port and the PyIrToy Python module by Chris LeBlanc. Install it or just download the file irtoy.py and save it into the same directory where you saved ACBot. Then set the correct values in acbot.conf file.
In [host] section set the type key to the value pc or raspberry according where the Telegram bot is running on. Example:
[host]
type = raspberry
or
[host]
type = pc

Then in the irtoy section set the serial port to which IrToy is connected to. Example:
[irtoy]
port = /dev/ttyACM0

You must have a your own json file where you saved the encoded signal of your own remote control. Save it in the ./codes directory and assign the name of the file to the codes_file key in the [signal] section of acbot.conf configuration file. Example:
[signal]
codes_file=RKS502A502A.json

Here in the following picture you can see the IrToy connected to a USB port.


Using acbot with Raspberry Pi's GPIO

Coming soon ...

Using acbot with Lirc

Coming soon ...

mercoledì 22 novembre 2017

How to send signals

Now let's see hot to send the decoded signal.

Using Python I wrote a Telegram bot  (ACBot) to send commands to my air conditioner also from remote with different devices.
using a PC, a Raspberry Pi or Arietta G25 (another Linux embedded ARM device).

The bot can run on a PC or on a Raspberry Pi or on Arietta and you can use it in the following ways:
    • an IrToy v2 connected to a PC USB port
    • an IrToy v2 connected to a Raspberry Pi USB port
    • a simple infrared LED connected to a GPIO of a Raspberry Pi (it needs pigpio library or Lirc)
    • a simple infrared LED connected to a pin of Arietta G25 (it needs Lirc)

     

    How to use ACBot

    My ACBot project is easy to use. It's enough to clone it or to copy the *.py files and the configuration file into a directory
    Then you must create your own bot through BotFather. Write the assigned token in the token_string key in the [common] section of acbot.conf configuration file.
    Be careful to correctly set the other sections in acbot.conf and to have the needed dependency modules: nothing difficult.
    Then run:

    python acbot.py

    The managed commands in ACBot are: /start, /menu, /stop, with obvious meanings.
    Typing /start in the bot a custom keyboard will appear:


    You can switch ON, OFF or selecting SETTINGS you can set the other parameter of the air conditioner (i.e. FAN SPEED, COOL, TEMP etc.).

    In evidence

    Control your air conditioner with a Telegram bot

    I have a Mitsubishi SRK 258 CENF-R air conditioner with its RKS502A502A remote control. I can not set a timer to switch it on and/or off a...

    Most popular