# Sunevent node to light lamp

**URL:** https://discourse.nodered.org/t/sunevent-node-to-light-lamp/93971
**Category:** General
**Created:** [17 December 2024 18:06 UTC](https://discourse.nodered.org/t/sunevent-node-to-light-lamp/93971 "2024-12-17T18:06:47Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![pabz](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pabz/32/97290_2.png) [@pabz](https://discourse.nodered.org/u/pabz)
#### Post date: [17 December 2024 18:06 UTC](https://discourse.nodered.org/t/sunevent-node-to-light-lamp/93971/1 "2024-12-17T18:06:47Z")

</div>

Hi,

I've been tinkering with HA and Node-Red for a few days now and I want to make the garden lights and the porch light turn on and off based on a sunevent ([node-red-contrib-sunevents (node) - Node-RED](https://flows.nodered.org/node/node-red-contrib-sunevents)).

What I want is for the light to turn on at the sunevent dusk. As far as I know, a light needs the payload "on" to turn on. So based on this assumption, I have built the flow.

Below is an example of the flow as I have solved it myself, but I wonder if it can be done more easily.

The flow has 2 inject nodes so that the sunevent node is triggered every day (as advised in the documentation). Then a GPS location is pushed into the sunevent node. The sunevent node has a payload object with 4 properties: msg.payload.latitude, msg.payload.longitude, msg.payload.sunevent, and msg.payload.datetime. Since I am only interested in msg.payload.sunevent, I first remove the other 3 in a change node. Then the stripped payload goes to a JSON node to convert it into a string, then another change node to convert the string "sunevent":"dusk" to "on".

Is there perhaps an easier way to do this? Probably with function nodes, but I can't really code :9. By the way, the sunevent node keeps posting this at every sunevent and then passes it unchanged to the switch node as a text string instead of "on" because it is not converted if the string is anything other than "sunevent":"dusk". I haven't tested what effect that has on a light, for example.

Tips are welcome!

```auto
[{"id":"32cb8da3.eeffc2","type":"tab","label":"Sun Events simple example","disabled":false,"info":""},{"id":"2d8758dc.922e08","type":"inject","z":"32cb8da3.eeffc2","name":"","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payloadType":"str","x":110,"y":120,"wires":[["58c171f7.59b7a"]]},{"id":"ae9be1e3.2e7ab","type":"sun events","z":"32cb8da3.eeffc2","testmode":true,"verbose":true,"topic":"sunset","name":"","x":590,"y":180,"wires":[["7c3cf0a444bb5631"],[]]},{"id":"58c171f7.59b7a","type":"change","z":"32cb8da3.eeffc2","name":"set GPS coordinates (change node) ","rules":[{"t":"set","p":"payload.latitude","pt":"msg","to":"52.702521","tot":"num"},{"t":"set","p":"payload.longitude","pt":"msg","to":"3.188700","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":180,"wires":[["ae9be1e3.2e7ab"]]},{"id":"c0aa61b0.223ae","type":"inject","z":"32cb8da3.eeffc2","name":"","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"00 12 * * *","once":false,"onceDelay":0.1,"topic":"","payloadType":"str","x":110,"y":240,"wires":[["58c171f7.59b7a"]]},{"id":"448101bf3080f56a","type":"debug","z":"32cb8da3.eeffc2","name":"debug 7","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":840,"y":280,"wires":[]},{"id":"7c3cf0a444bb5631","type":"change","z":"32cb8da3.eeffc2","name":"","rules":[{"t":"delete","p":"payload.latitude","pt":"msg"},{"t":"delete","p":"payload.longitude","pt":"msg"},{"t":"delete","p":"payload.datetime","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":380,"wires":[["cf8e5d92f04a1243"]]},{"id":"cf8e5d92f04a1243","type":"json","z":"32cb8da3.eeffc2","name":"","property":"payload","action":"","pretty":false,"x":610,"y":480,"wires":[["a5ea0f971b1aad50"]]},{"id":"a5ea0f971b1aad50","type":"change","z":"32cb8da3.eeffc2","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"{\"sunevent\":\"dusk\"}","fromt":"str","to":"on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":480,"wires":[["448101bf3080f56a"]]}]

```

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [17 December 2024 18:18 UTC](https://discourse.nodered.org/t/sunevent-node-to-light-lamp/93971/2 "2024-12-17T18:18:45Z")

</div>

> [@pabz](#):
>
> Tips are welcome

Install node-red-contrib-cron-plus. Enter your map coordinates. Choose your sun events (dusk, dawn, whatever) and it will output when it happens. No need to inject. No need to check. Simple.

---

<div class="post-metadata">

### Author: ![pabz](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pabz/32/97290_2.png) [@pabz](https://discourse.nodered.org/u/pabz)
#### Post date: [17 December 2024 18:52 UTC](https://discourse.nodered.org/t/sunevent-node-to-light-lamp/93971/3 "2024-12-17T18:52:11Z")

</div>

thanks! Will def look into it. And what about my chain of thought like I described? Did it make sense? Just trying to learn 😃

---

<div class="post-metadata">

### Author: ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)
#### Post date: [17 December 2024 19:34 UTC](https://discourse.nodered.org/t/sunevent-node-to-light-lamp/93971/4 "2024-12-17T19:34:22Z")

</div>

I use the Big-Timer node to control my home lighting system and Cron-Plus to control my home surveillance system. Big-Timer is probably a bit of an "over-kill" for this application but was the first node I found many, many years ago when I created the flow and dashboard.

 ![tues_big_Timer_A](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/e/aea32fdbfdb230e31440888f98e96a573cf0e60d.png)  
 ![tues_big_Timer_B](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/f/3f86f030adf3c2168317ea30ac9030978ad7fc5e.png)  
 ![tues_big_Timer_C](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/e/6e7c345c491eaa499998e5f27e3937afda4bbcb3.png)  
This part of the flow provides feedback to indicate when a light has reacted to its command.  
 ![tues_big_Timer_E](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/1/317f7433a74cb68fb26f175f7758f5a7ca0a348e.png)  
As I wanted my home lighting system to work "unattended" in "auto" and "manual" mode, I ended-up building a Finite State Machine (FSM) to manage and control the various states. The lights come on at Sunset and go off at 22:00hrs. At 22:00hrs until sunrise the home surveillance system takes over monitoring my infrared detectors and sending messages to a Telegram account on my mobile phone if body-heat is detected. I use a number of S20 and S26 Mains Switches flashed with Tasmota to turn the external lights On/Off.  
 ![tues_big_Timer_D](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/7/c7a5de1e2cd3b4de7353c8fd9ef7564cd9e9d1e9.png)  
I can't publish the flow just now as it is huge and contains a number of embedded security features applicable to my house and property.  
If I get some spare time at Xmas I'll try to simplify it and publish it on... _Share Your Projects_.

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [17 December 2024 19:51 UTC](https://discourse.nodered.org/t/sunevent-node-to-light-lamp/93971/5 "2024-12-17T19:51:45Z")

</div>

I don't have too many lights to control so after some years of using a more complex scalable setup I went back to basics and have a small flow for each lamp:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/3/638451c20561da34c6b94b7a02a8f99b0bf3f903.png)

CRON+ is used for the timed brightness setting but use the sun position nodes to output standard data to MQTT:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/7/77ea0987c1cd90415fc8617d23e321d647bc0b33.png)

So I can have settings that change lighting when the sun is at a specific azimuth/elevation if I want (though I don't actually bother).

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/0/800374deef20bbd360fd783361c0ea7f0cc6c0eb.png)

Instead, I use the daylight and sleep booleans as you can see.

Some of the lamps do use solar events though:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/9/c9b32c53a08adaa1ed7498a4df0d1ddf978ca882.png)

I really should rationalise things a bit more. But it all works so there isn't much incentive. 🙂 It has simply grown and evolved over time.

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [18 December 2024 06:48 UTC](https://discourse.nodered.org/t/sunevent-node-to-light-lamp/93971/6 "2024-12-18T06:48:27Z")

</div>

Another angle/approach - I have true adaptive lighting based on a lux sensor that measures the lux outside (could be inside too ofcourse) and I map the incoming value to a range with a range node, between sunset-60 (ie starting 60 mins before sunset) and have a long transition of 2 minutes.

This will slowly turn on the lights based on the outside brightness, the darker it gets, the brighter the lights.

eg. lux 400 - 0 will map to 0 - 60% brightness. Every time a new measurement comes back from the lux sensor the lights will change their brightness.

---

<div class="post-metadata">

### Author: ![pabz](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pabz/32/97290_2.png) [@pabz](https://discourse.nodered.org/u/pabz)
#### Post date: [23 December 2024 14:32 UTC](https://discourse.nodered.org/t/sunevent-node-to-light-lamp/93971/7 "2024-12-23T14:32:28Z")

</div>

@bakman2 @TotallyInformation @dynamicdave @Steve-Mcl  
Thanks for all the replies. Will spend some time reading up haha.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [23 March 2025 14:33 UTC](https://discourse.nodered.org/t/sunevent-node-to-light-lamp/93971/8 "2025-03-23T14:33:25Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
