What I want to achieve: I am using the Blind Control Node for my shutters. However, in addition to the calculated positions coming from this node, the shutters may also be opened or closed with physical buttons and/or voice assistant commands.
[only] in this case, I want to feed the new blind position back into the Blind Control Node to trigger it's "positionOverride" function (the automation is then suppressed for some time).
my best idea so far: After a lot of trial & error, I came up with a function that should distinguish between values coming from the controller node versus values coming from manual input... and decide, what to do...
what doesn't work:, I seem to be doing something wrong with the context storage. The auto value gets correctly stored in the node-context, however it cannot be retrieved if the node is re-triggered.. the count-value, strangely, behaves as expected.. please help!!!
// function to determine manual override
// Out1: to shutterblind
// Out2: back to controller node
var autoPos = context.get("autoPos")||10;
// Test if context is maintained correctly :-/
var count = context.get("count")||0;
count+=1;
context.set("count",count);
if (msg.hasOwnProperty("blindCtrl")) {
// function was triggered by controller node
node.status({fill:"grey",shape:"dot",text:"new auto "+msg.payload});
context.set("autoPos", msg.payload);
return [ msg, null ];
}
else {
// function was triggered by a new value coming from the blinds
// debug, why is autoPos reverted to the default?????
node.status({fill:"grey",shape:"dot",text:"auto is "+autoPos});
// allow for slight variations
if(Math.abs(msg.payload - autoPos)<=0.04)
{
// real position equals autoValue
// do nothing
// node.status({});
}
else
{
// relevante Positionsänderung
var OverrideMsg = {
topic: "levelOverwrite",
payload: -1,
position: -1,
importance: 1
}
// node.status({fill:"blue",shape:"dot",text:"Override "+payload+" >> "+myValue});
}
return [ null, OverrideMsg ];
}