snarkyninja
Member
Background: I have two units that I want to link the states of, i.e. Unit1 ON means Unit2 ON, Unit1 OFF means Unit2 OFF and vice versa. In PC Access, the code was pretty simple:
WHEN Unit1 ON
THEN Unit2 ON
WHEN Unit1 OFF
THEN Unit2 OFF
WHEN Unit2 ON
THEN Unit1 ON
WHEN Unit2 OFF
THEN Unit1 OFF
I tried to do the same in HaikuHelper with the onUnitLevelChange like so:
function onUnitLevelChange(unit) {
if (unit.name == 'Unit1') controller.unitWithName('Unit2').setLevel(unit.level);
if (unit.name == 'Unit2') controller.unitWithName('Unit1').setLevel(unit.level);
}
Unfortunately I found that onUnitLevelChange was being called for every singe step during the dim/brighten process, and whenever a command was issued my lights would set themselves to random levels between 0 and 100 every second (change from 2 to 78 to 53 to 100 to 2 to 12 etc. etc.).
I also tried it with the following:
function onUnitOn(unit) {
if (unit.name == 'Unit1') controller.unitWithName('Unit2').setLevel(100);
if (unit.name == 'Unit2') controller.unitWithName('Unit1').setLevel(100);
}
function onUnitOff(unit) {
if (unit.name == 'Unit1') controller.unitWithName('Unit2').setLevel(0);
if (unit.name == 'Unit2') controller.unitWithName('Unit1').setLevel(0);
}
This looks a lot more like the old PC Access code, and exhibited different behavior - turning them on worked fine, turning them off started the cycle of random levels again.
Is there any way for me to get what I want out of this? Whatever level one unit is set to, the other one should be set to as well. Etc. And is onUnitLevelChange really supposed to execute repeatedly during a single change? Thanks for your time!
WHEN Unit1 ON
THEN Unit2 ON
WHEN Unit1 OFF
THEN Unit2 OFF
WHEN Unit2 ON
THEN Unit1 ON
WHEN Unit2 OFF
THEN Unit1 OFF
I tried to do the same in HaikuHelper with the onUnitLevelChange like so:
function onUnitLevelChange(unit) {
if (unit.name == 'Unit1') controller.unitWithName('Unit2').setLevel(unit.level);
if (unit.name == 'Unit2') controller.unitWithName('Unit1').setLevel(unit.level);
}
Unfortunately I found that onUnitLevelChange was being called for every singe step during the dim/brighten process, and whenever a command was issued my lights would set themselves to random levels between 0 and 100 every second (change from 2 to 78 to 53 to 100 to 2 to 12 etc. etc.).
I also tried it with the following:
function onUnitOn(unit) {
if (unit.name == 'Unit1') controller.unitWithName('Unit2').setLevel(100);
if (unit.name == 'Unit2') controller.unitWithName('Unit1').setLevel(100);
}
function onUnitOff(unit) {
if (unit.name == 'Unit1') controller.unitWithName('Unit2').setLevel(0);
if (unit.name == 'Unit2') controller.unitWithName('Unit1').setLevel(0);
}
This looks a lot more like the old PC Access code, and exhibited different behavior - turning them on worked fine, turning them off started the cycle of random levels again.
Is there any way for me to get what I want out of this? Whatever level one unit is set to, the other one should be set to as well. Etc. And is onUnitLevelChange really supposed to execute repeatedly during a single change? Thanks for your time!