Node Red with Home Assistant: Need some help to start

Hi,

I started a couple of weeks with Home Assistant and it is already working very well, except some complicated automation rules.

Then I noticed Node Red and I think it could help me. I installed it just a couple of days ago and I was checking the internet for some tips and tricks.

I have already some very basic automation tasks running, but for more sophisticated rules I need some kickoff support.

What I want to do:

  • Check SolarRadiation of outside weatherstation
  • If solar radiation is above 250 for 5 Minutes and outside temp is higher then 17 degrees, then I want to close the shutter of my roof windows
  • If solar radiation is below 250 for 5 Minutes, then the shutter should be opened again

This is my test flow:

The second output of the timer is sending a STOP Message.

My issue is, that the trigger is not triggered only one time, it is triggered whenever a change on the solar radiation happens, regardless if it is still below or above the threshold.

[{"id":"f656a892.f6c508","type":"trigger-state","z":"e5f37dc0.ca69","name":"Sonnenstrahlung","server":"e76cb70.9b3bd48","entityid":"sensor.pws_solarradiation","debugenabled":false,"constraints":[{"id":"b71wfwmloq39","targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"greater_than","comparatorValueDatatype":"str","comparatorValue":"250"}],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"x":130,"y":600,"wires":[["4dee1d93.1e5d54"],["8eece640.753448"]]},{"id":"a3a38b20.1a0ff8","type":"api-current-state","z":"e5f37dc0.ca69","name":"Außentemperatur größer 17 Grad","server":"e76cb70.9b3bd48","halt_if":">17.0","override_topic":true,"override_payload":true,"entity_id":"sensor.pws_temp_c","x":680,"y":560,"wires":[["8df7a5a6.2b9c98"]]},{"id":"4dee1d93.1e5d54","type":"stoptimer","z":"e5f37dc0.ca69","duration":"5","units":"Minute","payloadtype":"str","payloadval":"STOP","name":"5 Minuten Delay","x":380,"y":540,"wires":[["a3a38b20.1a0ff8"],["8eece640.753448"]]},{"id":"8eece640.753448","type":"stoptimer","z":"e5f37dc0.ca69","duration":"5","units":"Minute","payloadtype":"str","payloadval":"STOP","name":"5 Minuten Delay","x":380,"y":640,"wires":[["6876f54c.d9d2cc"],["4dee1d93.1e5d54"]]},{"id":"8df7a5a6.2b9c98","type":"api-call-service","z":"e5f37dc0.ca69","name":"","server":"e76cb70.9b3bd48","service_domain":"notify","service":"pushover_johannes","data":"{     \"message\": \"Arbeitszimmer Beschattung ein\",     \"title\": \"NR: Hohe Sonneneinstrahlung\"   }","mergecontext":"","x":990,"y":560,"wires":[[]]},{"id":"6876f54c.d9d2cc","type":"api-call-service","z":"e5f37dc0.ca69","name":"","server":"e76cb70.9b3bd48","service_domain":"notify","service":"pushover_johannes","data":"{     \"message\": \"Arbeitszimmer Beschattung aus\",     \"title\": \"NR: Niedrige Sonneneinstrahlung\"   }","mergecontext":"","x":990,"y":620,"wires":[[]]},{"id":"e76cb70.9b3bd48","type":"server","z":"","name":"Home Assistant","url":"https://SERVERNAME","pass":"PASSWORD"}]

Maybe someone could give me some hints?

Br,
Johannes

Hi, nice project you are working on – it sounds like you could use some RBE nodes (report by exception). It can be set up to report only changes from the previous msg, or differences beyond of a certain percentage (deadband). There are also some contrib nodes that will report only when a value leaves a range by a certain amount of either time or value (node-red-contrib-excursion). Good luck!

Dear Johannes,
I have built a similar solution but with other HW to control my Markisen (auf Deutsch denke ich), Awnings in english. The brand is Elero and it is working very well since at least 5 years. To measure the Sun intensity, I use a light sensor for the 1-wire network (OneWire), the sensor is outside at the very top roof of our house.

I have also worked a bit with Home Assistant (HA) and I do think a combination of HA and Node-RED (NR) is a good match (I think HA is a great Interface Hub since it is supporting many integrations of all kind). But as you say, setting up rules is complicated and there is a lot to wish, especially syntax control, for the built-in editor for scripts written in (yet another) scripting language (Jinja2)

Here I prefer NR, javascript, html (for GUI’s) and (my choice) eventually Python for specific background services

When you design your solution, I would just like to give you some of my experiences & ask a few questions:

  • Check SolarRadiation of outside weatherstation
    What kind of weatherstation do you have?

  • If solar radiation is above 250 for 5 Minutes and outside temp is higher then 17 degrees, then I want to close the shutter of my roof windows

  • If solar radiation is below 250 for 5 Minutes, then the shutter should be opened again

Always calculate average values to get a smoother operation and transition between opening/closing your shutters. Myself, I measure the sun radiation once per minut and for closing I use a 5 minute average value (sum of 5 measurements divided by 5). For opening I use a 30 minute average ((sum of 30 measurements divided by 30). To avoid problems when the values are close to the limits, I use fixed levels with an offset, i.e. when the 5 min average reaches and exceeds the “closing” level, lets say 10.0, the shutters are closed. Then when the 30 min average drops below the “opening” level, lets say 8.0, shutters will open again. I do also block further open/close commands for 10 minutes after a command has happened. In this way you will avoid the risk that the opening/closing logic is too sensitive.
In addition, maybe only nice to have for awnings, I have rules considering weather conditions, time and calendar (no need to have awnings down when risk for rain and during nights or during winter months) Just as example how I have implemented it for awnings.

Will be interesting to see the progress,
Best regards, Walter

Thanks, very intersteing.

For now I made a different approach. I replaced the Home Assistant Trigger by an Event_State and afterword I have added a switch (True and False, depending on the Threshold). Maybe this could be my solution.

But I will also look into your suggestions.

Br,
Johannes

Thanks for this answers.

Very interesting.

I am using a Ventus W830 as a Weatherstation. I had this already before I started with HomeAutomation. If this is working well I want to change to a “offline” version.

Regarding the Elero: What Bridge are you using? I have also elero for my blinds, but so far I only know the expensive bridge from Elero.

Br,
Johannes

For Elero, I have made a really nasty trick; I bought “cheaper” wall mounted buttons, took them apart, mounted 433 MHz radio remote controlled relays with contacts simulating button press for up/down. Replaced batteries with 3V power supply, everything put into a new nice looking box. Inside, well…it is like a “a not so fancy car” under the hood but it is working

So the basic is to simulate button press on a standard Elero wall remote

Limitation: if you have need for several addresses (individual control of shutters) you need one remote per shutter. Maybe then the gateway is a better option anyway. I use all-for-one so I need only one remote

BR Walter

Ok, this is the limitation. I have shutters and therefore I would need 8 Remotes… Also if I would group rooms together I would still need 5 remotes.

So I will stick on the existing Remote - Elero Tempotel 2, which allows me at least sunset based control.

Br,
Johannes

@krambriw

Maybe you could give me some hints on how you resolved it with average values.

I tried it with the timer, which should have a similar effect, but I have the problem that either one of the timer is called whenever there is a change on the solar radiation...

Nr,
Johannes

Yes, you use the “Smooth” node, feed both with the same value, set one for 5 readings (if you have a reading per minute), the other to 30 readings. At the outputs you get an averaged value

I am still fighting with the basics...

I am using now the smooth function and I guess it is working.

But how can I solve the issue that the Close or Open is only triggered once? At the moment it is triggered every minute due to the injection.

image

Br,
Johannes

I think this could be of interest (Elero). Seems only an Elero USB stick is needed, price is around 129 euro.
http://www.smarthomedirekt.de/category/elero-online-shop/elero-centero/

I found a discussion & full implementation for openHAB where the API available from Elero is used
https://community.openhab.org/t/new-elero-transmitterstick-binding/24515/15

Several possibilities:

  1. Use the bash script from this link with the Exec node in NR. This is most likely the quickest start to get things connected with NR
    https://github.com/openhab/openhab1-addons/issues/4149

  2. Use openHAB with the ELERO stick as a gateway to the shutters, communicate with NR using MQTT. Seems to be a simple solution, everything is already implemented and supported. You can then send commands and receive events via MQTT

  3. Try if Serial port in NR could be used for direct communication with the USB stick, maybe is good enough as solution to send commands straight off. Here a discussion about serial communication with the Elero stick
    https://homematic-forum.de/forum/viewtopic.php?f=37&t=26066

  4. Write a set of nodes for NR supporting ELERO stick
    Long term dream, nice to have…

Look at the rbe (report by exception) node

I am one step ahead:

image

I trigger with the timestamp every 1 minute, get the solar_radiation_value and feed it to the smooth function. Then I check an inut_boolean to execute each flow-path only once, doing my action and changing the input_boolean.

That works fine.

But now I want to add one function:
Before closing the shutter I want to check the outside temperature. If below 17.0 Degree the Flow should be halted.

I guess I cannot use "<17.0" in the "Halt if" Statement?

Br,
Johannes

I think slowly I understand Node Red.

Maybe I solved the issue by myself.

  1. I created a global variable (global, because I will use this on other flows as well) which is feed with the Outside-Temperature

  2. I created a function, which only passes the message if the temperature of the global variable is aboth a certain threshold

    var AT = global.get("Aussentemperatur");
    if ( AT > 17.0 ) {
    return msg;
    } else {
    return;
    }

What do you think, is this ok? Or is there a better way to do it?

Br,
Johannes

1 Like

I think this is ok to do, I use some global variables myself in the same way for various purposes. The only thing against using too many global variables in the system is that it might be tricky to debug if you get lost one day. Secondly the value will be lost if you restart NR.

If persistence is needed you have to save the value so it survives restarts/reboots. I suggest to save to a MQTT topic with the retained flag set. Then subscribe to the same topic and set the global variable from there. In this way your global variable will always be updated and re-initiated also after restarts.

Also for the temperature I would suggest to Smooth the readings to avoid fast changes around the trip-point. Otherwise you could end up having a very sensitive system just around 17.0 if the temperature is toggling a couple of times between 17.0 and 17.1, your shutters would go crazy…Maybe send the output from the Smooth node to a RBE node and use a defined dead-band as well to avoid flickering

Its fine to use the rbe node to avoid that the same message is repeated. However, if you really would need the same message to be repeated for synchronization purposes like I have done in my system, you could solve it having a timer that sends a “dummy” message to the rbe node at some regular intervals to “reset” it so to say

Like if you send “Close” as msg.payload every minute to the RBE node, it will only be forwarded the first time. Then every 15 minute a Trigger node sends " " as msg.payload to the same RBE input. Next time “Close” is sent, the RBE node will forward it on further into your flow and you can use this for synchronization (of course you have to have some logic that doesn’t react on or filters out the " " msg.payload)

Thanks, the persistance I am doing with input_boolean on home assistant, but of course MQTT could be an option, but I have no MQTT Brooker running at the moment.

Another question:

I have multiple flows which are controling my Velux Roof Window (Window, shutter, blinds,…). I have the feeling that it doenst like, when many actions are called at the same time.

What would be the way to “halt” all other flows for 30 seconds if one flow is executed.

E.g.: I have three windows. Each window is represented by a dedicated flow and at the end of each flow I am triggering the Velux Gateway.
When now the first trigger happens, all triggers from all other flows should be “suspended”. After 30 seconds the next flow should continue but block again all other flows.

I hope you understand what I mean?

Br,
Johannes

OK, I see your point with the Velux Gateway

I assume you have all flows in the same NR, right? (not flows running in different NR setups)

First of all, they do not happen exactly at the same time since NR is single threaded but it might be that it is anyway too fast for the Velux Gateway

One way I think you can solve it is to build a queue for the commands sent to the Velux. And then send each command from the queue to Velux with a time delay

Fortunately, there is a node available that can help, it is the Delay node

Instead of each flow sending directly to Velux, configure them to send to the same Delay node instead (you can put the Delay node on separate flow and use links for this purpose) Configure the Delay node for Rate limit like 1 msg per 5 seconds or what works fine with Velux

In this way, all flows will deliver their messages to the Delay internal buffer “at the same time” (FIFO I think) but then they will be sent out one by one with the configured delay in between each of them

For #2: It seems more natural to me to use a switch node – although the function node will work. Test for global. Aussentemperatur > 17 and route to port #1 – any incoming msg that doesn’t pass the test is dropped from the flow…

Hi,

Yes, this I know, but whenever there is a change on the input value it will pass again the switch, as long as it will pass the threshold, right? If I want to have it triggered only once I need a different approach.

Br,
JOhannes