UK:LightwaveRF Integration

I've been using LightwaveRF devices integrated into ST via a Ras Pi to the Lightwave (LW) hub.
I've got it working with Hubitat Elevation.
I didn't the process but have just been a grateful recipient.
Here is the ST thread which shows you how to set it all up, followed by the DH code which I have amended to work with HE.

Dimmer.

/**
 *  Lightwave Lights
 *
 *  Copyright 2015 Adam Clark
 *  For any information or help please contact ad@mclark.co 
 *
 *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 *  in compliance with the License. You may obtain a copy of the License at:
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
 *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
 *  for the specific language governing permissions and limitations under the License.
 *
 */
 
import java.security.MessageDigest
 
preferences {
    input("serverIP", "text", title: "Server IP Address", description: "IP Address of the Server")
    input("lightwaveIP", "text", title: "Lightwave IP Address", description: "IP Address of the Lightwave Hub")
	input("roomID", "text", title: "Room ID", description: "The room id")
    input("deviceID", "text", title: "Device ID", description: "The device id")
}
 
metadata {
	definition (name: "Lightwave Dimmer Switch", namespace: "smartthings-users", author: "Adam Clark") {
		capability "Switch"
        capability "Switch Level"
        capability "Refresh"
        command "register"
	}

	simulator {}
       
    tiles(scale: 2) {
		multiAttributeTile(name:"switch", type: "lighting", width: 6, height: 4, canChangeIcon: true){
			tileAttribute ("device.switch", key: "PRIMARY_CONTROL") {
				attributeState "on", label:'${name}', action:"switch.off", icon:"st.switches.switch.on", backgroundColor:"#79b821", nextState:"off"
				attributeState "off", label:'${name}', action:"switch.on", icon:"st.switches.switch.off", backgroundColor:"#ffffff", nextState:"On"
			}
			tileAttribute ("device.level", key: "SLIDER_CONTROL") {
				attributeState "level", action:"switch level.setLevel", range:"(5..100)"
			}
		}

        standardTile("register", "device.status", inactiveLabel:false, decoration:"flat",height: 2, width: 2) {
            state "default", label:"Register", icon:"http://www.mocet.com/pic/link-icon.png", action:"register"
        }

		main "switch"
		details(["switch", "level","register"])
	}

}

// parse events into attributes
def parse(String description) {
	log.debug "Parsing '${description}'"
	// TODO: handle 'switch' attribute

}

// handle commands
def on() {
	sendEvent(name: "switch", value: 'on')
	apiGet('/on', 0)
}

def off() {
	sendEvent(name: "switch", value: 'off')
	apiGet('/off', 0)
}

def setLevel(value) {
	if (value == 0) {
		sendEvent(name: "switch", value: 'off')
		sendEvent(name: "level", value: '0')
		apiGet('/off', 0)
	} else {
		sendEvent(name: "switch", value: 'on')
		sendEvent(name: "level", value: value)
		apiGet('/on', value)
    	}
}

def register() {
	apiGet('/register', 0)
}

private apiGet(path, level) {

	log.debug settings.serverIP + ':8000'

    def httpRequest = [
        method:     'GET',
        path:       path,
        headers:    [
            HOST:       settings.serverIP + ':8000',
            Accept:     "*/*"
        ],
        query: [
        	ip: settings.lightwaveIP,
        	room: settings.roomID, 
            device: settings.deviceID,
            level: level
        ]
    ]

	log.debug httpRequest.query

    return new hubitat.device.HubAction(httpRequest)
}

Outlet.

/**
 *  Lightwave Lights
 *
 *  Copyright 2015 Adam Clark
 *  For any information or help please contact ad@mclark.co 
 *
 *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 *  in compliance with the License. You may obtain a copy of the License at:
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
 *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
 *  for the specific language governing permissions and limitations under the License.
 *
 */
 
import java.security.MessageDigest
 
preferences {
    input("serverIP", "text", title: "Server IP Address", description: "IP Address of the Server")
    input("lightwaveIP", "text", title: "Lightwave IP Address", description: "IP Address of the Lightwave Hub")
	input("roomID", "text", title: "Room ID", description: "The room id")
    input("deviceID", "text", title: "Device ID", description: "The device id")
}
 
metadata {
	definition (name: "Lightwave Switch", namespace: "smartthings-users", author: "Adam Clark") {
		capability "Switch"
        capability "Refresh"
        command "register"
	}

	simulator {}
       
    tiles(scale: 2) {
		multiAttributeTile(name:"switch", type: "outlet", width: 6, height: 4, canChangeIcon: true){
			tileAttribute ("device.switch", key: "PRIMARY_CONTROL") {
				attributeState "on", label:'${name}', action:"switch.off", icon:"st.switches.switch.on", backgroundColor:"#79b821", nextState:"off"
				attributeState "off", label:'${name}', action:"switch.on", icon:"st.switches.switch.off", backgroundColor:"#ffffff", nextState:"On"
			}
			tileAttribute ("device.level", key: "SLIDER_CONTROL") {
				attributeState "level", action:"switch level.setLevel", range:"(100)"
			}
		}

        standardTile("register", "device.status", inactiveLabel:false, decoration:"flat",height: 2, width: 2) {
            state "default", label:"Register", icon:"http://www.mocet.com/pic/link-icon.png", action:"register"
        }

		main "switch"
		details(["switch","register"])
	}

}

// parse events into attributes
def parse(String description) {
	log.debug "Parsing '${description}'"
	// TODO: handle 'switch' attribute

}

// handle commands
def on() {
	sendEvent(name: "switch", value: 'on')
	apiGet('/on', 0)
}

def off() {
	sendEvent(name: "switch", value: 'off')
	apiGet('/off', 0)
}

def setLevel(value) {
	if (value == 0) {
		sendEvent(name: "switch", value: 'off')
		sendEvent(name: "level", value: '0')
		apiGet('/off', 0)
	} else {
		sendEvent(name: "switch", value: 'on')
		sendEvent(name: "level", value: value)
		apiGet('/on', value)
    	}
}

def register() {
	apiGet('/register', 0)
}

private apiGet(path, level) {

	log.debug settings.serverIP + ':8000'

    def httpRequest = [
        method:     'GET',
        path:       path,
        headers:    [
            HOST:       settings.serverIP + ':8000',
            Accept:     "*/*"
        ],
        query: [
        	ip: settings.lightwaveIP,
        	room: settings.roomID, 
            device: settings.deviceID,
            level: level
        ]
    ]

	log.debug httpRequest.query

    return new hubitat.device.HubAction(httpRequest)
}
2 Likes

Thank you for the contribution. Could I ask you a quick favor? Please edit your post, select all of the source code you pasted into the window, and then click the Pre-Formatted Text menu button that looks like < / >. This will make it much easier for others to copy and paste your code.

Thanks for letting me know how to do that. Never been told that before.

1 Like

Giving that it is based on a 2015 piece of code, I suspect this only works with Gen1 and not Gen2. Can you confirm?

I only have gen 1.

Hi, I was also thinking of buying some new lightwave sockets but it looks there most recent electric sockets are on a different RF than the originals so not sure this will work.

Failing that does anybody know any other good brands of electric sockets that work well with HE in the UK?

This might be a dumb question but first day with Hubitat. I have installed the drivers code but not sure of next step. I can create a virtual device with the lightwaverf dimmer properties and enter the room ID, device ID etc but unsure what is mean by Server IP address, is this the Hubitat hub ip address? Tried that but not sure what next step is to getting Hubitat to discover the lightwaverf device. Any help would be great, I appreciate the original post was quite some time ago.

1 Like

The server IP address (for me) is my RPi.
image

This is the my LWRF hub.
image

I have given both static/fixed/reserved (people use different descriptions) addresses otherwise if the addresses change then the lights/switches will not be turned on/off.

I'm so sorry to ask this but what is the next step or am i getting lost?
i have copped the text for the dimmer, pasted it to the new driver tab, saved it.
gone to devices, added virtual device, clicked lightwaverf, put my router as the server IP, lightwaves hub as its ip, room ID 1 for the first room on the LW drop down and device ID 5 (as its the 5th in the drop down), the clicked save preferences.

then pressing on and off does nothing. any help will be appreciated, thanks.

The first thing I would do is log on to your RPi and open a command window.
In the screenshot below you can see how you can monitor the commands going from the HE hub through the RPi to the LW hub.
I stopped the service, then turned the device on and off in the device in the HE hub.
You should see the commands in the command line on your RPi.
When done, start the lwrf service again.
This should tell you if things are working OK.
If you are seeing the commands then I would suggest you have put in the wrong room and device ID.
image

so step one get a Raspberry Pi, how do i connect the RPI to the Lw hub?
I found this article but not sure if this is going too deep?
https://www.raspberrypi.org/forums/viewtopic.php?t=96926
I think once i finally get this sorted i might make a youtube video(with your consent) of it as its a bit more complicated then i thought.
Again thanks for the help.

I followed the SmartThings forum post that I have put a link to in post 1. I did have it working without a RPi but then you will be using cloud to cloud from HE to LWRF and back again.
I wanted local so did it using a Pi.
It is a long post and it was about 3 years ago when I set this up on ST. I just ported it across when I moved to HE.

I'm not that technical but can follow instructions and I did get there in the end with setting up the Pi.

1 Like

Have a look at post 8 in the ST link above. That should get you going cloud to cloud I think.
Use the drivers I posted above though.
EDIT: This is probably the video to follow but please bear in mind that these instructions are for cloud to cloud on SMARTTHINGS.
Convert the steps to HE and see how you go.
I haven't listened to all of this video but I think it's the one you want. (Hopefully).

1 Like

Ok i have done that but think where it goes wrong for me is the server IP address. Also am i supposed to do anything with the register and refresh buttons?

Does the video tell you what the server IP address should be.
I honestly cannot remember the set up for a non rpi.
I would have thought that would be your router gateway but I'm really not sure.

Did you use my code above?
This code is if you are using an RPi or something similar.
Are you trying to do it cloud to cloud?

yeah cloud to cloud thats why it isn't working

OK. You will need to port over the code that Adam is using in his video for cloud connectivity.
This needs your login ad password for your LWRF app. (I think).
I can have a look later if you wish but I'm busy at the mo.
Probably an hour or so. Sorry.
Basically though all you need to do is get Adam's driver code for SmartThings.
Copy it in and then change everything that says 'physicalgraph' to 'hubitat'.
Hopefully that is all that is needed.

nice ill give that a go now


yeah its still not worked and i have no idea why not. copied and pasted the password and username exactly to insure no spelling mistakes and still no light.

btw the word physiography wasn't present in the code from adam clark.

Download the Hubitat app