I’ve written before about Vera and Fibaro. I’ve moved from the Vera system to Fibaro Home Center 2. One of the features missing is the ability to control LightwaveRF devices.

I’ve now figured out how to do this with just the addition of a LightwaveRF Wifi Link.

Here’s how.

Configure LightwaveRF Link and Add Devices

The first thing you need to do is install your LightwaveRF Wifi Link box and make a note of its IP. You can get this from the LCD menu options on the box itself.

Once installed you need to use the Android/iOS app to add all of your devices.

Add Global Variables to HC2

To make life a little easier I added two Global Variables via the Variables Panel.

The first is called “LWRF_IP” and contains the IP address of the WiFi Link box.
The second is ‘LWRF_Port’ and should be set to 9760.

It might make sense for you to add a DHCP reservation in your router so that the IP doesn’t change.

Create Your Virtual Device

You’ll need to figure out the Room Number and Device Number for each LightwaveRF device you want to control.

The first room listed in your app is Room Number 1, the second is Room Number 2, and so on.
It works the same way for devices; the first device in a room is Device Number 1, etc.

Add a pair of buttons to the Virtual Device and label them “On” and “Off”.
Here’s the LUA code to paste in for the “On” button:

local _selfId = fibaro:getSelfId()

-- *******************************************
-- ** edit below variables for each button **
-- *******************************************
local room_num = 1
local device_num =  1
local commandName = 'On' -- Freeform text, to show on LWRF LCD
local commandNumber = 1 -- 1 for On, 0 for Off

-- ********************************************
-- ** code below shouldn't need to be edited **
-- ********************************************

--get name of virtual device to show on LWRF LCD
local device_name =  fibaro:getName(_selfId)

--load global variables for LWRF Link box
local LWRF_IP = fibaro:getGlobalValue("LWRF_IP")
local LWRF_Port = fibaro:getGlobalValue("LWRF_Port")

--build string to send to LWRF
local command = '001,!R' .. room_num .. 'D' .. device_num .. 'F' .. commandNumber .. '|'.. device_name .. '|' .. commandName

-- send the command
socket = Net.FUdpSocket() 
bytes, errorCode = socket:write(command, LWRF_IP, LWRF_Port)

I’m lazy, so I cheat and put the Device Number in the “TCP Port” for the Virtual device and the Room Number in the “IP Address” field. This makes it easier to duplicate the device. If you take this route too then you can change

local room_num = 1
local device_num = 1


local room_num = fibaro:get(_selfId, "IPAddress")
local device_num = fibaro:get(_selfId, "TCPPort")

The code for the off button is exactly the same, but you change the commandName to ‘Off’ and the commandNumber to ‘0’.

Dimming Controls

Dimming isn’t too difficult to accomplish. First add a slider to your Virtual Device.
The slider reports values from 0 to 100, but LightwaveRF uses values from 0 to 32.

So we use the same code as the On/Off buttons but add a line at the top to get the dim level selected from the slider:

local LWRF_DimLevel = math.floor((_sliderValue_ / 100) * 32)

We then change this line:

--build string to send to LWRF
local command = '001,!R' .. room_num .. 'D' .. device_num .. 'F' .. commandNumber .. '|'.. device_name .. '|' .. commandName

to send the dimming command:

--build string to send to LWRF
local command = '001,!R' .. room_num .. 'D' .. device_num .. 'FdP' .. LWRF_DimLevel.. '|'.. device_name .. '|' .. commandName


You can now control the device from HC2. When you send your very first command from the HC2, the LightwaveRF Wifi Link box should prompt you to confirm the ‘registration’ of the controlling device. You’ll only need to do this once.

Simply create more Virtual Devices to control further LightwaveRF devices, remembering to change the Room Number and Device Number for each one,

Have fun