Integrating and Controlling Lightwave RF with Demopad

LightwaveRF Communi… > Blog > Integrating and…

In this guide I’ll be explaining how to integrate Lightwave’s following products with Demopad:

  • WiFi Link
  • Dimmer Switch
  • Power Socket
  • Radiator Valve (the old type)
  • Inline Relay (500w 2 x load version)
  • EcoMeter

Overview of Steps involved:

  1. Configure Lightwave Wi-Fi Link as normal
  2. Pair Lightwave products with desired iOS or Android device using official Lightwave app
  3. Create and configure a new device in Demopad
  4. Add commands to the device
  5. Configure 2-way feedback
  6. Assign actions to buttons
  7. Display data from 2-way feedback
  8. Step 8: Test and troubleshoot!

Lightwave Protocol

Now you probably already know the Lightwave basic command protocol, but just to cover everything, I’ll explain this briefly first. Below is an extract from the API you can source from Lightwave directly…

“Example command structure: !R1D16F1<cr> is Room1 Device 16 Function ON.
<start character>R<RoomNo>D<DeviceNo>F<FunctionType>P<Parameter><cr>
<Start Character>= ! (Send command) or
                   ? (Query command) or
                   @ (systems parameter)
<RoomNo>= Lightwave Room valid 1 -> 16 in ascii.
<DeviceNo> = Device No within room 1->16 in ascii (Optional).
<Function type> is single lower cased Ascii letter Commands
0- 1- >- <- a- c- d- e- f- g- h- i- k- l- m- n- s- r- q- t- u- x-
Off (That’s a zero) On (that’s a One) Dim Up Dim Down 
<Parameter>is an optional Maximum 4 digit Integer value / 16-character text.
Examples : P16 or P1234
<cr> carriage return IMPORTANT!”

The full command package sent is :
<transaction number>,<Command><cr>
For example :
will turn on device 1 in room 1

Step 1: Configure Lightwave Wi-Fi Link

As you’d expect you need to setup your Wi-Fi link before Demopad will be able to communicate with it.

You should follow the Lightwave instructions to assign it a static IP address, or alternatively, if your router permits it, you can tell your router the IP to assign to the Wi-Fi link via its MAC address. The process for this depends on the router you have, so I won’t go into any more detail here, however if you’d like to use this method and require assistance, feel free to ask.

Step 2: Pair Lightwave devices

Prior to me attempting this, I read somewhere about the requirement to tell the WiFi link to allow the device you’re sending commands from, to connect to it. I assumed that if I set up my Lightwave switches and so on, via the official Lightwave app on my iPad, it would do all this for me …and it worked, so I guess I was right?

So, go ahead and pair your various devices to your iOS device as per the Lightwave instructions using their official app.

Now is probably a good time to create a table/spread sheet containing which Room or Device number you’re assigning to a device, i.e. Room 1, Device 1 for me is the Living Room – Pendant lights.

You’ll need all this information for step 4: adding commands (view “mycommandlist.xlsx” for more commands I’ve used).

Step 3: Create and configure a new device in Demopad

Create a new device in Demopad with the settings below, (replacing the IP address with your own of course). Note the command suffix is \x0D (this is the carriage return they say is required at the end of each command).

Lightwave’s Wi-Fi link receives signals via UDP on port 9760 and it is meant to send out a response via port 9761, however Demopad doesn’t seem to agree with the latter…more on that later.

Step 4: Add commands to the device

Add your various commands as you would normally, using the structure as below (below is an example of a command to turn on my pendant lights in the living room)-

Below is an example of a command to turn on my ceiling light in the living room to 50%? (level 16/32 – I’ll go into dimming controls in more detail later)-

Step 5: Configure 2-way feedback

One of the more interesting commands is to query the EcoMeter- @?W|EcoQuery

Which returns a similar command to – ?W=290,2930,5610,14730;?V=2.20; (Readings in watts, current, maximum today, total today, total yesterday and software version number, 2.20)

The current version of Demopad doesn’t allow “maths” to be carried out on data so at the moment we can only display the data as it is returned above, i.e. 290 opposed to 0.29kW (unless someone can think of something I’ve overlooked? If so, please let me know).

So, first off we will need a few labels created. From the project settings tab, create some project labels as below:


Default Value










Now let’s configure the Lightwave device’s 2-way feedback. Make sure the response terminator is \x0D and maintain active connection, is (surprisingly) NOT ticked.

In order to extract the individual sections of data and store them in separate labels, we need to use a bit of RegEx. I’m by no means an expert in RegEx but I’ve managed to figure out the required format to extract each reading, except for the “total yesterday” (if anyone can figure this out I’d be most grateful!). Below you can see the different RegEx commands used:

W=(.*?),                       returns the current kW
W=.*?,(.*?),                   returns the kW used in the last 24hrs
W=.*?,.*?,(.*?),               returns the kW used today
W=.*?,.*?,.*?,(.*?);           should return the kW used yesterday (but doesn’t work! HELP!)

Basically Demopad stores the data captured within the brackets. For more info regarding RegEx it’s worth looking at the two links below:

Below is a screen shot of what my device’s 2-way feedback looks like-

As you can see, I have used the label for the current kW called “EcoCurKw” which stores the relevant data captured from the RegEx, similarly for the other actions, I’ve used the other labels we created earlier.

So at this stage we’ve created our device, with commands and 2-way feedback passing data into the relevant labels, now we need to assign actions to buttons and also assign the EcoMeter query command as a repeating Page Load action.

I mentioned earlier that responses are sent from the Wi-Fi link via port 9761, however Demopad doesn’t seem to respond well to my attempts at retrieving data via this port. Instead the configuration I have used above seems to work most successfully combined with the Page Load action you’ll see in the next step. Essentially, the Wi-Fi link seems to send response data out via port 9760 when you blast it with query commands at particular repetition.

I’ve run this by Demopad, however we’ve not had any improvements with this as of yet. Please test different settings and let me know if you can improve on the above.

Step 6: Assign actions to buttons and create dynamic labels

Pretty simple step really, create relevant buttons and assign the desired commands to them as you would any other button/device.

The main thing with this step is to note that whatever page you wish to display the EcoMeter results on, you should create a Page Load action to send the EcoMeter Query command every 0.25s? (From testing this is the best setup I’ve found for successful data retrieval at present).

The EcoMeter is by far the most “buggy” part of my Lightwave setup in Demopad, as it sometimes requires a physical “refresh” button to be pressed, which sends a single EcoMeter query command upon each press. Sometimes I find I have to press this multiple times in fairly quick succession to achieve a data update. I will be continuing to try and improve this working with Demopad support in the future.

Step 7: Display data from 2-way feedback

To display the captured EcoMeter data, create a piece of text and assign it the dynamic label you require (the ones we created in step 5), see below-

Note, that the text field will display the text “loading…” until the label EcoCurrKw actually contains the data retrieved from the EcoMeter, as we set the default data to “loading…” earlier on.

Step 8: Test and troubleshoot!

At this stage you should be ready to upload the project and give it a whirl.

So the above has covered the basics of how to get it all working and below I’ll go into more detail on integrating the various products Lightwave sell with things like slider controls etc. 

The Dimmer Switch:

The dimmer switch can be sent a simple On or Off, however being a dimmer, you can of course send various dimmer levels.

Lightwave’s API documentation states that the dimmer values can range between 0 (being Off) and 32 (being On).

The Lightwave command to send a particular dimmer level is below-


This will make the lights illuminate at a level of 50% (as it’s 16/32) whereas !R1D1FdP8 would be 25% and !R1D1FdP24 would be 75%. It is completely up to you how many levels of dimming you use. It’s mainly down to how many actions you can be bothered to assign to a number variable.

You can of course create buttons and assign them the commands above, or alternatively you could use sliders.

Sliders work with Number variables, so first off we’ll need to create a variable, I have called mine- “PendantDim” with a min value of 0, a max value of 32 and a default value of 0.

You then need to create the relevant commands that the various number values are going to send to the Wi-Fi link, i.e.  024,!R1D1FdP16

Now you can assign “Custom Actions” to your project number. So, select the number and click on custom actions. Now set the min and max range relevant to the command you wish to send and click Add, then double click from the table to set an action.

In this example I’m only going to refer to five commands: Off, 25%, 50%, 75% and ON:



Custom action



Send a command – lightwaverf – Off (F0)



Send a command – lightwaverf – 25% (FdP8)



Send a command – lightwaverf – 50% (FdP16)



Send a command – lightwaverf – 75% (FdP24)



Send a command – lightwaverf – On (F1)

Now you need to create a slider as normal and in the Gauge section of the ribbon, assign it the relevant number you’re working with (i.e. “PendantDim”). When you use the slider, this will make the Number variable’s value change between 0-32 (depending on how far you move the slider within its range), which in turn will cause a command to be sent to the Wi-Fi link, dependant on the min and max values you’ve set out as per above.

The Power Socket:

Not really much to say about these other than each socket is a separately paired device (even the dual gang ones) and you can only send a simple On or Off.

The Radiator Valve (well, the old type at least…):

Although I’ve not really fully tested this, the official Lightwave app, allows you to pair with an older style TRV and will allow you to simply turn it On or Off, which from my brief testing, actually changes the temperature on the TRV to 21degC or 5degC respectively. As this was the only functionality it gave me, I didn’t actually bother trying it with Demopad, however from the API and various bits and pieces I’ve come across, I believe the below command would work-

!R1D1dhF0 = Off/5degC                   and                  !R1D1dhF1 = On/21degC

The Inline Relay (500w 2 x load version):

I have used the inline relay to control my electric projector screen. My screen has a RF remote and a hard wired control box with 3 buttons, UP/ STOP / DOWN. The relay obviously only has 2 load outputs and a disconnect both option. I use the load outputs for the up and down buttons and leave the stop button out of the equation.

I may be lucky in that my screen doesn’t necessarily require the use of the stop button, my screen will allow you to press the DOWN button and then press the UP button to stop the screen in its tracks. However in order to then lower the screen further, I’d then have to press the DOWN button twice. It’s a bit hard to explain, however as we progress through this I’m sure it will become clearer.

Basically I’ve soldered 4 wires onto the back of the control box’s PCB, at opposite corners of the UP and DOWN buttons and connected these to the relay’s Load 1, COM and Load 2. On the pictures below the Red and Black are for UP and the Yellow and Blue are for DOWN.

The live and neutral for the relay have been taken from a separate plug.

To get this working in Demopad, I did a similar thing as with the other devices and paired the Relay with the official lightwave app first. You need to choose the OPEN/CLOSE option when your selecting the device type. As before, note down the Room and Device number on your command list. For the purpose of this guide, mine is Room 2, Device 2.

From Lightwave’s API the function for :
OPEN is                   F(
STOP is                                     F^
CLOSE is                   F)

The above is interesting, because if you’ve got yourself a copy of the official API from lightwave, the brackets are documented as being the other way around…however (unless I’m mistaken), they’re wrong!

The complete signal for my DOWN command is 027,!R2D2F(

I use a “cinema mode” button to dim my lights, turn on my projector and lower the screen etc all in one press, so in my setup, I send the DOWN command (which is OPEN on the relay) then 4 seconds later I send the STOP command, disconnecting or essentially “taking your finger off” the down button and the once the screen is at the desired height I send the UP command (CLOSE on the relay) followed again by STOP another few seconds later.

Then once the movie is over and I want to turn off cinema mode, I issue UP (CLOSE on the relay) followed by STOP a few seconds later and then after a long enough time period for the screen to be completely raised I issue the DOWN command once again followed by STOP. This will leave the screen in a “ready to go down” state for the next movie.

The EcoMeter:

As explained in step 5 above, this is a bit buggy but you can retrieve data back through port 9760 when you blast the query command to the Wi-Fi at particular repetition. Hopefully in due course this will become more stable and once Demopad release an update including the ability to undertake maths on the number variables we should be able to display the results in a more sensible format.


Obviously as we know, at present Lightwave’s products aren’t 2-way, in that we can’t query them to determine what state a power socket or dimmer switch is in. This doesn’t unfortunately mean, that with things like sliders, if you were to use the manually dimmer switch on the wall, the slider won’t update/reflect the change. Hopefully Lightwave might enhance this possibility in the future, but only time will tell.

That’s all I’ve tackled with Lightwave so far, but I hope it will be of use to you and please feel free to contact me if you have any issues.


  • I’m not sure which variant of regular expressions DemoPad uses, however the following seems to do the trick in Ruby (see

    W=(\d+), returns the current kW
    W=\d+,(\d+), returns the kW used in the last
    W=\d+,\d+,(\d+), returns the kW used today
    W=\d+,\d+,\d+,(\d+)\; should return the kW used yesterday

    The \d+ should match a sequence of at least one digit and the \; should match the semi-colon at the end.

    • Hi Ian,

      OK, just tested this…you’re suggestions all worked except for the last one.
      I changed:
      which worked spot on :)

      Thanks for your pointer with the ruby link, the quick reference section at the bottom was ideal for sorting the above!

  • Thanks Ian, I’ll give this a go when I get home (won’t be until Wednesday as I’m working away atm).

    Do you know of a way to apply maths to data reteived by regex? I.E. to turn the returned data of 290 into 0.29 and so on?

  • HA-beginner says:

    I tried obtaining the first three characters using the LCD display when controlling from the lightwaveRF app

    The first three characters 024 (shown above) were in the 300′s, they also changed even when the command was for say 50% it would be 308,!R1D1FdP16 then for 50% again it would go to 310, the codes do not seem to be working in my demopad app. However, I have not configured any two-way feedback. Do I need to?