Hi all,
at the moment I am trying to implement my roller shutter automation in Node-Red. The roller shutter are closing at night automatically and open in the morning - everything like expected. Now I also want to Implement the following thing:
1.) If the door is opened while the roller shutter would close at night the roller shutter stays open until I close the door/window.
2.) If the rollershutter is closed and I open the window it should automatically open the rollershutter and after i close the window it should automatically close it again (but only if it was closed before I open the door/window).
I already tried it by storeing the state of the door and rollershutter in two variables (Bürobalkontür_war_geöffnet and Bürorollladen_war_geschlossen).
The function block 'Bürobalkontür_war_geöffnet_true' has the following code inside:
var Bürobalkontür_war_geöffnet=flow.get('Bürobalkontür_war_geöffnet')|| 0 ;
Bürobalkontür_war_geöffnet == 1;
flow.set('Bürobalkontür_war_geöffnet',Bürobalkontür_war_geöffnet);
return msg;
The function block 'Bürobalkontür_war_geöffnet_false' has the following code inside:
var Bürobalkontür_war_geöffnet=flow.get('Bürobalkontür_war_geöffnet')|| 0;
Bürobalkontür_war_geöffnet == 0;
flow.set('Bürobalkontür_war_geöffnet',Bürobalkontür_war_geöffnet);
return msg;
The function block 'Bürorollladen_war_geschlossen_false' has the following code inside:
var Bürorollladen_war_geschlossen=flow.get('Bürorollladen_war_geschlossen')|| 0; ;
Bürorollladen_war_geschlossen ==0;
flow.set('Bürorollladen_war_geschlossen',Bürorollladen_war_geschlossen);
return msg;
The function block 'Bürorollladen_war_geschlossen_true' has the following code inside:
var Bürorollladen_war_geschlossen=flow.get('Bürorollladen_war_geschlossen')|| 0;
Bürorollladen_war_geschlossen == 1;
flow.set('Bürorollladen_war_geschlossen',Bürorollladen_war_geschlossen);
return msg;
It seems that the variables do not work like expected because the flow is not working (the roller shutter stays closed when I open the door (and the state changes in node red).
Any Idea how I can solve this? and maybe there is an easier solution for my problem?
I am not sure I am going to be much help, but just to maybe get things moving.....
The shutters open/close automatically each day at given times.
I'm not having a go at your English - mine isn't the best.
But that is confusing.
I'll put my understanding here to maybe help clear things.
It is day time and the shutters are open.
You don't want them to close THIS evening.
But tomorrow you want them to close as usual. Correct?
Re-reading I don't think I got it quite right.
Re-take: (After writing 2 and rethinking what you wrote)
The shutters are open. (not really declared)
You open the door.
The time to close the shutter happens - and the door is still open.
The shutter stays open until that door is closed, then the shutter closes.
Better?
(This is complicated to read)
The shutter is closed/down.
You open the window (or door? - confused).
The shutter opens.
If you close the window BEFORE the time when the shutter is commanded to open: the shutter closes again.
Let's deal with the first one - as per the second attempt.
I don't have the nodes you use and so my application may affect how I am doing this.
(Oh. I am going to have to write some code. I'll post it soon, but I'll post this now to maybe give you some comfort that you aren't being left out of anyone's thoughts)
You need to explain ALL the possibilities.
Here's an example:
If SCHEDULE is set to CLOSED
You open the door.
What happens?
The shutters open - given.
You close the door.
The shutters close - given.
What happens if the SCHEDULE tells the shutters to open WHILE the door is open?
I'm guessing: DO NOTHING.
So, you could get away with this simple bit of code:
I don't have/use those nodes, but this may be a way to help you see how to do it.
The "new day" is needed to clear things to make them work.
Side note:
I send message for all instances to show you what is going on.
In reality you would filter those messages you don't need - the ABORTED one in particular.
Just to start, the code you presented does for sure look "not working". It is impossible to guess what your code should look like, you better share your complete flow and specifiy the non-standard nodes you are using to have a better chance to get some help on this
Hi all,
first thanks for your support! I am very new to Node-Red and still learning a lot each day
First here is the complete flow I posted in the first post for one door and roller shutter. I would suggest to only look at this combination first because it will be the same for all the other windows/doors I have in my flat.
Furthermore I think i have to explain the cases more that you understand it better (sorry for this - I will try my best to make it understandable for you )
1.) The cover of the door should close at sunset.
2.) The cover of the door should open at sunrise.
3.) If the door is open while #1 get triggered the cover should stay open until the door gets closed. Then the cover should close also. (e.g. I open the door and go out to the balkony. While I am outside the #1 automation gets triggered so I would get looked out at my balkony. Because of #3 the cover should get closed again when I am in my flat and closed the door and not directly at sunset)
4.) If the cover and door is closed and I open the door, the cover should automatically open. After I close the door again it should close the cover again. (This should only work when the cover was closed while the door gets opened) (e.g.: The cover and door is closed and I want to go out to the balkony. At the moment I have to open the cover manually and then I can go out. With #4 I want that if the cover and door is closed and I open the door that the cover automatically opens until I close the door again. When I go in again and close the door the cover should close automatically again that I do not have to close the cover manually after I close the door.)
#1 and #2 are already working in my flow. With #3 and #4 I have problems (due to my lack of knownledge with Node-Red )
Hi Thanks for your support. Hope all of you had a god start into 2022
Today I had some time for testing different things regarding Node Red and my roller shutter automation. I adjusted your code to my system ad gave it a try.
At the moment I am facing a problem that the 'manualshutter' changes randomly between open and close and therefore the roller shutter is moving up and down without stopping... Might be somehow related to the manualshutters reset?
Furthermore I think that there is a logical error in this flow: The scheduled close never affects the roller shutter. So the roller shutters will never close at sunset - or am I missing something?
Hi,
thanks again!
I tried your code again:
In closed state the door sensor sends false and in opened state true. So it was like you expected. I think that two connections between the closed/opened switch to the function block are missing ,or?
I already tried with and without the two connections but both were not working. If I press the Open/close Inject instead of the door sensor I can see the right output in the manualshutters debug node. If I open the windows I see that the state changes, but the manualshutters debug node doesn't get triggered.
EDIT: Because of this I changed the state type of the door sensor from bool to string and the closed/opened switch to off/on. With this change It is now closing/opening with the state of the sensor when scheduled close was triggered before (so everything like expected ). Because of this I think I do not need the and/or nodes and the state of the rollershutter because it will only work when the scheduled close was triggered before (and therefore it is only at night like I wanted to have it).
Two problems are still left (Both related to the scheduled open/close)
1.) In the morning the cover is (in normal conditions) closed (manualshutters = closed) and therefore the cover will not get opened in the morning at sunrise.
2.) If the window is closed and the cover is opened it should close the cover at sunset. At the moment it get Aborted (this should only get aborted if cover is open and window is also opened.)
I think both problems could be solved by changing the function node in the scheduled part of the flow.
One additional thing I changed in my flow is this connection, because I think this was an error...
Get rid of those nodes crossed out. They are taking up space and not really doing anything.
I've also wired the inject nodes so they are the same as the signals from what ever those nodes are. Yes I've left the messages as they were, but doing that can cause confusion to yourself.
Sorry my code/flow wasn't too good, but I don't have the nodes you have.
So you put the outputs of your nodes where the inject nodes connect.
I've laid it out nicely to help with clarity - I hope.
The nodes (and the inject nodes) messages go into a change node that sets the message to what is needed at the next step.
As the message is split there are two changed nodes used for each input.
Though it makes no difference to the code, laying it out in columns makes things easier to understand what is going on where. See the yellow lines.
I renamed 4 change nodes to you know what is going on in them. (Green markings.)
The two debug nodes don't really do much but it helps to label them with a meaningful name so when you see the messages they make sense.
Your code doesn't allow any of the scheduled messages to get out - from what I can see.
The switch nodes are only for the FORCE messages.
That's not going to help.
In the morning the cover is (in normal conditions) closed (manualshutters = closed) and therefore the cover will not get opened in the morning at sunrise.
I think that is covered by what I just said about not allowing the scheduled messages to get any where.
The other point.... I don't understand.
(Sorry the editor has thrown a wobbily and I can't scroll back while typing to see your posts.)
(Ah, better now)
Yeah. I don't understand what you mean.
Testing it to the best of what I understand it does what is needed.
Oh, and PLEASE! Don't include those foreign nodes. I don't have them and have to keep deleting their configuration nodes when I'm done.
Oh and good on your for seeing/catching my mistake with the connections in the first picture.
Sorry. My fault.
(Just out of interest: Do you have a spreadsheet program? If so which one?)
(I want to send you a spreadsheet that will maybe help you understand what is going on)
I will test this the next days and will give you feedback
One last thing: After deploying the flow it seems that the state of the Aquara sensor and sunset/sunrise (here I would have to check which triggered last) doesn't get defined until I open the window and the sunset/sunrise gets triggered the first time. Therefore the flow.manualshutters and flow.scheduleshutters payload is not set until the sensors get triggered the first time. Might lead into strange behaviour after each deployment. Is there a way to get the states directly after deployment?
The problem is/was the flow.context for the door status. (THE state of the door)
There was a condition where the flow could cause problems because the state of the door was not set.
If you opened/closed the door that problem would go away.
I added a couple of lines in one of the function nodes to get around that problem.
I also changed the "Clear context" changed node.
Rather than deleting the flow.context, I realised it is better to set it to a value ("closed") as that was also causing problems. Sorry. My fault.
That switch node you have at the end.....
Why?
By that stage the messages should give you enough to control what happens next.
(Ok, I digress. For now it is ok. But ultimately you don't need it.)
I'm guessing from that node, you will control the next thing (node?) to get the shutters to raise/lower.
I'll stop here and make the spread sheet.
Though it will be a bit messy, as I haven't done this kind of stuff for a long time and I can't exactly remember how to do them.
But it makes it easier (in some ways) to see what is going on.
Spreadsheet not as easy to do as I thought. I'll get back to you with it later.
There are 4inputs. 2 manual and 2 scheduled.
The "Remember" ring is the flow.context.
And in the middle is what is sent to the blind/shutter controller.
Let's try looking at it in this way:
The shutters are CLOSED.
There are only two valid things that can happen.
1 - you open them.
2 - they are opened at sunrise.
(The third is you close them. But given they are already closed.... That doesn't matter)
Now the shutters are OPEN.
Again there are two options that can happen. But I'll elaborate on them a bit more here.
And the "not applicable open command that could be sent.
So the two options are:
1 - you close them.
2 - the sun sets.
The trick here is to rememberhow they were opened.
If they were opened automatically, they can close.
But!
If YOU opened them, they have to stay open.
Now, some confusion is starting to happen for me.
IF you open them one day: They will stay open for ever.
You need to better define how the manual commands work.
Do they live on for ever or do they become void the next day?
Scenario:
Sunrise. The shutters open.
You decide it is too hot and close them.
Later on you open them again - in the afternoon.
What happens at sunset?
There is a big area of uncertainty with how the manual override then controls how things happen later on.
I modified the flow in order to safe the latest state of the window sensor in a file and read it in only once after deploment. With this the undefined state issue should be solved.