NodeRED Flow for "Time of Day" Design Pattern

Here’s a NodeRED flow using BigTimer nodes that replicates the functionality of the popular Time of Day design pattern. I made this when I became terminally frustrated with the Astro binding failing and the rules engine silently refusing to run my rules.

[
    {
        "id": "4493567.74367a8",
        "type": "tab",
        "label": "Time of Day",
        "disabled": false,
        "info": ""
    },
    {
        "id": "eea208f.6a652f8",
        "type": "bigtimer",
        "z": "4493567.74367a8",
        "outtopic": "openhab/in/vTimeOfDay/state",
        "outpayload1": "MORNING",
        "outpayload2": "EVENING",
        "name": "Sunrise/Sunset",
        "lat": "-32",
        "lon": "116",
        "starttime": "5003",
        "endtime": "5004",
        "startoff": 0,
        "endoff": 0,
        "offs": 0,
        "outtext1": "",
        "outtext2": "",
        "timeout": 1440,
        "sun": true,
        "mon": true,
        "tue": true,
        "wed": true,
        "thu": true,
        "fri": true,
        "sat": true,
        "jan": true,
        "feb": true,
        "mar": true,
        "apr": true,
        "may": true,
        "jun": true,
        "jul": true,
        "aug": true,
        "sep": true,
        "oct": true,
        "nov": true,
        "dec": true,
        "day1": 0,
        "month1": 0,
        "day2": 0,
        "month2": 0,
        "day3": 0,
        "month3": 0,
        "day4": 0,
        "month4": 0,
        "day5": 0,
        "month5": 0,
        "d1": 0,
        "w1": 0,
        "d2": 0,
        "w2": 0,
        "d3": 0,
        "w3": 0,
        "d4": 0,
        "w4": 0,
        "d5": 0,
        "w5": 0,
        "suspend": false,
        "random": false,
        "repeat": false,
        "atstart": false,
        "odd": false,
        "even": false,
        "x": 201.5,
        "y": 128.5,
        "wires": [
            [
                "ec253542.abb948",
                "70e46d42.7cb294"
            ],
            [],
            []
        ]
    },
    {
        "id": "ec253542.abb948",
        "type": "debug",
        "z": "4493567.74367a8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "x": 562,
        "y": 133,
        "wires": []
    },
    {
        "id": "70e46d42.7cb294",
        "type": "mqtt out",
        "z": "4493567.74367a8",
        "name": "vTimeOfDay",
        "topic": "openhab/in/vTimeOfDay/state",
        "qos": "0",
        "retain": "false",
        "broker": "54e87a57.1ceff4",
        "x": 562,
        "y": 223,
        "wires": []
    },
    {
        "id": "ddb1d19d.b2cc9",
        "type": "bigtimer",
        "z": "4493567.74367a8",
        "outtopic": "openhab/in/vTimeOfDay/state",
        "outpayload1": "NIGHT",
        "outpayload2": "BED",
        "name": "10pm and Midnight",
        "lat": "-32",
        "lon": "116",
        "starttime": "1320",
        "endtime": "0",
        "startoff": 0,
        "endoff": 0,
        "offs": 0,
        "outtext1": "",
        "outtext2": "",
        "timeout": 1440,
        "sun": true,
        "mon": true,
        "tue": true,
        "wed": true,
        "thu": true,
        "fri": true,
        "sat": true,
        "jan": true,
        "feb": true,
        "mar": true,
        "apr": true,
        "may": true,
        "jun": true,
        "jul": true,
        "aug": true,
        "sep": true,
        "oct": true,
        "nov": true,
        "dec": true,
        "day1": 0,
        "month1": 0,
        "day2": 0,
        "month2": 0,
        "day3": 0,
        "month3": 0,
        "day4": 0,
        "month4": 0,
        "day5": 0,
        "month5": 0,
        "d1": 0,
        "w1": 0,
        "d2": 0,
        "w2": 0,
        "d3": 0,
        "w3": 0,
        "d4": 0,
        "w4": 0,
        "d5": 0,
        "w5": 0,
        "suspend": false,
        "random": false,
        "repeat": false,
        "atstart": false,
        "odd": false,
        "even": false,
        "x": 198,
        "y": 325.5,
        "wires": [
            [
                "ec253542.abb948",
                "70e46d42.7cb294"
            ],
            [],
            []
        ]
    },
    {
        "id": "625e4032.7a38b",
        "type": "bigtimer",
        "z": "4493567.74367a8",
        "outtopic": "openhab/in/vTimeOfDay/state",
        "outpayload1": "AFTERNOON",
        "outpayload2": "DAWN",
        "name": "45 min pre-Sunrise/Sunset",
        "lat": "-32",
        "lon": "116",
        "starttime": "5004",
        "endtime": "5003",
        "startoff": "-45",
        "endoff": "-45",
        "offs": 0,
        "outtext1": "",
        "outtext2": "",
        "timeout": 1440,
        "sun": true,
        "mon": true,
        "tue": true,
        "wed": true,
        "thu": true,
        "fri": true,
        "sat": true,
        "jan": true,
        "feb": true,
        "mar": true,
        "apr": true,
        "may": true,
        "jun": true,
        "jul": true,
        "aug": true,
        "sep": true,
        "oct": true,
        "nov": true,
        "dec": true,
        "day1": 0,
        "month1": 0,
        "day2": 0,
        "month2": 0,
        "day3": 0,
        "month3": 0,
        "day4": 0,
        "month4": 0,
        "day5": 0,
        "month5": 0,
        "d1": 0,
        "w1": 0,
        "d2": 0,
        "w2": 0,
        "d3": 0,
        "w3": 0,
        "d4": 0,
        "w4": 0,
        "d5": 0,
        "w5": 0,
        "suspend": false,
        "random": false,
        "repeat": false,
        "atstart": false,
        "odd": false,
        "even": false,
        "x": 164,
        "y": 259.5,
        "wires": [
            [
                "ec253542.abb948",
                "70e46d42.7cb294"
            ],
            [],
            []
        ]
    },
    {
        "id": "a6a5f9d6.3b0db8",
        "type": "inject",
        "z": "4493567.74367a8",
        "name": "Manual \"DAY\"",
        "topic": "openhab/in/vTimeOfDay/state",
        "payload": "DAY",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 214,
        "y": 72,
        "wires": [
            [
                "ec253542.abb948",
                "70e46d42.7cb294"
            ]
        ]
    },
    {
        "id": "862a884c.1a9b48",
        "type": "bigtimer",
        "z": "4493567.74367a8",
        "outtopic": "openhab/in/vTimeOfDay/state",
        "outpayload1": "DAY",
        "outpayload2": "",
        "name": "Day/Noon",
        "lat": "-32",
        "lon": "116",
        "starttime": "5003",
        "endtime": "5002",
        "startoff": "60",
        "endoff": 0,
        "offs": 0,
        "outtext1": "",
        "outtext2": "",
        "timeout": 1440,
        "sun": true,
        "mon": true,
        "tue": true,
        "wed": true,
        "thu": true,
        "fri": true,
        "sat": true,
        "jan": true,
        "feb": true,
        "mar": true,
        "apr": true,
        "may": true,
        "jun": true,
        "jul": true,
        "aug": true,
        "sep": true,
        "oct": true,
        "nov": true,
        "dec": true,
        "day1": 0,
        "month1": 0,
        "day2": 0,
        "month2": 0,
        "day3": 0,
        "month3": 0,
        "day4": 0,
        "month4": 0,
        "day5": 0,
        "month5": 0,
        "d1": 0,
        "w1": 0,
        "d2": 0,
        "w2": 0,
        "d3": 0,
        "w3": 0,
        "d4": 0,
        "w4": 0,
        "d5": 0,
        "w5": 0,
        "suspend": false,
        "random": false,
        "repeat": false,
        "atstart": false,
        "odd": false,
        "even": false,
        "x": 223,
        "y": 191.5,
        "wires": [
            [
                "ec253542.abb948",
                "70e46d42.7cb294"
            ],
            [],
            []
        ]
    },
    {
        "id": "a305682c.d56118",
        "type": "comment",
        "z": "4493567.74367a8",
        "name": "Day Phases",
        "info": "45 min before sunrise: DAWN\nSunrise: MORNING\n60 mins after sunrise: DAY\n45 min before sunset: AFTERNOON\nSunset: EVENING\n10 PM: NIGHT\nMidnight: BED",
        "x": 466,
        "y": 72,
        "wires": []
    },
    {
        "id": "54e87a57.1ceff4",
        "type": "mqtt-broker",
        "z": "",
        "name": "Mosquitto",
        "broker": "localhost",
        "port": "1883",
        "clientid": "Node-RED",
        "usetls": false,
        "compatmode": true,
        "keepalive": "60",
        "cleansession": true,
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": ""
    }
]

Obviously you’ll need to edit the lat/long values to match where you live.

In my case I’m using the MQTT message bus to set the item in OpenHAB, but it also works with the OpenHAB nodes if you want to use those instead.

As-built, the day phases are:

Start Time Phase
45 min before sunrise DAWN
Sunrise MORNING
60 mins after sunrise DAY
45 min before sunset AFTERNOON
Sunset EVENING
10 PM NIGHT
Midnight BED

But obviously these can be tuned to suit your needs.

3 Likes

Thanks, very helpfull get frustrated about the astro binding as well and the fact the OH community doesn’t seem to realize these are the things that are killing OH in the long run. There isn’t a single user that doesn’t want to use Time of Day or sun above or below horizon for creating automations, yet this is not a standard feature.