Lighting controller ideas

Using uibuilder of course :grinning: :sunglasses:

Finally made some progress;

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]);