Everspring HSP02

I bought three of these and they would not work out of the box I found code on the net to add as an app but can this not be used to add directly ST and what is the process to do that ?

I am new to ST but not new to automation. There was also code for the Aeon Smartstrip that I want to use later to control my UPS’s on my VMWare lab and NAS to power them off and on remotely

I did not write the code this is where I found it and he should get the credit. https://github.com/jialong/smartthings

/**
 *  Everspring HSP02 Motion Sensor
 */
metadata {
	simulator {
		// messages the device returns in response to commands it receives
		status "motion (basic)"     : "command: 2001, payload: FF"
		status "no motion (basic)"  : "command: 2001, payload: 00"
		status "motion (binary)"    : "command: 3003, payload: FF"
		status "no motion (binary)" : "command: 3003, payload: 00"

		for (int i = 0; i <= 100; i += 20) {
			status "battery ${i}%": new physicalgraph.zwave.Zwave().batteryV1.batteryReport(
				batteryLevel: i).incomingMessage()
		}
	}

	tiles {
		standardTile("motion", "device.motion", width: 2, height: 2) {
			state "active", label:'motion', icon:"st.motion.motion.active", backgroundColor:"#53a7c0"
			state "inactive", label:'no motion', icon:"st.motion.motion.inactive", backgroundColor:"#ffffff"
		}
		valueTile("battery", "device.battery", inactiveLabel: false, decoration: "flat") {
			state "battery", label:'${currentValue}% battery', unit:""
		}
		standardTile("configure", "device.configure", inactiveLabel: false, decoration: "flat") {
			state "configure", label:'', action:"configuration.configure", icon:"st.secondary.configure"
		}

		main(["motion"])
		details(["motion", "battery", "configure"])
	}
}

// Parse incoming device messages to generate events
def parse(String description)
{
	// 0x30 0x86 0x72 0x85 0x71 0x84 0x80 0x70 0x20
    // 0x30 sensor binary
    // 0x86 version
    // 0x72 manuf
    // 0x85 association
    // 0x71 alarm
    // 0x84 wake up
    // 0x80 battery
    // 0x70 configuration
    // 0x20 basic
	def result = []
	def cmd = zwave.parse(description, [0x80: 1, 0x30: 1, 0x84: 2, 0x70:1, 0x20:1, 0x85:2])
	if (cmd) {
		// if( cmd.CMD == "8407" ) { result << new physicalgraph.device.HubAction(zwave.wakeUpV2.wakeUpNoMoreInformation().format()) }
        if ( cmd.CMD == "8407" ) {
        	result = zwaveEvent(cmd)
        }
        else {
			result << createEvent(zwaveEvent(cmd))
        }
	}
	log.debug "Parse returned ${result}"
	return result
}

// Event Generation
def zwaveEvent(physicalgraph.zwave.commands.wakeupv2.WakeUpNotification cmd)
{
	def map = [:]
    map.descriptionText = "${device.displayName} woke up"
    map.isStateChange = false
    
    def results = [createEvent(map)]
    results << response(zwave.batteryV1.batteryGet())
    results << response("delay 1200")
    results << response(zwave.wakeUpV2.wakeUpNoMoreInformation())
    
    results
}

def zwaveEvent(physicalgraph.zwave.commands.batteryv1.BatteryReport cmd) {
	def map = [:]
	map.name = "battery"
	map.value = cmd.batteryLevel > 0 ? cmd.batteryLevel.toString() : 1
	map.unit = "%"
	map.displayed = false
    
	map
}

def zwaveEvent(physicalgraph.zwave.commands.sensorbinaryv1.SensorBinaryReport cmd) {
	def map = [:]
	map.value = cmd.sensorValue ? "active" : "inactive"
	map.name = "motion"
	if (map.value == "active") {
		map.descriptionText = "$device.displayName detected motion"
	}
	else {
		map.descriptionText = "$device.displayName motion has stopped"
	}
	map
}

def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicSet cmd) {
	def map = [:]
	map.value = cmd.value ? "active" : "inactive"
	map.name = "motion"
	if (map.value == "active") {
		map.descriptionText = "$device.displayName detected motion"
	}
	else {
		map.descriptionText = "$device.displayName motion has stopped"
	}
	map
}

def zwaveEvent(physicalgraph.zwave.commands.configurationv1.ConfigurationReport cmd) {
	log.debug("Configuration report: Parameter number ${cmd.parameterNumber}, Configuration Value: ${cmd.configurationValue}")
}

def zwaveEvent(physicalgraph.zwave.Command cmd) {
	log.debug "Catchall reached for cmd: ${cmd.toString()}}"
	[:]
}

def configure() {
	log.debug "Configuring device..."
    
    def cmds = []
    
    // sensitivity
    cmds << zwave.configurationV1.configurationSet(parameterNumber: 3, configurationValue: [8]).format()
    // re-trigger interval
    cmds << zwave.configurationV1.configurationSet(parameterNumber: 4, size: 1, scaledConfigurationValue: 120).format()
    // on-off duration
    cmds << zwave.configurationV1.configurationSet(parameterNumber: 6, size: 1, scaledConfigurationValue: 120).format()
    
	delayBetween(
    	cmds,
        1000
	)
}

def test() {
	def cmds = []
    cmds << zwave.configurationV1.configurationGet(parameterNumber: 6).format()
    cmds << zwave.configurationV1.configurationGet(parameterNumber: 3).format()
    cmds << zwave.configurationV1.configurationGet(parameterNumber: 4).format()
    
    log.debug "Sending ${cmds.inspect()}"
    
    delayBetween(cmds, 1000)
}

@netgeek That code is a custom device type I wrote for HSP02 motion sensor. In order to use it, You’ll need to get access to the developer IDE first by going to https://graph.api.smartthings.com/. After you have access to the IDE, you can then create a new custom device type in the “My Device Type” section by copy and paste the above code. After you publish the device type for yourself, you’ll be able to go into the “My Device” section and change the device type of the HSP02 sensors you’ve paired with Smartthings Hub to the custom device type you just created.

Let me know if you run into any issues with the code.

Thank you I will give it a shot tonight keep up the awesome work !!

I pasted the code in the custom part but what do I put in the namespace I left it blank and got this error.

Error:500: Internal Server Error
URI
/ide/device/save
Reference Id
9256aba1-c430-4ce6-9019-9b4fabd222e8
Date
Sun Apr 27 23:55:10 UTC 2014
Class
java.lang.NullPointerException
Message
Cannot get property ‘defaultNamespace’ on null object

I don’t think that’s a required field. Just put in the name for the device type and hit create button. Then you paste code in the next page, save the code and publish it.

That worked TYVM

Has anyone found a device type that actually uses the LUX capability of this device?

Do you have an updated version of the device type for HSP02? I just got one of these but it is not very responsive at all, I am hoping with a more unique Device type it may actually function like a real motion detector
The code posted here is erring out when creating device type
Thanks

Hi

Did you ever get the light level feature to work?

Thanks

FWIW: I looked at the tech specs for this sensor, it appears the lux sensor is only used in conjunction with the motion detection. From the specs:

The user can set a detecting percentage of lux level which determines when
the light sensor will be activated. If percentage of lux level of ambient
illumination falls below this percentage, and a person moves across or within
the protected area, the detector will emit Z-Wave ON Command (i.e. Basic Set
Command (Value = Basic Set Level)) to controller and activate connected
modules and lighting.

They shouldn’t even mention the lux sensor in the sales materlal, it’s not a usable feature of this device.

Why I try to create a device and place the code in the code section it comes up with

Java.lang.IllegalArgumentException: Metadata definition not found

Any help?