# Lighting controller ideas

**URL:** <https://discourse.nodered.org/t/lighting-controller-ideas/50876>\
**Category:** General\
**Tags:** lighting\
**Created:** [10 September 2021 22:46 UTC](https://discourse.nodered.org/t/lighting-controller-ideas/50876 "2021-09-10T22:46:03Z")\
**Posts on this page:** 3\
**Page:** 2

<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:** [12 September 2021 10:06 UTC](https://discourse.nodered.org/t/lighting-controller-ideas/50876/21 "2021-09-12T10:06:16Z")

</div>

> [@dceejay](#):
>
> … of course …

Using uibuilder of course 😀 🕶

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [13 September 2021 16:44 UTC](https://discourse.nodered.org/t/lighting-controller-ideas/50876/22 "2021-09-13T16:44:52Z")

</div>

Finally made some progress;

```auto
const relayTopic = "relayboard/relay2"
var data = global.get('lighting') || { daylight: true, pir: "0", mode: "auto", dusk: false, button: "0" };

if (msg.topic && msg.topic == 'shellies/gjd-controller/input/0') { data.pir = msg.payload }
if (msg.topic && msg.topic == 'dusk') { data.dusk = msg.payload }
if (msg.topic && msg.topic == 'mode') { data.mode = msg.payload }
if (msg.topic && msg.topic == 'button') { data.button = msg.payload }
if (msg.topic && msg.topic == 'daylight') { data.daylight = msg.payload }

// run program only if dark enough for lights
if (data.daylight == false) {
switch (data.mode) {
    case "manual":
        if (data.button == "1") {
            node.send({ payload: "on", topic: relayTopic })
        } else if (data.button == "0" ) {
            node.send({ payload: "off", topic: relayTopic })
        }
    case "auto":
        if (data.dusk == true) {
            node.send({ payload: "on", topic: relayTopic })
        } else if (data.dusk == false && data.pir == "0") {
            node.send({ payload: "off", topic: relayTopic })
        } else if (data.dusk == false && data.pir == "1") {
            node.send({ payload: "on", topic: relayTopic })
        }
    }
}

// save back data to globals
global.set(["lighting.pir", "lighting.dusk", "lighting.mode", "lighting.button", "lighting.daylight"], [data.pir, data.dusk, data.mode, data.button, data.daylight]);

```

---

<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:** [12 November 2021 16:45 UTC](https://discourse.nodered.org/t/lighting-controller-ideas/50876/23 "2021-11-12T16:45:49Z")

</div>

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

[Previous page](https://discourse.nodered.org/t/lighting-controller-ideas/50876.md?page=1)
