Inject Node Time

Had set up several lights / devices to turn on at a certain time using the inject node. However, several of these devices have not turned on, or off, at the specified time.

Wondering what the best way to have a switch / light turn on / off at a certain time is in node red, its a bit more difficult than in HA IMO

1 Like

I looked into BigTimer previously and that caused more issues than it solved (lights turning on a midnight, etc)

Was hoping for a very simple way to just set a time, every day…

I’d also recommend bigtimer. What issues did you have because the inject node is certainly not the right way to do it.

The BigTimer node had two set times when all I needed was one. It was default to 0000 so it turned the lights on at midnight. My wife wasn’t very happy

1 Like

This works for me without fail for +2 years (without turning on at midnight). Are you sure On Time2 = 00:00 and Off Time2 = 00:00?

image

2 Likes

Yes, on and off were both 00:00 and the lights came on at midnight…

Might have been a fluke of something else, but unfortunately only way I can tell is to have the lights come on at midnight, which greatly impacts our sleep

Another of the issues I have with bigtimer is that there are multiple outputs that I don’t fully understand. Don’t quite get why a simple timing mechanism has to be this complicated.

1 Like

There are many ways this can be done in node-red (make your own with a function node, use combinations of time and wait until, etc). I provided one of the easiest ways to do this. ‘Yes’, it has many options and has many ways to deal with timing events if that’s what you mean by “complicated” but it works and it works well. The documentation is pretty clear about what each of the outputs do - use the first one and run it thru a switch node.

If you’re looking for alternatives, there is also Light Scheduler.

But as @NathanCu said, inject is not the way to do it.

Edit: have you verified that you don’t have a device issue, i.e., devices becoming unavailable, unknown, etc.?

I would expect my device to turn on at 20:15, however, it does not. That is my biggest issue with Bigtimer…it doesn’t seem to work, although perhaps I’m using it wrong. I have it set to call a service “on” using the top connnector, one off option…

image

A working example

image

[{"id":"9695a1a9.e20ec","type":"bigtimer","z":"69ff7662.5ff0d8","outtopic":"","outpayload1":"","outpayload2":"","name":"Driveway Light","comment":"On at Dusk Off at 9:45","lat":"39.7876112","lon":"-75.6966001","starttime":"5001","endtime":"1305","starttime2":0,"endtime2":0,"startoff":"0","endoff":0,"startoff2":0,"endoff2":0,"offs":0,"outtext1":"ON","outtext2":"OFF","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,"day6":0,"month6":0,"day7":"","month7":"","day8":"","month8":"","day9":"","month9":"","day10":"","month10":"","day11":"","month11":"","day12":"","month12":"","d1":0,"w1":0,"d2":0,"w2":0,"d3":0,"w3":0,"d4":0,"w4":0,"d5":0,"w5":0,"d6":0,"w6":0,"xday1":0,"xmonth1":0,"xday2":0,"xmonth2":0,"xday3":0,"xmonth3":0,"xday4":0,"xmonth4":0,"xday5":0,"xmonth5":0,"xday6":0,"xmonth6":0,"xday7":"","xmonth7":"","xday8":"","xmonth8":"","xday9":"","xmonth9":"","xday10":"","xmonth10":"","xday11":"","xmonth11":"","xday12":"","xmonth12":"","xd1":0,"xw1":0,"xd2":0,"xw2":0,"xd3":0,"xw3":0,"xd4":0,"xw4":0,"xd5":0,"xw5":0,"xd6":0,"xw6":0,"suspend":false,"random":false,"randon1":false,"randoff1":false,"randon2":false,"randoff2":false,"repeat":false,"atstart":true,"odd":false,"even":false,"x":120,"y":260,"wires":[[],[],["45e436e4.fbd158"]]},{"id":"45e436e4.fbd158","type":"switch","z":"69ff7662.5ff0d8","name":"On-Off","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"ON","vt":"str"},{"t":"eq","v":"OFF","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":290,"y":260,"wires":[["c8c360f1.d55db"],["e67e1a5b.920f78"]]},{"id":"c8c360f1.d55db","type":"api-call-service","z":"69ff7662.5ff0d8","name":"Driveway Light ON","server":"f3f422ce.9f2a6","version":5,"debugenabled":false,"domain":"switch","service":"turn_on","areaId":[],"deviceId":[],"entityId":["switch.drivewaylightswitch"],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":470,"y":220,"wires":[[]]},{"id":"e67e1a5b.920f78","type":"api-call-service","z":"69ff7662.5ff0d8","name":"Driveway Light OFF","server":"f3f422ce.9f2a6","version":5,"debugenabled":false,"domain":"switch","service":"turn_off","areaId":[],"deviceId":[],"entityId":["switch.drivewaylightswitch"],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"first","x":480,"y":280,"wires":[[]]},{"id":"f3f422ce.9f2a6","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30,"areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]
[
    {
        "id": "37aca3e667312fac",
        "type": "tab",
        "label": "Daily Automation Flows",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "6610fd625e4fe130",
        "type": "debug",
        "z": "37aca3e667312fac",
        "name": "debug 2",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 280,
        "y": 600,
        "wires": []
    },
    {
        "id": "590bc9eaa6de89ce",
        "type": "bigtimer",
        "z": "37aca3e667312fac",
        "outtopic": "",
        "outpayload1": "",
        "outpayload2": "",
        "name": "Test",
        "comment": "",
        "lat": 0,
        "lon": 0,
        "starttime": "525",
        "endtime": "540",
        "starttime2": 0,
        "endtime2": 0,
        "startoff": 0,
        "endoff": 0,
        "startoff2": 0,
        "endoff2": 0,
        "offs": 0,
        "outtext1": "ON",
        "outtext2": "OFF",
        "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,
        "day6": 0,
        "month6": 0,
        "day7": 0,
        "month7": 0,
        "day8": 0,
        "month8": 0,
        "day9": 0,
        "month9": 0,
        "day10": 0,
        "month10": 0,
        "day11": 0,
        "month11": 0,
        "day12": 0,
        "month12": 0,
        "d1": 0,
        "w1": 0,
        "d2": 0,
        "w2": 0,
        "d3": 0,
        "w3": 0,
        "d4": 0,
        "w4": 0,
        "d5": 0,
        "w5": 0,
        "d6": 0,
        "w6": 0,
        "xday1": 0,
        "xmonth1": 0,
        "xday2": 0,
        "xmonth2": 0,
        "xday3": 0,
        "xmonth3": 0,
        "xday4": 0,
        "xmonth4": 0,
        "xday5": 0,
        "xmonth5": 0,
        "xday6": 0,
        "xmonth6": 0,
        "xday7": 0,
        "xmonth7": 0,
        "xday8": 0,
        "xmonth8": 0,
        "xday9": 0,
        "xmonth9": 0,
        "xday10": 0,
        "xmonth10": 0,
        "xday11": 0,
        "xmonth11": 0,
        "xday12": 0,
        "xmonth12": 0,
        "xd1": 0,
        "xw1": 0,
        "xd2": 0,
        "xw2": 0,
        "xd3": 0,
        "xw3": 0,
        "xd4": 0,
        "xw4": 0,
        "xd5": 0,
        "xw5": 0,
        "xd6": 0,
        "xw6": 0,
        "suspend": false,
        "random": false,
        "randon1": false,
        "randoff1": false,
        "randon2": false,
        "randoff2": false,
        "repeat": false,
        "atstart": true,
        "odd": false,
        "even": false,
        "x": 170,
        "y": 660,
        "wires": [
            [],
            [],
            [
                "7db0e1deb0b1a2b3",
                "6610fd625e4fe130"
            ]
        ]
    },
    {
        "id": "7db0e1deb0b1a2b3",
        "type": "switch",
        "z": "37aca3e667312fac",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "on",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "off",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 330,
        "y": 660,
        "wires": [
            [
                "d5cc4cf064676528"
            ],
            [
                "f2c2c9517bc74b99"
            ]
        ]
    },
    {
        "id": "d5cc4cf064676528",
        "type": "api-call-service",
        "z": "37aca3e667312fac",
        "name": "",
        "server": "4e3730d1.5341d",
        "version": 5,
        "debugenabled": false,
        "domain": "light",
        "service": "turn_on",
        "areaId": [],
        "deviceId": [],
        "entityId": [
            "light.pc"
        ],
        "data": "",
        "dataType": "jsonata",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 490,
        "y": 640,
        "wires": [
            []
        ]
    },
    {
        "id": "f2c2c9517bc74b99",
        "type": "api-call-service",
        "z": "37aca3e667312fac",
        "name": "",
        "server": "4e3730d1.5341d",
        "version": 5,
        "debugenabled": false,
        "domain": "light",
        "service": "turn_off",
        "areaId": [],
        "deviceId": [],
        "entityId": [
            "light.pc"
        ],
        "data": "",
        "dataType": "jsonata",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 490,
        "y": 680,
        "wires": [
            []
        ]
    },
    {
        "id": "4e3730d1.5341d",
        "type": "server",
        "name": "Home Assistant",
        "addon": true,
        "rejectUnauthorizedCerts": true,
        "ha_boolean": "",
        "connectionDelay": false,
        "cacheJson": false,
        "heartbeat": false,
        "heartbeatInterval": "",
        "statusSeparator": "",
        "enableGlobalContextStore": false
    }
]

@jwadsley I’m assuming the code you just posted is not working for you? I believe your switch node should use all uppercase ON and OFF to match the output from your test node.

Correct the code posted did not work. I have updated the switch to have capitals, lets see if that does it. Appreciate your help

@MaxK It appears to be working. Thank you for taking the time to help me figure it out. I also found some documentation in the GitHub that helped…

Whether or not you use the optional Topic Msg (MQTT Topic), the first output sends out a message with the text from the ON Msg (MQTT Payload) and OFF Msg (MQTT Payload) fields at your set ON and OFF times (and if the repeat tickbox is ticked - every minute)

The second output has a topic of "status" and simply sends the state - 1 or 0 every minute as well as echoing the status in msg.state and msg.time. (from v1.5.6 onwards several properties have been added to msg)

The third output sends an optional message, ON Text and OFF Text - suitable for speech output or a log (this happens only at ON or OFF times, NOT every minute).

@jwadsley Glad it’s working for you.

BTW, you can get the documentation within node-red. If you hover your cursor over any node in the left pain in the pallet manager, a pop-out will display that gives a brief summary of the node. AND there are two small boxes on the lower right of the pop-out: click the first one for the documentation; click the second one to get a list of where you use those nodes in your flows.

For any node used in your flow, you can click on the node then click the Help tab/button on the upper right pain.
image

Thanks, learn something new every day.

Can BigTimer be used to only turn off an action? From what I’ve seen, a start time must be set, I guess if you used a switch that was only “off” that would do it?

Yes, but you might want to think about why you would do this, and a potentially better solution, before using bigtimer.

My thought was if I had another node using a different timing method like sun, range time, etc. What would be a better way to do a one way shut off?

If you just want to do something at a specific time every day, then the time node might be a better choice. Bigtimer does have other timing methods - check them out. Plus there are other time nodes (time, wait until, time range, etc.)

1 Like