I am a hacker at best, meaning I take other peoples code and manipulate it for myself so dont mind my ignorance. I have to learn based off trial and error.
As a test I have an app that switches modes via a virtual on/off switch and is also based off of sunrise/sunset. I know this has already been done but my endgame is for disarming my alarm and putting it in the correct mode, either way this part works fine.
What I also want is for the switch to change to on or off based on a mode change. So in other words if I manually change the mode to Home the switch is showing as On.
I have def modeChangeHandler(evt) setup just to test to see if I did it right and it is not even being triggered based on the log when I make a mode change. I know its something stupid but with my lack of knowledge, I have no idea what
I just tested your code. It is registering mode changes. I don’t have “Home Day”, but when I change mode, it logs “Changed to something else”. Is there something else you are expecting to happen? How are you changing the mode?
Edit: I also tested it with a mode I do have, and it is working too.
Thanks for testing it. I guess the good news is that I actually did it right
The bad news is its not working for me.
The “Changed to something else” is what I was expecting but it does not happen for me. I select “Live Logging” in the IDE and then change the mode manually using my iphone via the dashboard…not any smartapp.
@swindmiller what does the Live Logging state regarding the app, if anything? You should get a “WARN” if the mode you are attempting to switch into is the current mode.
@chuck_pearce, I don’t get anything for the app at all unless I hit the virtual on/off button I have set to this app. I should not need to do anything with the button at all right, as the mode change should trigger it independently of the button, right?
I just tried re-creating the app by going to “MySmartApps”, “New Smartapp”, “From Code” and pasting in:
Open the app on your phone, then click Done in the upper right, you SHOULD see "Updated with settings: " with a block of text about the switch that is selected, do you not even see that? Make sure you have the “Live Logging” running before you open the app on your device.
Nevermind…its working now
I removed everything related to that switch and started over. Must have screwed something up at some point.
Thanks to everyone for helping me out
I am sure I will have more questions later.
This is really cool that I was able to write my own app…well kind of…lol
This handles the Off then the On and then also if the mode is changed manually. The way I have it now:
def modeChangeHandler(evt) {
if (evt.value == "Away Day" || evt.value == "Away Night")
{
log.debug "Changed to armed"
theSwitch.on()
}
else {
log.debug "Changed to Disarmed"
theSwitch.off()
}
}
creates a loop or repeating event because of the “theSwitch.off()” and “theSwitch.on()”, I know this is incorrect but what I was trying to do was simply turn the switch on or off if the mode was changed manually, not run everything all over again. How can I replace the “theSwitch.on()” (or off) to just simply turn it on or off without running def onHandler(evt) again.
Thanks and sorry for the stupid questions…still learning.
I believe what you are going to need to do is call unsubscribe after the event fires then subscribe again after the turn the switch into the other state. Also, you may not want to hard code mode names, you can easily create a selector for that.
Thanks but that did not seem to work. I understand why it should have worked
I will keep trying.
Would something like this work?
sendEvent(name: “contact”, value: “closed”)
I saw it in another post but did not know if thats what I needed or how to implement it.
I tried sendEvent(name: “switch”, value: “inactive”) but that did not do anything.
@swindmiller, thanks for sharing your progress. I was stuck working on my own SmartApp and I learned from your code.
I’m developing a SmartApp that pushes out notifications to devices (Arduino/Particle based) so that they can process certain events locally; i.e., it could turn on a night light when in night mode upon seeing motion immediately, rather than waiting for the cloud or hub. It could also sound an alarm immediately upon sensing motion in away mode also, making the home slightly more self-sufficient in case of an internet outage.