Guest User

'fixed' brightness Node red

a guest
Jun 22nd, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 7.89 KB | None | 0 0
  1. [{"id":"9c415ffe.b87e8","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":"800f9653.0fe9e8"}]}],"out":[{"x":620,"y":60,"wires":[{"id":"6666fe70.8e43f","port":0}]},{"x":620,"y":140,"wires":[{"id":"6666fe70.8e43f","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":"28a2f39f.34c46c","port":0}]}},{"id":"6666fe70.8e43f","type":"function","z":"9c415ffe.b87e8","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":"81eacda7.95fed","type":"inject","z":"9c415ffe.b87e8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":170,"y":200,"wires":[["28a2f39f.34c46c"]]},{"id":"28a2f39f.34c46c","type":"function","z":"9c415ffe.b87e8","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":"800f9653.0fe9e8","type":"function","z":"9c415ffe.b87e8","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":[["6666fe70.8e43f"],["28a2f39f.34c46c"]]},{"id":"59f41da4.f64cb4","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"7d2db12d.baf51","type":"api-call-service","z":"59f41da4.f64cb4","name":"payload light","server":"37d68302.2aabcc","version":1,"debugenabled":false,"service_domain":"","service":"","entityId":"light.tasmota76","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":450,"y":340,"wires":[[]]},{"id":"9365076f.e60e18","type":"api-call-service","z":"59f41da4.f64cb4","name":"payload light","server":"37d68302.2aabcc","version":1,"debugenabled":false,"service_domain":"","service":"","entityId":"light.tasmota62_1","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":450,"y":400,"wires":[[]]},{"id":"1ddad9e8.065666","type":"bigtimer","z":"59f41da4.f64cb4","outtopic":"morning","outpayload1":"turn_on","outpayload2":"turn_off","name":"Weekdays SunRise +- 01hr","comment":"","lat":"51.831092","lon":"4.335460","starttime":"5003","endtime":"5003","starttime2":0,"endtime2":0,"startoff":"-60","endoff":"+60","startoff2":0,"endoff2":0,"offs":0,"outtext1":"on","outtext2":"off","timeout":1440,"sun":false,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":false,"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,"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,"repeat":false,"atstart":false,"odd":false,"even":false,"x":320,"y":180,"wires":[["8b79fb9f.fef338"],[],[]]},{"id":"7c7117e6.20ab48","type":"function","z":"59f41da4.f64cb4","name":"light_bar","func":"if ( msg.payload == \"turn_on\" )\n{\n msg.payload = {\n domain: \"light\",\n service: msg.payload,\n data: {\n entity_id: \"light.tasmota62_1\",\n \"brightness_pct\": 25\n }\n };\n}\nelse\n{\n msg.payload = {\n domain: \"light\",\n service: msg.payload,\n data: {\n entity_id: \"light.tasmota62_1\"\n }\n };\n}\n\n\nreturn msg;\n","outputs":1,"noerr":0,"x":280,"y":400,"wires":[["9365076f.e60e18"]]},{"id":"38cdf8b3.933ef8","type":"function","z":"59f41da4.f64cb4","name":"light_kitchen","func":"if ( msg.payload == \"turn_on\" )\n{\n msg.payload = {\n domain: \"light\",\n service: msg.payload,\n data: {\n entity_id: \"light.tasmota76\",\n \"brightness_pct\": 25\n }\n };\n}\nelse\n{\n msg.payload = {\n domain: \"light\",\n service: msg.payload,\n data: {\n entity_id: \"light.tasmota76\"\n }\n };\n}\n\n\nreturn msg;\n","outputs":1,"noerr":0,"x":290,"y":340,"wires":[["7d2db12d.baf51"]]},{"id":"8b79fb9f.fef338","type":"subflow:9c415ffe.b87e8","z":"59f41da4.f64cb4","name":"09:00-14:30 MoTuWeThFr","env":[{"name":"start","value":"06:00","type":"str"},{"name":"stop","value":"08:30","type":"str"},{"name":"days","value":"[1,2,3,4,5]","type":"json"}],"x":320,"y":260,"wires":[["38cdf8b3.933ef8","7c7117e6.20ab48"],[]]},{"id":"37d68302.2aabcc","type":"server","z":"","name":"Home Assistant"}]
Add Comment
Please, Sign In to add comment