This binding supports sending infrared (IR) and radio frequency (RF) commands using a range of devices for made by (and occasionally OEM licensed from) [Broadlink](https://www.ibroadlink.com/).
The highlevel overview is:
1. learn codes from your existing IR (and RF) remote controls, associating each of them with a command that you choose such as `AC_OFF`;
2. making openHAB rules that send the command e.g. `AC_OFF` to the device;
3. the binding will look up the learned code associated with your command and then send it.
| sp2 | Broadlink SP2 WiFi Smart Socket with night light |
| sp2-s | OEM SP2 Mini WiFi Smart Socket with night light |
| sp3 | Broadlink SP3/Mini WiFi Smart Socket with night light |
| sp3-s | Broadlink SP3s WiFi Smart Socket with Power Meter |
| rm-pro | Broadline RM Pro WiFi IR/RF Transmitter with temperature sensor |
| rm3 | Broadlink RM3/Mini WiFi IR Transmitter |
| rm3-q | Broadlink RM3 WiFi IR Transmitter with Firmware v44057 |
| rm4-pro | Broadlink RM4 Pro WiFi RF/IR Transmitter with temperature and humidity sensors|
| rm4-mini | Broadlink RM4 mini WiFi IR Transmitter |
## Discovery
Devices in the above list that are set up and working in the Broadlink mobile app should be discoverable by initiating a discovery from the openHAB UI.
> The `Lock Device` setting must be switched off for your device via the Broadlink app to be discoverable in openHAB.
1. Set the *Name of IR/RF command to learn* property to the command you want the device to learn. This can be any text that you want, but you will use it in your rules to send commands, so for example 'AC_OFF' or 'TV_VOLUME_UP' would be good commands.
3. For IR find the *Remote Learning Control* channel and create an Item for it, for RF use the *Remote RF Learning Control* channel instead. (Only needed the first time)
10. If no success, the channel will be named "NULL". Look in the logs on your openHAB server for any issues - try under the Developer Tools section of Main UI.
11. Check and save the IR/RF command by clicking the item once more and select "Check and save command"
13. If successfull, the channel will change name to the command saved
14. If no success, the channel be named "NULL", restart from step 3.
### Sending Remote Codes
In a rule, send your command to a String-type Item linked to the command (IR) or rf-command (RF) channel of your device. The binding will look up the learned IR or RF remote code you associated with that command and send it.
The binding is also capable of modifying a previously stored code, and to delete a previously stored code.
To modify a previously stored code, the procedure is the same as the one shown above, except that in step 4, the option to choose is *Modify IR command* or *Modify RF Command*
*Please note that the "Learn command" will not modify a previously existent code, and the "Modify" command will not create a new command.
This is done to avoid accidentally overwriting commands*
In order to delete a previously stored code, the procedure is as follows:
0. In the openHAB web UI, navigate to your RMx Thing
1. Set the *Name of IR/RF command to learn* property to the name of the command you want the device to learn
2. Click on its *Channels* tab
3. For IR find the *Remote Learning Control* channel and create an Item for it, for RF use the *Remote RF Learning Control* channel instead (Only needed the first time).
4. Click the item, and click the rectangular area that is marked NULL
5. In the pop-up menu that appears, select *Delete IR command* for IR or *Delete RF command* for RF
*VERY IMPORTANT NOTE: As of openHAB version 4.3.0, writing the codes into the files is handled by openHAB. While it is possible to create a file externally, copy it in the proper location and use it as a remote codes database (As it is done in the case of Remote codes file migration) IT IS STRONGLY DISCOURAGED to modify the file while the binding is acive. Please make sure the binding is stopped before you modify a remote codes file manually. Also, have the following things in mind:*
*-openHAB does not interpret a missing code file as empty. It will assume the file is corrupt and try to read from one of the backups, which can lead to confusion. if you want to empty your code file, create an empty file with a set of culry brackets, one per line*
*-Remember if you manipulate the code file manually, remember to provide the proper location, and the proper ownership and permissions (Location is `$OPENHAB_USERDATA`, and permissions are `-rw-r--r-- 1 openhab openhab*
Before openHAB version 4.3.0, the file used the [Java Properties File format](https://en.wikipedia.org/wiki/.properties) and was stored in the `<OPENHAB_CONF>/transform` folder.
By default, the file name was `broadlink.map` for the IR codes, but could be changed using the `mapFile` setting.
In similar fashion, the RM pro models stored the RF codes in the `broadlinkrf.map` file.
Here is a map file example of the previous file format:
Since openHAB version 4.3.0, codes are stored stored in the $OPENHAB_USERDATA/jsondb directory. IR codes are stored in `$OPENHAB_USERDATA/jsondb/broadlink_ir.json`. For the RM Pro series of devices the RF codes are stored in `$OPENHAB_USERDATA/jsondb/broadlink_rf.json`
The advantage of this change is that the files are now backed up by openHAB, which is more practical for migrations, data robustness, etc. Having the storage of the codes handled by openHAB also provides uniformity with other openHAB configuration through Main UI.
With the change of the storage mechanism, the files are also changing format, and codes are now stored in json, like this: