Set time of time-range-switch per dashboard

Hello, i'm new to Node-Red and have a question about the node-red-contrib-time-range-switch 1.0.0..
Is it possible to set the time from the dashboard instead directly in the node ?
I did found the text input node witch i can set to time picker, but how i can feed the value into the time-range-switch node ?

It cant unfortunately. That’s why I made this subflow a while back:
https://flows.nodered.org/flow/fce3ff5ca0df010ab2d4e692f2e50b4e
It doesn’t support the sunrise and sunrise events of the timerange node has but it does support day of week in addition to times.
It can be set from a message in a specified format which should be pretty easy to make from the ui output in a function node.
Id be willing to help you setting this up if you give me the output you get from the dashboard.
But have a look first and see if this could help you.
Johannes

Thank you for the subflow. It's exactly what i was looking for. I also tested your scheudler and it's also really helpfull but i think its more than i need for my project. I want a text input(time picker) field for the start and one for the endtime and maybe a textfield where i can set the days like you do (1,2,3,4,5,6,7).

When i use the timepicker i get a timestamp from milliseconds since midnight...but i have no idea how i get the HH:mm string from it. i tried it with a moment node but i always get the actual time instead of the time witch was set in the time picker.

Here is my test flow:

[{"id":"3a12fd53.03e222","type":"subflow","name":"timerange","info":"Lets through or blocks a payload\nbased on a time range. This can\neither be configured through the\nenviroment variables in the node ui\nor as described below with a message\nthat has an override topic.\nIf in range the msg will be passed\nto the first output and otherwise\nto the second.\nThe start and stop time needs\nto be defined in an hh:mm format.\nThere is also a week array. The week\nstarts on monday so 4 for example is\nThursday. Payload will only be passed\non days that are in the array.\nOut of time range payloads will\nbe redirected to the second output.\nThe schedule can be overriden by injecting\na message with the topic of \"override\"\nthat contains a ```msg.payload``` object with the\nkeys of \"start\",\"stop\",\"days\" like\nthis:\n```\n{\n    \"start\": \"10:00\",\n    \"stop\": \"14:00\",\n    \"days\": [\n        1,\n        2,\n        3,\n        4,\n        5,\n        6,\n        7\n    ]\n}\n```\nStart and stop need to be strings in the hh:mm\nformat and days an array of numbers as\ndescribed above.\nThe override can be deleted by injecting a\nmsg.payload string \"reset\".","category":"","in":[{"x":100,"y":100,"wires":[{"id":"ab39d06.842d33"}]}],"out":[{"x":620,"y":60,"wires":[{"id":"e631458f.435ff8","port":0}]},{"x":620,"y":140,"wires":[{"id":"e631458f.435ff8","port":1}]}],"env":[{"name":"start","type":"str","value":"00:00","ui":{"icon":"font-awesome/fa-arrow-right","label":{"en-US":"from hh:mm"},"type":"input","opts":{"types":["str"]}}},{"name":"stop","type":"str","value":"00:00","ui":{"icon":"font-awesome/fa-circle","label":{"en-US":"until hh:mm"},"type":"input","opts":{"types":["str"]}}},{"name":"days","type":"json","value":"[1,2,3,4,5,6,7]","ui":{"icon":"font-awesome/fa-calendar","label":{"en-US":"days"},"type":"input","opts":{"types":["json"]}}}],"color":"#C7E9C0","inputLabels":["payload input"],"outputLabels":["in time range","out of time range"],"icon":"node-red/switch.svg","status":{"x":480,"y":200,"wires":[{"id":"83bd16dd.0776e8","port":0}]}},{"id":"e631458f.435ff8","type":"function","z":"3a12fd53.03e222","name":"is in range?","func":"const schedule = flow.get(\"schedule\");\nlet start = env.get(\"start\");\nlet stop = env.get(\"stop\");\nlet days = env.get(\"days\");\nif(schedule !== undefined){\n    start = schedule.start;\n    stop = schedule.stop;\n    days = schedule.days;\n}\nconst time = new Date();\nlet day = time.getDay();\nif(day === 0) day = 7;\nlet hour = String(time.getHours());\nlet minute = String(time.getMinutes());\nif(hour.length == 1) hour = \"0\" + hour;\nif(minute.length == 1) minute = \"0\" + minute;\nconst hmtime = hour + \":\" + minute;\nif(days.includes(day)){\n    if(start == stop){\n        return [msg, null];\n    } else if(start > stop){\n        if(hmtime >= start || hmtime < stop){\n            return [msg, null];\n        } else {\n            return [null, msg];\n        }\n    } else if(hmtime >= start && hmtime < stop){\n        return [msg, null];\n    } else {\n        return [null, msg];\n    }\n} else {\n    return null;\n}","outputs":2,"noerr":0,"x":450,"y":100,"wires":[[],[]]},{"id":"bc9bfb0.50dc008","type":"inject","z":"3a12fd53.03e222","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":170,"y":200,"wires":[["83bd16dd.0776e8"]]},{"id":"83bd16dd.0776e8","type":"function","z":"3a12fd53.03e222","name":"display rule","func":"const schedule = flow.get(\"schedule\");\nif(typeof schedule == \"object\"){\n    const start = schedule.start;\n    const stop = schedule.stop;\n    const days = String(schedule.days).replace(/1/g,\"Mo\").replace(/2/g,\"Tu\").replace(/3/g,\"We\").replace(/4/g,\"Th\").replace(/5/g,\"Fr\").replace(/6/g,\"Sa\").replace(/7/g,\"Su\");\n    msg.payload = \"override: \" + start + \"-\" + stop + \"/\" + days;\n} else {\n    const start = env.get(\"start\");\n    const stop = env.get(\"stop\");\n    const days = String(env.get(\"days\")).replace(/1/g,\"Mo\").replace(/2/g,\"Tu\").replace(/3/g,\"We\").replace(/4/g,\"Th\").replace(/5/g,\"Fr\").replace(/6/g,\"Sa\").replace(/7/g,\"Su\");\n    const override = false;\n    msg.payload = start + \"-\" + stop + \"/\" + days;\n}\nreturn msg;","outputs":1,"noerr":0,"x":350,"y":200,"wires":[[]]},{"id":"ab39d06.842d33","type":"function","z":"3a12fd53.03e222","name":"check for override","func":"if(msg.topic == \"override\"){\n    flow.set(\"schedule\",msg.payload);\n    return [null, msg];\n} else if (msg.payload == \"reset\"){\n    let reset;\n    flow.set(\"schedule\",reset);\n    return [null, msg];\n} else {\n    return [msg, null];\n}","outputs":2,"noerr":0,"x":250,"y":100,"wires":[["e631458f.435ff8"],["83bd16dd.0776e8"]]},{"id":"c265dbf1.cab778","type":"mqtt in","z":"be72e3e5.8c613","name":"","topic":"esp32/output","qos":"2","datatype":"auto","broker":"96c3a6f6.bb2378","x":670,"y":240,"wires":[["ff1eb885.6ec0b8"]]},{"id":"7fcdd208.35da7c","type":"debug","z":"be72e3e5.8c613","name":"Light1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1030,"y":80,"wires":[]},{"id":"ff1eb885.6ec0b8","type":"ui_switch","z":"be72e3e5.8c613","name":"Licht1 Switch","label":"Licht 1","tooltip":"","group":"7ba4c963.6c7cf8","order":0,"width":0,"height":0,"passthru":false,"decouple":"true","topic":"esp32/output","style":"","onvalue":"light1on","onvalueType":"str","onicon":"","oncolor":"","offvalue":"light2off","offvalueType":"str","officon":"","offcolor":"","x":830,"y":240,"wires":[["3be43377.324f0c"]]},{"id":"3be43377.324f0c","type":"mqtt out","z":"be72e3e5.8c613","name":"","topic":"esp32/output","qos":"2","retain":"true","broker":"96c3a6f6.bb2378","x":1190,"y":160,"wires":[]},{"id":"ad71cd73.cf29a","type":"inject","z":"be72e3e5.8c613","name":"","topic":"","payload":"","payloadType":"date","repeat":"10","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":160,"wires":[["5b26b245.2931cc"]]},{"id":"23f9b944.232006","type":"change","z":"be72e3e5.8c613","name":"set msg.payload on","rules":[{"t":"set","p":"payload","pt":"msg","to":"light1on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":810,"y":140,"wires":[["7fcdd208.35da7c","3be43377.324f0c"]]},{"id":"90ea9a3d.3467e8","type":"change","z":"be72e3e5.8c613","name":"set msg.payload off","rules":[{"t":"set","p":"payload","pt":"msg","to":"light1off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":810,"y":180,"wires":[["7fcdd208.35da7c","3be43377.324f0c"]]},{"id":"5b26b245.2931cc","type":"moment","z":"be72e3e5.8c613","name":"","topic":"","input":"","inputType":"date","inTz":"Europe/Vienna","adjAmount":"0","adjType":"hours","adjDir":"add","format":"HH:mm","locale":"de_AT","output":"payload","outputType":"msg","outTz":"Europe/Vienna","x":340,"y":160,"wires":[["8d6579e.9856188","83559dd9.0f40c"]]},{"id":"3d8ec71f.0e9a88","type":"comment","z":"be72e3e5.8c613","name":"Light 1","info":"Control Light1 by time","x":110,"y":80,"wires":[]},{"id":"83559dd9.0f40c","type":"debug","z":"be72e3e5.8c613","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":570,"y":60,"wires":[]},{"id":"8d6579e.9856188","type":"subflow:3a12fd53.03e222","z":"be72e3e5.8c613","name":"","env":[{"name":"start","value":"18:00","type":"str"},{"name":"stop","value":"23:56","type":"str"}],"x":540,"y":160,"wires":[["23f9b944.232006"],["90ea9a3d.3467e8"]]},{"id":"4daa40e9.9a88a","type":"ui_button","z":"be72e3e5.8c613","name":"","group":"7ba4c963.6c7cf8","order":32,"width":0,"height":0,"passthru":false,"label":"save","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"save","x":110,"y":520,"wires":[["e7dfec04.55224"]]},{"id":"96b576b3.4b3c88","type":"ui_text_input","z":"be72e3e5.8c613","name":"","label":"text","tooltip":"","group":"7ba4c963.6c7cf8","order":31,"width":0,"height":0,"passthru":true,"mode":"time","delay":300,"topic":"textinput","x":110,"y":460,"wires":[["e7dfec04.55224","9464356.e2184c8"]]},{"id":"73746951.62f0d8","type":"debug","z":"be72e3e5.8c613","name":"text out","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":840,"y":500,"wires":[]},{"id":"e7dfec04.55224","type":"function","z":"be72e3e5.8c613","name":"text","func":"var lastinput = context.get(\"lastinput\") || \"\";\n\nif(msg.topic === \"textinput\"){\n    lastinput = msg.payload;\n    context.set(\"lastinput\",lastinput);\n}\nif(msg.topic === \"save\"){\n    msg.payload = lastinput;\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":370,"y":500,"wires":[["7c9948aa.717448"]]},{"id":"9464356.e2184c8","type":"debug","z":"be72e3e5.8c613","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":390,"y":460,"wires":[]},{"id":"4d7d265f.47b4d8","type":"inject","z":"be72e3e5.8c613","name":"example override schedule","topic":"override","payload":"{\"start\":\"10:00\",\"stop\":\"12:00\",\"days\":[1,2,3,4,5]}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":260,"wires":[["8d6579e.9856188","71948ffc.a3cec"]]},{"id":"71948ffc.a3cec","type":"debug","z":"be72e3e5.8c613","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":450,"y":260,"wires":[]},{"id":"7c9948aa.717448","type":"moment","z":"be72e3e5.8c613","name":"","topic":"","input":"","inputType":"date","inTz":"Europe/Vienna","adjAmount":"0","adjType":"hours","adjDir":"add","format":"HH:mm","locale":"de_AT","output":"payload","outputType":"msg","outTz":"Europe/Vienna","x":620,"y":500,"wires":[["73746951.62f0d8"]]},{"id":"96c3a6f6.bb2378","type":"mqtt-broker","z":"","name":"CHANGEME","broker":"CHANGEME","port":"1883","clientid":"CHANGEME","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"7ba4c963.6c7cf8","type":"ui_group","z":"","name":"Lampen","tab":"3517db29.1f32d4","order":1,"disp":true,"width":"6","collapse":false},{"id":"3517db29.1f32d4","type":"ui_tab","z":"","name":"Steuerung","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

Thanks for your help.

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