Send a switch ON event from motion detected event (GE 26933)

I’m trying to send an event to turn on the switch from the event that reports motion.

The motion event runs but the light never turns on. Am I using the wrong method to send an event to the switch, or can you not send a zwave event from another zwaveEvent?

def zwaveEvent(physicalgraph.zwave.commands.notificationv3.NotificationReport cmd){
	//log.debug "---NOTIFICATION REPORT V3--- ${device.displayName} sent ${cmd}"
	def result = [ ]
    	def cmds = [ ]
	if (cmd.notificationType == 0x07) {
		if ((cmd.event == 0x00)) { // No Motion }
		else if (cmd.event == 0x08) {
		// Motion detected
		
		// Turn on the light switch
		sendEvent(name: "switch", value: "on")
		}
	}
}

The flow there is that the device has sent a message and you have parsed it and determined that it is reporting motion has been detected. Now you need to let SmartThings know about it and you might do that using sendEvent(name: "motion", value: "active"). SmartThings would then set the motion attribute to active and pass the information on to any apps that have asked to be kept updated.

By doing sendEvent(name: "switch", value: "on") you are telling SmartThings that you want to treat what has happened as if a switch has been turned on rather than a motion sensor having gone active. That’s up to you.

If your device also has a physical switch and you want that to be turned on when motion is received then you need to construct and send a Z-Wave command to do it, not use a sendEvent. Then when it has done it it would report back to say the switch is on and that is where you would do your sendEvent(name: "switch", value: "on").

I’ll defer to others for the Z-Wave command. If you have already have an on() command method you could probably just call that.

Thank you, i think you understand.
This is exactly what i am looking for. I’ve tried a few attempts at the sending the zwave event but it did not turn the switch on. Can you send a new zwave event from a zwave event that is still running?

def zwaveEvent(physicalgraph.zwave.commands.notificationv3.NotificationReport cmd){
	//log.debug "---NOTIFICATION REPORT V3--- ${device.displayName} sent ${cmd}"

// if motion detected
// Send zwave event to turn light on

}

Is this supported? What’s the zwave event?

You can check out the SmartThingsPublic repo for examples of what you’re trying to achieve, there’s no official documentation about DTH anymore because it is part of our legacy platform. (Please, look at this announcement)
I suggest you take a look at Edge drivers, the new feature to integrate Hub-Connected devices in SmartThings.

To look at this a different way…
What’s the exact brand/model of the two devices?

If you really want the switch to turn on every time the motion sensor detects motion, that’s exactly the use case zwave direct association was designed for. (Part of the independent third party zwave standard, not the SmartThings architecture.)

If you do it that way, assuming the sensor supports it, it will be faster and more efficient.

Just a thought…:thinking:

There is only one device; a switch with a motion sensor built in. So I don’t think association applies here. It sounds like a basic case of when motion is detected via

zwaveEvent(physicalgraph.zwave.commands.notificationv3.NotificationReport cmd)

send a different zwaveEvent event to turn on the lights. My attempts to send an event were fruitless so I’m asking when should the zwave event look like?

Thank you. I did look through that repository but I did not see any examples of:

def zwaveEvent(..){
if(Specific event received){
// Send new zwaveEvent to the same device
}

I’ll take a look at at the Edge drivers but this DTH is doing about 90% of what I need. Not sure I’d choose to start over unless that’s the only option.

Most devices of that type use internal communication, not out to the network and back again. Did you disable that function?

Are these two endpoints on the same device? Do they have a unique device ID other than an endpoint distinction?

I’m tagging @taustin just in case he has any thoughts on how this might work with an edge driver since you’ll have to change to one of those pretty soon anyway.

The most recent announcement about newly added devices starting to default to Edge would seem to indicate that the Groovy sunset isn’t too far off. Assuming the device you’re discussing is the GE 26931 that you’ve previously posted about, you can try using my Edge driver for these (or use my code as a starting point for the edits you’re trying to make):

As @JDRoberts mentioned, the GE 26931 hardware does support turning on the light after a motion event without hub intervention, so long as the mode is set to occupancy. This could also be done through a ST routine (which would likely run locally on your hub if you move to Edge). Those would be my first couple of options before I’d consider hard coding that behavior.

1 Like

Thanks for the head start; that makes the idea of switching to Edge easier to swallow.

Yes, I think I’m using a GE\Jasco 26933 (motion) but I’m trying to run with the operation mode set to Manual. The 30min time out limit was to short for me so I’d like use WebCore to handle the Off events (working) and the motion sensor in the device to send on light On event, triggering an on event only when motion is detected (not working).

Turning on occupancy does everything I want except that 30min limit is not great for me.

I see this option in the ST App and it does exactly what I’m looking for so using ST Routines I may be able to accomplish what I could not through the DTH; I’ll give it a try even though my device is set to mode=manual.

It would be educational to see what the zwave event looks like sending a ON event from the motion detected event.

Do these have two distinct device IDs? Or are they two endpoints on the same device? If they are two endpoints on the same device, it’s probably not going to work the way you hope.

Have you tried walking up to the device and then while standing next to the switch using the smartthings app to turn it on and see if it turns on then? That would let you know if there’s some kind of internal override going on. :thinking:

In my device list there is just the one device with it’s ID. If I move in front of the device (triggering motion) I can push the devices button and power comes on but I can see in the live log that two different events are triggered; first motion and then button pushed.

So I’m thinking that you may be right in that while the motion event is actively running (physicalgraph.zwave.commands.notificationv3.NotificationReport) I can’t send a different event to the device but it’s not crystal cleat that it’s not supported either.

It’s been a while since I’ve messed around in Groovy so I’ve forgotten a lot, but I think you need to have your motion event handler return the z-wave command you want to send. This DTH has a number of instances where receiving one z-wave command triggers another to be sent that you might be able to use as an example.

It would be simple in Edge - you would just call device:send(cmd), passing the appropriate z-wave command as cmd.

1 Like

The motion event handler will return control to the parse() method. Most commonly you see the parse() method return an event map and the ‘system’ will handle sending the event. However it does also work with Z-Wave commands and other hubActions, but it perhaps isn’t quite so common to see. You just have to be careful with the return values. A common mistake would be to add a log statement at the end of the method.

The DTH that was linked to shows this behaviour excellently, with zwaveEvent() either returning an event map, or explicitly using sendEvent() and returning a command. This return value is then used as the return value from parse().

It is command methods such as on() or refresh() where you more typically see commands returned and the ‘system’ will handle actually sending the command. Doing it yourself involves explicitly sending the hubAction. So while I mentioned earlier how an extant on() method might be exploited, it might actually be returning a command that still needs to be processed.

I’d definitely go down the Edge route myself, and I don’t particularly like Edge. I think the Groovy DTH has finally run out of time.

1 Like

Are you looking at capture a zwave event or send a zwave command?

Each zwave event has a unique method that needs to be defined in the DTH to process that event if present. There’s all a catch zwave method handler for handling undefined events.

For sending a zwave command it can be done from anywhere by sending that specific zwave command

My DTH has zwave events for the motion sensor (1) and the on button (2).

1: def zwaveEvent(physicalgraph.zwave.commands.notificationv3.NotificationReport cmd){…}
2: def on() {…}

on() is sending secureSequence([zwave.basicV1.basicSet(value: 0x63), zwave.switchMultilevelV1.switchMultilevelGet()], 3500)

On() works when the physical button is pressed. I’d like to call On() from the motion sense event but it does not seem to work. If I call it from somewhere else (like a WebCore piston) it works as expected and the light turns on. Calling the same from the zwaveEvent does not turn on the light.

I would like to call on() from the zwaveEvent so that the light turns on when motion is detected. This is essentially the behavior of Occupancy mode, but I’m trying to avoided using that because it has limitations.

The point is if it is returning that then it isn’t sending anything. It is returning what needs to be sent.

If zwaveEvent(physicalgraph.zwave.commands.notificationv3.NotificationReport cmd) returns on(), and in turn parse() returns the result of the zwaveEvent() then the commands should be sent.

If that isn’t the case then you have to explicitly send the commands. This will entail doing something like …

sendHubCommand( on() )

It might be exactly that or it might just be something similar to that. I don’t know. I’ve never had to do it. I have, however read quite a bit of https://buildmedia.readthedocs.org/media/pdf/smartthings/latest/smartthings.pdf which can be helpful (an archive of the legacy docs - not the latest but better than a poke in the eye).

2 Likes

images1

And the high five goes to orangebucket!

So simple, of course it’s the right answer. Thank you!

         } else if (cmd.event == 0x08) {
			result << createEvent(name: "motion", value: "active", descriptionText: "$device.displayName detected motion")
            log.debug "$device.displayName detected motion"
            sendHubCommand( on() )
		}

I can now resume my normal life.

Then again there’s this new shiny toy, Edge Drivers, so probably not.

BTW, thank for the light reading. I wish I had this a year ago. It’s a real page turner.

1 Like