Starting with Node-Red: Switch on lights x minutes before sunset depending on cloud conditions

Hi,
I’m not new to HA itself but new to Node-RED. After reading through a few entries in the community, watching several videos, I’m here now because I could not find a suitable (at least for me) starting point.
Currently, I have two automations directly in HA to switch on the living room lights before sunset. The 1st is set to do that 55 minutes earlier with a transition of 15 minutes to a brightness of 50% if the lights are actually off and the weather code from openweathermap is below 800 or above 801.
The 2nd switches on the lights 20 minutes before sunset, again checking if the lights are already on, not checking weather code (not needed), and checking if it is before 23:00 (interesting during summer…).
I tried with BigTimer, sun.sun, Light Scheduler but could not find something that worked (except switching on the lights at a fixed time). Could maybe someone give me an example especially for the trigger in this case? As well as the weather code thing? I think, that I just need the right starter to work out the rest for myself.
Any help highly appreciated!
KR
Carsten

I have a node called “Sun events” under the input section, a node called “Sun rise/set” under the time section and then the BigTimer.
All three should be able to get the sun state, but it is important that you set the longitude and latitude, since it will else fail.

Try to paste this into a function node:


msg.sun = global.get('homeassistant').homeAssistant.states["sun.sun"];
msg.sun_state = global.get('homeassistant').homeAssistant.states["sun.sun"].state;
msg.sun_attr_next_dawn = global.get('homeassistant').homeAssistant.states["sun.sun"].attributes.next_dawn;

return msg;

This will create a node that return the sun values in msg.sun, msg.sun_state and msg.sun_attr_next_dawn.
You can put a debug node after it and set the output to the complete message object (This should actually always be done or you will miss information from the debug node now and then).

For other values from HA you can open up the Context Data in the down arrow in the upper right corner and then click the refresh icon next to Global.
This will show the HA values in NodeRed and those are the ones that are extracted with the global.get command in the function node.