[{"id":"4940f5f149be677c","type":"tab","label":"工作日、休息日判定","disabled":false,"info":"","env":[]},{"id":"cb3dab61683c7148","type":"function","z":"4940f5f149be677c","name":"判断是否节假日函数","func":"// 创建一个表示当前日期和时间的对象\nvar now = new Date();\n\n// 从now中获取当前的年份,并存储到变量year中\nlet year = now.getFullYear();\n\n// 从now中获取月份(JavaScript的月份是从0开始计数,所以加1)\nlet month = now.getMonth() + 1;\n\n// 从now中获取日期\nlet day = now.getDate();\n\n// 将year、month、day合成字符串YYYY-MM-DD,为今天日期\nlet formattedDate = `${year}-${month.toString().padStart(2, '0')}-${day.toString().padStart(2, '0')}`;\n\n// 初始化一个空字符串变量sentence\nvar sentence = "";\n\n//节假日的日期用"https://timor.tech/api/holiday/year/2024"用这个连接获取\n// 人工填写2024年节假日日期\nvar holidayArr = [\n '2024-01-01', '2024-02-04', '2024-02-10', '2024-02-11', '2024-02-12', '2024-02-13',\n '2024-02-14', '2024-02-15', '2024-02-16', '2024-02-17', '2024-02-18', '2024-04-04',\n '2024-04-05', '2024-04-06', '2024-04-07', '2024-04-28', '2024-05-01', '2024-05-02',\n '2024-05-03', '2024-05-04', '2024-05-05', '2024-05-11', '2024-06-08', '2024-06-09',\n '2024-06-10', '2024-09-14', '2024-09-15', '2024-09-16', '2024-09-17', '2024-09-29',\n '2024-10-01', '2024-10-02', '2024-10-03', '2024-10-04', '2024-10-05', '2024-10-06',\n '2024-10-07', '2024-10-12'];\n\n// 人工填写2024年调休日=工作日,即因调休而需要上班的周末日期\nvar workdayArr = [\n '2024-01-13', '2024-02-24', '2024-04-28', '2024-05-04', '2024-06-08',\n '2024-09-14', '2024-09-29', '2024-10-12'];\n\n// 判断是否为节假日: 检查“今天日期”是否在holidayArr假日数组中。在假日中,就将"sentence"变量设为"休息日"\nif (holidayArr.indexOf(formattedDate) != -1) { \n sentence = "休息日";\n \n // 判断是否为调休日:若当前日期在workdayArr调休日数组中,则为工作日\n} else if (workdayArr.indexOf(formattedDate) != -1) {\n sentence = "工作日";\n \n // 判断是否工作日:若当前是周一至周五,则为工作日。否则,设置为休息日\n} else if (now.getDay() >= 1 && now.getDay() <= 5) {\n sentence = "工作日";\n \n // 判断是否为周末:若当前是周六或周日,并且不在workdayArr调休日数组中,则为休息日\n} else if (now.getDay() === 0 || now.getDay() === 6) {\n sentence = "休息日";\n}\n\n// 将结果存储在msg.payload对象中的speak属性中\nmsg.payload = { speak: sentence };\n\n// 返回修改后的msg对象\nreturn msg;\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":600,"y":320,"wires":[["c1c4ced5077564cf","6d8dbc875f33c171"]]},{"id":"e30ecc986f8fe5f1","type":"inject","z":"4940f5f149be677c","name":"定时循环","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"0 0-6 * * *","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":410,"y":320,"wires":[["cb3dab61683c7148","9a8f45908d1cdd73"]]},{"id":"c1c4ced5077564cf","type":"debug","z":"4940f5f149be677c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":830,"y":320,"wires":[]},{"id":"6d8dbc875f33c171","type":"ha-sensor","z":"4940f5f149be677c","name":"工作日或休息日","entityConfig":"00dfe422141207c8","version":0,"state":"payload.speak","stateType":"msg","attributes":[],"inputOverride":"allow","outputProperties":[],"x":840,"y":380,"wires":[[]]},{"id":"9a8f45908d1cdd73","type":"debug","z":"4940f5f149be677c","name":"debug 245","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":580,"y":420,"wires":[]},{"id":"00dfe422141207c8","type":"ha-entity-config","z":"4940f5f149be677c","server":"9b347904.408af8","deviceConfig":"8022c011c0c13686","name":"2024工作日或休息日","version":"6","entityType":"sensor","haConfig":[{"property":"name","value":"工作日判定"},{"property":"icon","value":"mdi:briefcase"},{"property":"entity_picture","value":""},{"property":"entity_category","value":""},{"property":"device_class","value":""},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""}],"resend":true,"debugEnabled":true},{"id":"9b347904.408af8","type":"server","name":"Home Assistant","addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"时间:","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m:s.ms","enableGlobalContextStore":true},{"id":"8022c011c0c13686","type":"ha-device-config","z":"4940f5f149be677c","name":"2024工作日判定","hwVersion":"","manufacturer":"Node-RED","model":"","swVersion":""}]