I am still fighting with the "smooth" and "rbe" function and I do not get it working poperly.
When using automation on Home Assistant I was checking the solar-radiation, and based on that output I was closing or opening the shutters.
Above 250 W/m2 for 10 minutes - close
Below 250 W/m2 for 20 minutes - open
That was working really nice and I had no situation where the shutter closed/opend/closed...
Now on Node Red I have this issue.
This is my config:
And then I am checking within a function:
var Beschattung = global.get("beschattung_ein");`
if ( Beschattung >= 250 ) {
return msg;
} else {
return;
}
With the functions I know at the moment in Node Red I have the issue that it open/closes much faster and I do not know what I should change...
Br,
Johannes
I understand you use Beschattung as condition together with temperature to decide if shutters should be open or closed
For Beschattung you are correctly creating two smoothed values (10 resp 20 readings), one faster and one slower. I would use this and check when the faster is above the slower and above 250. When this is the case and temperature is 17 or higher, condition would be ātrueā to close the shutters, otherwise āfalseā. Then next would be to send a command to your Velux if Beschattung condition and temperature value is fulfilled (send it to an rbe node and then to Velux to avoid repeating the same command every minute)
The code below is an example code I would test (you need to get the temperature as well)
var BeschattungEin = global.get("beschattung_ein");
var BeschattungAus = global.get("beschattung_aus");
var Temp = global.get("smoothed_temperature");
if (BeschattungEin > BeschattungAus){
if ( BeschattungEin >= 250 && Temp >= 17.0) {
msg.payload = "OK to close shutters";
//msg.payload = true;
//or send something that triggers the Velux to close
return msg;
}
} else {
msg.payload = "OK to open shutters";
//msg.payload = false;
//or send something that triggers the Velux to open
return msg;
}
Since I like Function nodes very much I could not resist to elaborate a bit furtherā¦
The example code below has additional functionality. The problem to avoid is that your shutters opens/closes too frequently when your logic is close to the setpoints. I mean it would look very strange if they opens and then right away closes (as well as the opposite).
So I have added some counters that will prevent this (I assume that you trigger the function node every minute). It works like this; When shutters are closed or opened, the opposite command is blocked for 5 minutes. As long as shutters are open or closed, the corresponding counter will get updated to prevent frequent operations. I have set 5 (minutes) for both but you can of course change whatever is better, maybe delay opening longer than closing. Like closing them fast after 1 minute but then keeping them closed for at least 10 minutes. You have to try this out what works best, most tricky situations are likely when it is partly cloudy weather
Also, hopefully I have not created any bugs in the code below but who knows
var BeschattungEin = global.get("beschattung_ein");
var BeschattungAus = global.get("beschattung_aus");
var Temp = global.get("smoothed_temperature");
// To avoid too frequent open/close operations
context.set('block_open',context.get('block_open')||0);
context.set('block_close',context.get('block_close')||0);
if (context.get('block_open') > 0) {
var bo = context.get('block_down');
bo = bo-1;
context.set('block_open', bo);
}
if (context.get('block_close') > 0) {
var bc = context.get('block_up');
bc = bc-1;
context.set('block_close', bc);
}
if (BeschattungEin > BeschattungAus && context.get('block_close') === 0){
if ( BeschattungEin >= 250 && Temp >= 17.0) {
msg.payload = "OK to close shutters";
//msg.payload = true;
//or send something that triggers the Velux to close
context.set('block_open',5);
return msg;
}
}
if (BeschattungEin <= BeschattungAus && context.get('block_open') === 0){
if ( BeschattungEin < 250) {
msg.payload = "OK to open shutters";
//msg.payload = false;
//or send something that triggers the Velux to open
context.set('block_close',5);
return msg;
}
}