Haiku New to HaikuHelper questions

snarkyninja

Member
Hey all, just picked up a Mac Mini and HaikuHelper to hopefully take my HAI system to the next level. I had a couple questions while getting into the software, hoping you can help:
 
1. Is there any way to leverage javascript's object oriented capabilities for triggered actions? I.e. instead of doing this:

function onButtonActivate(button) {
if (button.name == 'Garage 1') {
controller.unitWithName('GarageDoor1').setOnForSeconds(2);
}
if (button.name == 'Garage 2') {
controller.unitWithName('GarageDoor2').setOnForSeconds(2);
}
if (button.name == 'Garage 3') {
controller.unitWithName('GarageDoor3').setOnForSeconds(2);
}
// etc...
}

I'd like to do something like this:

controller.buttonWithName('Garage 1').onPress('openCloseGarage', 1);
controller.buttonWithName('Garage 2').onPress('openCloseGarage', 2);
controller.buttonWithName('Garage 3').onPress('openCloseGarage', 3);

function openCloseGarage(which) {
controller.unitWithName('GarageDoor'+which).setOnForSeconds(2);
}

Does this capability exist/is it in the roadmap? Or are global methods the only way to go?
 
2. Is there any preference one way or the other programming in HaikuHelper/Javascript vs. programming in PC Access? Right now I'm just duplicating the functionality of my existing program in HaikuHelper, but there are some parts along the lines of IF OFF THEN Siren OFF that I can't really see the advantage of moving out of the PC Access program. I've also seen people using HaikuHelper and also leaving significant portions of automation code, like sprinkler control, almost entirely within PC Access. Thoughts?
 
3. Is there a "proper" way to do time-based programming? Something like:

function at0930() {
doSomething();
doSomethingElse();
}

Thanks in advance!
 
1. This is planned to be added. You can probably already do it by wrapping the callbacks, but it's not built in yet.

2. It's up to you how much programming you want to put where. You may want to keep the most core basic programming on the controller in case the machine running HaikuHelper fails. There's another an advantage to having less programming on the controller - it will run faster.

3. You can use the helper's onSyncStart() callback. It's called every minute and passes a date object. Or you can roll your own scheduling system.
 
Back
Top