Haiku First Java Script

hick

Member
Lupinglade,
 
 
Used your samples in HaikuHelper script API to write simple zone unsecured/secured send message. see below:
 
 
function onZoneNotReady(zone) {
 if(zone.number == 14 ) {// Match zone by number
    helper.sendNotification(controller, zone.bestDescription + ' Open'); 
     }
}     
     
function onZoneSecure(zone) {
  if(zone.number == 14) { // Match zone by number
  
      helper.sendNotification(controller, zone.bestDescription  + ' Closed'); 
      }
}    
 
 
It Works.
 
 
Now I'm  "Trying" to write a function that is triggered on flag change (Off) and zone (not ready) to send push.
 
function onUnitOff(unit) { // when flag off 
 if(unit.number == 438)// this the flag #
 if(zone.number == 14) // this is the zone #, but only if unsecured
     helper.sendTroubleNotification(controller, "Main Garage Door OPEN");
 }
 
 
When i run script in script editor no problem.
 
when I change the flag in pc access I get a message in Helper that states- unhandled exeception on first line :
 
 
in function "onUnitOff": can't find variable:zone.
 
 
I have been playing with this script for hours, so I'm down  to begging for help.
 
 
 
Thanks in advanced.
 
Mike Hickman
 

:blink:
 
zone is not defined in your onUnitOff() function, that's why the error is coming up. You need to use something like this:
Code:
if(unit.number == 438 && controller.zoneWithNumber(14).isNotReady) {
... send notification
}
 
lupinglade,
 
WOW,
 
Thanks for the quick reply. I rewrote the script per your reply
 
starting at line 19.
 
my JS is written as follows:
 

function onUnitOff(unit) {    // when flag off 
 if(unit.number == 438 && controller.zone(14).isNotReady) {  //match unit by number and confirm zone Not ready by number
helper.sendTroubleNotification(controller,"Garage Door is Open");
  }
}

 
Clears run script.
 
Making progess got a differant respose in HH.
 
when flag is turn off I get this message in HH.
 
"Unhandled exception in script on line: 19 in function "onUnitOff": Unknown method zone() accessed on Controller object."
 
Again, Thanks in advance.
 
Mike
 
lupinglade,
 
Thank You,
 
When I got rid of the() surrounding zone (14), the function worked. See how written, and seen in HH script editor below.
 
 

function onUnitOff(unit) {    // when flag off 
 if(unit.number == 438 && controller.zone14.isNotReady) {  //match unit by number "and" confirm controller zone # Not ready
helper.sendTroubleNotification(controller,"Rhonda you left the Garage Door Open");
  }
}

 
// Not quite sure why it worked? but will study some more.
 
// The troubleNotification sends a differant tone than a noftification which helps my wife.
 
Thanks
Mike Hickman
 
Your code is incorrect. The proper code for that line is as I pasted it:
if(unit.number == 438 && controller.zoneWithNumber(14).isNotReady) {
controller.zone14 nor controller.zone(14) are valid.
 
lupinglade,
 
thanks for your reply and your patience,
 
Had to looked at your first response a dozen times and never saw "WithNumber". Might be ADD, might have been a Monday issue. Either way, I changed script to match as you posted.  (see Below)
 
Of Course its works fine.
 
 
function onUnitOff(unit) {    // when flag off 
 if(unit.number == 438 && controller.zoneWithNumber(14).isNotReady) {  //match unit by number "and" confirm controller zone # Not ready
helper.sendTroubleNotification(controller,"Rhonda you left the Garage Door Open");
 }
}

 
 
Want to let you know that I love Haiku, and looking forward to using HH more as I learn.
 
Thanks
 
Mike Hickman
 
Lupinglade,
 
Finally had some more free time.
 
Added "else" to my script. Works well just wanted to know if it is the best way to write this script?
 
2 differant (pushes) with 2 diff sounds.
 
 
function onUnitOff(unit) { // when Rhonda's flag off (triggered by proximity Detection)

//match Rhondas flag unit by number and confirm DBL garage door zone by number Not ready

if(unit.number == 438 && controller.zoneWithNumber(14).isNotReady){    
 
 helper.sendTroubleNotification(controller,"'Rhoda' Your  Garage  Door Left 'OPEN'");

}else { // else if her garage door is closed (Secure) when her flag turned off send differant message

if(unit.number == 438 && controller.zoneWithNumber(14).isSecure){
 
helper.sendNotification(contoller, "Rhonda is leaving");
}
 }
  }
 
Also is there a way for her to respond to TroubleNotifaction (,"'Rhoda' Your  Garage  Door Left 'OPEN'"); by pressing launch and going to my camera view of that door and sending command to close door? Instead of her pressing launch, go to camera view, go to button, push button, go back to camera view.
 
 
 
 
or am I asking for too much?
 

Thanks in advanced for any comments or suggestions you my make.
 
Mike Hickman
 
This should do the same with less code:
Code:
function onUnitOff(unit) { // when Rhonda's flag off (triggered by proximity Detection)
	// match Rhondas flag unit by number and confirm DBL garage door zone by number Not ready
	if(unit.number == 438) {
		if(controller.zoneWithNumber(14).isSecure) helper.sendNotification(contoller, "Rhonda is leaving");
		else helper.sendTroubleNotification(controller,"'Rhoda' Your Garage Door Left 'OPEN'");
	}
}
Regarding the button, yes, you can mark the button as a favorite (using the top right star button in Haiku when viewing the button). Then, she can just swipe up from the bottom of the screen when viewing the camera (or from anywhere else) and that button will appear along with any other favorited buttons.
 
Lupinglade,
 
Thanks for your input. Really appericate you taking time to help me. Puts HH at another level compared to some "other" software's Company customer service.
 
Great idea on using favorite to swipe up from bottom of screen.
 
Rewrote script to your example, works great.(of course)
 
Copy and pasted new script below existing(see below) and changed unit, zone, and message to apply to "my" garage door. Only my script (bottom block) will work during testing.
 
What am I missing? Each one(block) works separately, but not when together. (2 functions named the same)?
 
// I left comments out for clairty.
 
 
function onUnitOff(unit) {
     if(unit.number == 438) {
if (controller.zoneWithNumber(14).isSecure) helper.sendNotification(controller,"Rhonda is leaving");
else helper.sendTroubleNotification(controller,"'Rhoda' you left Garage Door'OPEN'");
 }    
}

function onUnitOff(unit) {
     if(unit.number == 437) {
if (controller.zoneWithNumber(12).isSecure) helper.sendNotification(controller,"Mike is leaving");
else helper.sendTroubleNotification(controller."'Dummy' you left Garage Door'OPEN'");
 }    
}
 
Again "Thanks" in advance.
 
Mike
 
You can't name the two functions the same -- you are overriding the first function with the second one. Instead, merge them into one function with an "else if()" on the second one. Or you can name the functions separately and then call them both from the onUnitOff() callback function. Whichever you prefer.
 
lupinglade,
 
Thanks, kinda thought that was the problem.
 
Rewrote with "else if" for now (see below). I will play with rename the functions and then call them back later this weekend. Also added when "we" arrive home.
 
Got to get on the road before everbody else.
 
Have a Great 4th.
 
 
 function  onUnitOff(unit) { // when Rhonda's or Mike flag off (triggered by proximity Detection)
      if (unit.number == 438 ) { // Rhonda's flag and garage door zone
if (controller.zoneWithNumber(14).isSecure) helper.sendNotification(controller,"Rhonda is leaving");
else helper.sendTroubleNotification(controller,"'Rhoda' you left Garage Door 'OPEN'");
     }
else if(unit.number == 437) {//Mike's flag and garage door zone
if (controller.zoneWithNumber(12).isSecure) helper.sendNotification(controller,"Mike is leaving");
else helper.sendTroubleNotification(controller,"'Dummy' you left Garage Door 'OPEN'");
}    
}


function onUnitOn(unit) { // when Rhonda's or Mike flag on (triggered by proximity Detection)
    if(unit.number==437) // Mike's flag
    helper.sendNotification(controller, "'Welcome' Home Mikey");
else if    (unit.number==438) { // Rhonda's flag
    helper.sendNotification(controller, "'Welcome' Home Rhonda");
}
}  
 
 
Thanks again.
Mike Hickman
 
Back
Top