HAMBridge Motion app throwing error. Need help please

Can someone please tell me why my code keeps throwing me this error?

2018-02-16 15:10:37.918:errorNo signature of method: app15188154212101659971614.$() is applicable for argument types: (app15188154212101659971614$_motionHandler_closure2) values: [app15188154212101659971614$_motionHandler_closure2@173d2fda] Possible solutions: is(java.lang.Object), run(), run(), any(), any(groovy.lang.Closure), use([Ljava.lang.Object;) on line null

/**

  • Copyright 2015 SmartThings
  • 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.
  • Smart Nightlight
  • Author: SmartThings

*/
definition(
name: “HAMBridge motion Controller”,
namespace: “HAMBridge”,
author: “jprosiak”,
description: “Sends one HAMBridge command when it’s dark and motion is detected. Sends another when it becomes light or some time after motion ceases.”,
category: “Convenience”,
iconUrl: “https://s3.amazonaws.com/smartapp-icons/Meta/light_motion-outlet-luminance.png”,
iconX2Url: “https://s3.amazonaws.com/smartapp-icons/Meta/light_motion-outlet-luminance@2x.png
)

preferences {
section(“Which Motion Sensors…”){
input “motionSensor”, “capability.motionSensor”, title: “Where?”, multiple: true, required: true
}
section(“And then off when it’s light or there’s been no movement for…”){
input “delayMinutes”, “number”, title: “Minutes?”
}
section(“HAMBridge Information:”){
input “server”, “text”, title: “Server IP”, description: “Your HAM Bridger Server IP”, required: true
input “port”, “number”, title: “Port”, description: “Port Number”, required: true
input “HAMBcommandMotionActive”, “text”, title: “Command to send when motion starts”, required: true
input “HAMBcommandMotionInactive”, “text”, title: “Command to send when motion stops (optional)”, required: false
}
section(“Using either on this light sensor (optional)”){
input “lightSensor”, “capability.illuminanceMeasurement”, required: false
}
section(“Set mode restrictions”){
input (
name : “modes”
,type : “mode”
,title : “Set for specific mode(s)”
,multiple : true
,required : false
)
}
}

def installed() {
initialize()
}

def updated() {
unsubscribe()
unschedule()
initialize()
}

def initialize() {
subscribe(motionSensor, “motion”, motionHandler)
if (lightSensor) {
subscribe(lightSensor, “illuminance”, illuminanceHandler, [filterEvents: false])
}
}

def motionHandler(evt) {
log.debug "$evt.name: $evt.value"
if (evt.value == “active”) {
//if (enabled()) {
def crntLux = lightSensor.currentValue(“illuminance”).toInteger()
log.debug "Lux Level is ${crntLux}"
if (!modes || modes.contains(location.mode)) and (${crntLux} < 200) {
def HAMBcommand = settings.HAMBcommandMotionActive
sendHttp()
}
//}
state.motionStopTime = null
}
else {
state.motionStopTime = now()
if(delayMinutes) {
runIn(delayMinutes*60, turnOffMotionAfterDelay, [overwrite: true])
} else {
turnOffMotionAfterDelay()
}
}
}

def illuminanceHandler(evt) {
log.debug “$evt.name: $evt.value, lastStatus: $state.lastStatus, motionStopTime: $state.motionStopTime”
//def lastStatus = state.lastStatus
def crntLux = lightSensor.currentValue(“illuminance”).toInteger()
if (${crntLux} > 200) {
def HAMBcommand = settings.HAMBcommandMotionInactive
sendHttp()
}
else if (state.motionStopTime) {
def elapsed = now() - state.motionStopTime
if (elapsed >= ((delayMinutes ?: 0) * 60000L) - 2000) {
def HAMBcommand = settings.HAMBcommandMotionInactive
sendHttp()
}
}
}

def turnOffMotionAfterDelay() {
log.trace "In turnOffMotionAfterDelay, state.motionStopTime = $state.motionStopTime, state.lastStatus = $state.lastStatus"
if (state.motionStopTime) {
def elapsed = now() - state.motionStopTime
log.trace "elapsed = $elapsed"
if (elapsed >= ((delayMinutes ?: 0) * 60000L) - 2000) {
def HAMBcommand = settings.HAMBcommandMotionInactive
sendHttp()
}
}
}

def scheduleCheck() {
log.debug “In scheduleCheck - skipping”
//turnOffMotionAfterDelay()
}

//private enabled() {
// def result
// if (lightSensor) {
// result = lightSensor.currentIlluminance?.toInteger() < 200
// }
// else {
// def t = now()
// result = t < state.riseTime || t > state.setTime
// }
// result
//}

def sendHttp() {
def ip = “${settings.server}:${settings.port}“
log.debug “${ip}“
log.debug “sending ${HAMBcommand} to HAMBridge on ${ip}”
//sendHubCommand(new hubitat.device.HubAction(””“GET /?${settings.HAMBcommand} HTTP/1.1\r\nHOST: $ip\r\n\r\n”””, hubitat.device.Protocol.LAN))
sendHubCommand(new hubitat.device.HubAction(""“GET /?${HAMBcommand} HTTP/1.1\r\nHOST: $ip\r\n\r\n”"", hubitat.device.Protocol.LAN))
}

try

if ((!modes || modes.contains(location.mode)) and (crntLux < 200)) {

Not sure about that code and the parens, but the and (crntLux part was just hanging out by itself, and you didn’t want to convert crntLux to a string having just turned it into an integer for comparison to 200.

Throws this when saving it:

expecting ‘)’, found ‘and’ @ line 78, column 55.

It should be && not and

Ah! Yup that fixed it. Now lets hope it works as expected.

Thanks!!!

So the on part works but when it sends command after motion stops the HABcommand Variable returns null…

So after delay minutes it does runin and calls turnOffMotionAfterDelay

def motionHandler(evt) {
	log.debug "$evt.name: $evt.value"
	if (evt.value == "active") {
		//if (enabled()) {
        	def crntLux = lightSensor.currentValue("illuminance").toInteger()
        	log.debug "Lux Level is ${crntLux}"
        if ((!modes || modes.contains(location.mode)) && (crntLux < 200)) {
            	HAMBcommand = settings.HAMBcommandMotionActive
				sendHttp()
        	}
		//}
		state.motionStopTime = null
	}
	else {
		state.motionStopTime = now()
		if(delayMinutes) {
			runIn(delayMinutes*60, turnOffMotionAfterDelay, [overwrite: true])
		} else {
			turnOffMotionAfterDelay()
		}
	}
}

Within turnOffMotionAfterDelay I set HAMBcommand = settings.HAMBcommandMotionInactive

def turnOffMotionAfterDelay() {
	log.trace "In turnOffMotionAfterDelay, state.motionStopTime = $state.motionStopTime, state.lastStatus = $state.lastStatus"
    if (state.motionStopTime) {
		def elapsed = now() - state.motionStopTime
        log.trace "elapsed = $elapsed"
		if (elapsed >= ((delayMinutes ?: 0) * 60000L) - 2000) {
            def HAMBcommand = settings.HAMBcommandMotionInactive
        	sendHttp()
		}
	}
}

When sendHttp() is run, it returns sending null to HAMBridge

def sendHttp() {
    def ip = "${settings.server}:${settings.port}"
    log.debug "${ip}"
    log.debug "sending ${HAMBcommand} to HAMBridge on ${ip}"
	//sendHubCommand(new hubitat.device.HubAction("""GET /?${settings.HAMBcommand} HTTP/1.1\r\nHOST: $ip\r\n\r\n""", hubitat.device.Protocol.LAN))
    sendHubCommand(new hubitat.device.HubAction("""GET /?${HAMBcommand} HTTP/1.1\r\nHOST: $ip\r\n\r\n""", hubitat.device.Protocol.LAN))
}

Any advice on why this is happening? This looks correct to me.

I found this little gem with your name on it and decided to use that as the template for this app. It’s much easier for me to follow than the template I found in smartThings.

Now the only problem I am having is the delay for the lights turning off isn’t working. It throws:

Name cannot be null.

I think this is the last time I will have to bother you. I appreciate all of your help.

I just loaded that code I wrote and it works fine. What do you mean about the error? Show the logs. Or are you talking about your code? I don’t see what problem you are referring to.

I am talking about my code. Sorry about that.

app:882018-02-17 09:44:00.553:error Name cannot be null.
app:882018-02-17 09:44:00.208:debug sending hueUpstairsHallOff to HAMBridge on ****:8080
app:882018-02-17 09:44:00.205:debug ****:8080
app:882018-02-17 09:44:00.200:debug Here we are 5
app:882018-02-17 09:44:00.170:debug true
app:882018-02-17 09:44:00.166:debug HAMBcommand = null
app:882018-02-17 09:44:00.137:debug Here we are 4
app:882018-02-17 09:44:00.118:debug delayMinutes = 5
app:882018-02-17 09:44:00.114:debug true
app:882018-02-17 09:44:00.044:debug Here we are 3
app:882018-02-17 09:43:48.024:debug sending hueUpstairsDayTime to HAMBridge on ****:8080
app:882018-02-17 09:43:48.020:debug ****:8080
app:882018-02-17 09:43:48.001:debug Here we are 5
app:882018-02-17 09:43:47.959:debug Lux Level is 48
app:882018-02-17 09:43:47.955:debug HAMBCommand = null
app:882018-02-17 09:43:47.871:debug Here we are 2

weird… It’s working now. Thanks for helping me with all of this!

1 Like