Now that I have written an app to consider motion, temp and wind speed. I would also like to be able to override those conditions by turning the switch on with the app or switch.
So I realize this will be an “else if” statement in my app. But I don’t know the code to retrieve an “on” event from the app or actual switch? Or since the (evt) section is based on motion how can I accomplish this? Do I need another (evt) section for the app or switch command?
Any suggestions? Here is the (evt) part of my app I want to modify:
def motionHandler(evt) {
log.debug "$evt.name: $evt.value"
def data = getWeatherFeature( "conditions", zipcode )
log.debug( "Current windspeed in ${zipcode} is ${data.current_observation.wind_mph} mph")
if (evt.value == "active") {
def lastTemp = sensor1.currentTemperature
if (lastTemp >= temperature1){
def lastWindspeed = data.current_observation.wind_mph
if (lastWindspeed <= wind1){
log.debug "turning on lights"
switches.on()
state.inactiveAt = null
}
}
}
else if (evt.value == "inactive") {
if (!state.inactiveAt) {
state.inactiveAt = now()
}
}
}
@garymullen Thanks for the code. But what I really want may not be possible. I have an app that turns on a switch based on motion conditional on temp and wind. But what if I decide…forget all the conditions…I want the fan to just stay on and not turn off after a period of inactivity.
So I would like to use the App to send an On command and have this override the app or the conditions in the app. So I need to be able to see the On signal from the app? Is this possible? Is it possible to see where a command came from and not the status of the switch?
Thanks!
Scott
Oh, I see what you’re trying to do. Within your switch on/off handles you can use the event method isPhysical() to test if it was a button was pushed, then set an override to true.
@GaryMullen@Dianoga Thanks so much for your expertise! I will integrate your suggestions later today and post my findings. But this looks perfect to handle On/Off from the physical switch.
Is it possible to detect the On signal sent from the Android App? So if I turn on the switch with the app the switch stays on like your suggestion.
Thanks again,
Scott <— not a developer (EE) but learning quickly with cut/paste/trial&error. Fortran 77 is not very helpful now.
p.s. Dumb question but all my apps have been based on a single (evt). Can (evt) blocks be nested? Or do they each need to close and process in sequence?
The event object has a source attribute which is supposed to contain one of APP, APP_COMMAND, COMMAND, DEVICE, HUB, or LOCATION, but in my limited testing is only ever contains DEVICE. I’m going to email support about it. However, I think this is what you would use.
I’m not quite sure what you mean about the nesting of event handlers. They’re just code blocks, so one could call another, if that’s what you mean?