Je partage mon flux réalisé à partir de api-couleur-tempo.fr et non directement de l’API RTE. Ce site simplifie légèrement la mise en oeuvre car il ne nécessite pas de compte utilisateur ni de token.
[{"id":"707bfa6aa3b4b4a0","type":"tab","label":"EDF","disabled":false,"info":"","env":[]},{"id":"e2891a8732bb9133","type":"inject","z":"707bfa6aa3b4b4a0","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"},{"p":"delay","v":"900000","vt":"num"},{"p":"max_retries","v":"3","vt":"num"}],"repeat":"3600","crontab":"","once":true,"onceDelay":"1","topic":"","payload":"","payloadType":"date","x":110,"y":40,"wires":[["2a647c1378e02aad"]]},{"id":"4cf442c77ec8cdd2","type":"inject","z":"707bfa6aa3b4b4a0","name":"06:01","props":[{"p":"payload"},{"p":"topic","vt":"str"},{"p":"delay","v":"300000","vt":"num"},{"p":"max_retries","v":"2","vt":"num"}],"repeat":"","crontab":"01 06 * * *","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":120,"wires":[["2a647c1378e02aad"]]},{"id":"c4929c1aa960a163","type":"inject","z":"707bfa6aa3b4b4a0","name":"22:01","props":[{"p":"payload"},{"p":"topic","vt":"str"},{"p":"delay","v":"300000","vt":"num"},{"p":"max_retries","v":"2","vt":"num"}],"repeat":"","crontab":"01 22 * * *","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":160,"wires":[["2a647c1378e02aad"]]},{"id":"32c5ddfda06248b5","type":"inject","z":"707bfa6aa3b4b4a0","name":"00:01","props":[{"p":"payload"},{"p":"topic","vt":"str"},{"p":"delay","v":"300000","vt":"num"},{"p":"max_retries","v":"2","vt":"num"}],"repeat":"","crontab":"01 00 * * *","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":80,"wires":[["2a647c1378e02aad"]]},{"id":"4fe5995075ba4b7d","type":"http request","z":"707bfa6aa3b4b4a0","name":"Jours Tempo","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://www.api-couleur-tempo.fr/api/joursTempo?dateJour[]={{{dateJ0}}}&dateJour[]={{{dateJ1}}}","tls":"45b6751b593261a4","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":650,"y":160,"wires":[["402b7715133ee8e0"]]},{"id":"5631cadcbd636f8b","type":"function","z":"707bfa6aa3b4b4a0","name":"TEMPO J0","func":"let codeJour;\n\nif (msg.payload[0].dateJour == msg.dateJ0) {\n codeJour = msg.payload[0].codeJour;\n} else if (msg.payload[1].dateJour == msg.dateJ0) {\n codeJour = msg.payload[1].codeJour;\n}\n\nswitch (codeJour) {\n case 1:\n node.status({ fill: \"blue\", shape: \"dot\", text: \"BLEU \" + msg.dateJ0 });\n msg.payload = 1;\n break;\n case 2:\n node.status({ fill: \"grey\", shape: \"dot\", text: \"BLANC \" + msg.dateJ0 });\n msg.payload = 2;\n break;\n case 3:\n node.status({ fill: \"red\", shape: \"dot\", text: \"ROUGE \" + msg.dateJ0 });\n msg.payload = 3;\n break;\n default:\n node.status({ fill: \"yellow\", shape: \"dot\", text: \"??? \" + msg.dateJ0 });\n msg.payload = 0;\n}\n\nmsg.topic = \"EDF/Tempo/J0\"\n\nreturn msg;\n","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":1170,"y":160,"wires":[["011a36635ecfecb5","aa3e8abc38212466"]]},{"id":"fe4269e1a6936a4c","type":"function","z":"707bfa6aa3b4b4a0","name":"TEMPO J1","func":"const date = new Date();\nlet codeJour = 0;\n\n// Toujours incertain entre 6 et 11h\nif (date.getHours() >= 11 || date.getHours() < 6) {\n if (msg.payload[1].dateJour == msg.dateJ1) {\n codeJour = msg.payload[1].codeJour;\n } else if (msg.payload[0].dateJour == msg.dateJ1) {\n codeJour = msg.payload[0].codeJour;\n }\n}\n\nswitch (codeJour) {\n case 1:\n node.status({ fill: \"blue\", shape: \"dot\", text: \"BLEU \" + msg.dateJ1 });\n msg.payload = 1;\n break;\n case 2:\n node.status({ fill: \"grey\", shape: \"dot\", text: \"BLANC \" + msg.dateJ1 });\n msg.payload = 2;\n break;\n case 3:\n node.status({ fill: \"red\", shape: \"dot\", text: \"ROUGE \" + msg.dateJ1 });\n msg.payload = 3;\n break;\n default:\n node.status({ fill: \"yellow\", shape: \"dot\", text: \"??? \" + msg.dateJ1 });\n msg.payload = 0;\n}\n\nmsg.topic = \"EDF/Tempo/J1\"\n\nreturn msg;\n","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":1170,"y":220,"wires":[["0da0154f82762fb3","aa3e8abc38212466"]]},{"id":"2a647c1378e02aad","type":"function","z":"707bfa6aa3b4b4a0","name":"Horaire, Dates","func":"const date = new Date();\nlet hours = date.getHours();\nlet tz, time, dateJ0, dateJ1;\n\n// set date as it is UTC\ntz = -date.getTimezoneOffset();\ntime = date.getTime();\ndate.setTime(time+tz*60*1000);\n\nmsg.topic = 'EDF/Horaire';\n\n// Toutes les journées TEMPO commencent par la période des heures pleines suivie de la période des heures creuses (PM suivi de AM)\nif (hours >= 6 && hours < 22) {\n // 0: Heures pleine\n msg.payload = 0;\n node.status({ fill: \"grey\", shape: \"dot\", text: \"HP\" });\n} else {\n if (hours >= 22) {\n // 1: Heures creuses avant minuit (PM)\n msg.payload = 1;\n node.status({ fill: \"grey\", shape: \"ring\", text: \"HC (PM)\" });\n } else {\n // 2: Heures creuses après minuit (AM)\n msg.payload = 2;\n time = date.getTime() - 24*60*60*1000;\n date.setTime(time);\n node.status({ fill: \"grey\", shape: \"ring\", text: \"HC (AM)\" });\n }\n}\n\nmsg.dateJ0 = date.toISOString().substring(0,10);\ntime = date.getTime() + 24*60*60*1000;\ndate.setTime(time);\nmsg.dateJ1 = date.toISOString().substring(0,10);\n\nmsg.retry_counter = 0;\n\nreturn msg;\n","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":300,"y":100,"wires":[["8e44b1d098f935be","011a36635ecfecb5","aa3e8abc38212466"]]},{"id":"402b7715133ee8e0","type":"switch","z":"707bfa6aa3b4b4a0","name":"Status","property":"statusCode","propertyType":"msg","rules":[{"t":"eq","v":"200","vt":"num"},{"t":"neq","v":"200","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":810,"y":160,"wires":[["320c09a35b6ec042"],["24814366eaf3546b"]]},{"id":"24814366eaf3546b","type":"switch","z":"707bfa6aa3b4b4a0","name":"Max retries","property":"retry_counter","propertyType":"msg","rules":[{"t":"gte","v":"max_retries","vt":"msg"},{"t":"lt","v":"max_retries","vt":"msg"}],"checkall":"false","repair":false,"outputs":2,"x":970,"y":220,"wires":[["5631cadcbd636f8b","fe4269e1a6936a4c"],["bc797ae25448c924"]]},{"id":"bc797ae25448c924","type":"function","z":"707bfa6aa3b4b4a0","name":"Increment","func":"msg.retry_counter++;\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":180,"y":220,"wires":[["e85d605a35908c82"]]},{"id":"e85d605a35908c82","type":"delay","z":"707bfa6aa3b4b4a0","name":"Delay","pauseType":"delayv","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":330,"y":220,"wires":[["8e44b1d098f935be"]]},{"id":"8e44b1d098f935be","type":"function","z":"707bfa6aa3b4b4a0","name":"Counter","func":"node.status({fill:\"grey\", shape:\"dot\", text: msg.retry_counter + \" / \" + msg.max_retries});\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":160,"wires":[["4fe5995075ba4b7d"]]},{"id":"320c09a35b6ec042","type":"json","z":"707bfa6aa3b4b4a0","name":"JSON","property":"payload","action":"obj","pretty":false,"x":990,"y":160,"wires":[["5631cadcbd636f8b","fe4269e1a6936a4c"]]},{"id":"efa6968301e2c54d","type":"ui_text","z":"707bfa6aa3b4b4a0","group":"bae23f72ed5c5061","order":1,"width":6,"height":1,"name":"Couleur J0","label":"Maintenant","format":"{{msg.payload}}","layout":"col-center","className":"","style":false,"font":"","fontSize":16,"color":"#000000","x":1670,"y":100,"wires":[]},{"id":"2d6d4fed2f202390","type":"ui_text","z":"707bfa6aa3b4b4a0","group":"bae23f72ed5c5061","order":2,"width":6,"height":1,"name":"Couleur J1","label":"Demain (à.p.d. 6h00)","format":"{{msg.payload}}","layout":"col-center","className":"","style":false,"font":"","fontSize":16,"color":"#000000","x":1670,"y":160,"wires":[]},{"id":"011a36635ecfecb5","type":"join","z":"707bfa6aa3b4b4a0","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":" ","joinerType":"str","useparts":true,"accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1350,"y":100,"wires":[["69c76145a1b08e30"]]},{"id":"69c76145a1b08e30","type":"function","z":"707bfa6aa3b4b4a0","name":"Format","func":"var text = '';\nswitch (msg.payload['EDF/Tempo/J0']) {\n case 1: text = 'BLEU'; break;\n case 2: text = 'BLANC'; break;\n case 3: text = 'ROUGE'; break;\n default: text = '???'; \n}\n\nswitch (msg.payload['EDF/Horaire']) {\n case 0: text += ' HP'; break;\n case 1: text += ' HC (PM)'; break;\n case 2: text += ' HC (AM)'; break;\n default: text += ' ??'; \n}\n\nnode.status({ fill: \"grey\", shape: \"dot\", text: text });\n\nmsg.payload = text\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1500,"y":100,"wires":[["efa6968301e2c54d"]]},{"id":"0da0154f82762fb3","type":"function","z":"707bfa6aa3b4b4a0","name":"Format","func":"var text = '';\nswitch (msg.payload) {\n case 1: text = 'BLEU'; break;\n case 2: text = 'BLANC'; break;\n case 3: text = 'ROUGE'; break;\n default: text = '???'; \n}\n\nnode.status({ fill: \"grey\", shape: \"dot\", text: text });\n\nmsg.payload = text\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1500,"y":160,"wires":[["2d6d4fed2f202390"]]},{"id":"3979fd696f3261b0","type":"debug","z":"707bfa6aa3b4b4a0","name":"debug 17","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":640,"y":300,"wires":[]},{"id":"1fcb7cc13aea0439","type":"catch","z":"707bfa6aa3b4b4a0","name":"Exceptions","scope":null,"uncaught":true,"x":480,"y":300,"wires":[["3979fd696f3261b0","4fe5995075ba4b7d","ae1ba7def011bb85"]]},{"id":"4f972b8599dc02e4","type":"inject","z":"707bfa6aa3b4b4a0","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"},{"p":"delay","v":"1800000","vt":"num"},{"p":"max_retries","v":"12","vt":"num"}],"repeat":"","crontab":"01 12 * * *","once":true,"onceDelay":"1","topic":"","payload":"","payloadType":"date","x":110,"y":360,"wires":[["c0ec6bbb5d5cd102"]]},{"id":"ae1ba7def011bb85","type":"http request","z":"707bfa6aa3b4b4a0","name":"Jours Tempo","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://www.api-couleur-tempo.fr/api/joursTempo?periode={{{payload}}}","tls":"45b6751b593261a4","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":650,"y":420,"wires":[["caac4579b3f214b8"]]},{"id":"9ef2c0242cd044e8","type":"function","z":"707bfa6aa3b4b4a0","name":"Tempo jours par couleur","func":"var msg1 = { topic: \"EDF/Tempo/Compteurs/Bleu\", payload: 0 };\nvar msg2 = { topic: \"EDF/Tempo/Compteurs/Blanc\", payload: 0};\nvar msg3 = { topic: \"EDF/Tempo/Compteurs/Rouge\", payload: 0};\n\nfor (var item of msg.payload) {\n switch (item.codeJour) {\n case 1: msg1.payload++; break;\n case 2: msg2.payload++; break;\n case 3: msg3.payload++; break;\n }\n};\n\nnode.status({fill: \"grey\", shape: \"dot\", text: msg1.payload+\"/\"+msg2.payload+\"/\"+msg3.payload});\n\nreturn [msg1,msg2,msg3];\n","outputs":3,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":1210,"y":420,"wires":[["a0e837b0df61ef9f","aa3e8abc38212466"],["aa1b810b75929c50","aa3e8abc38212466"],["9de9958095be18df","aa3e8abc38212466"]]},{"id":"c0ec6bbb5d5cd102","type":"function","z":"707bfa6aa3b4b4a0","name":"Tempo période","func":"const date = new Date();\n\nlet day = date.getDate();\nlet month = date.getMonth() + 1;\nlet year = date.getFullYear();\n\nmsg.topic = \"EDF/Tempo/Compteurs/Periode\"\n\nif (month >= 9) {\n msg.payload = year+\"-\"+(year+1);\n} else {\n msg.payload = (year-1)+\"-\"+year;\n}\n\nnode.status({ fill: \"grey\", shape: \"ring\", text: msg.payload });\n\nmsg.retry_counter = 0;\n\nreturn msg;\n","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":300,"y":360,"wires":[["a8f2302a0457caf4","ee6a5a53b48ab846","aa3e8abc38212466"]]},{"id":"caac4579b3f214b8","type":"switch","z":"707bfa6aa3b4b4a0","name":"Status","property":"statusCode","propertyType":"msg","rules":[{"t":"eq","v":"200","vt":"num"},{"t":"neq","v":"200","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":810,"y":420,"wires":[["4e75650607404cca"],["2a07871befd4975d"]]},{"id":"2a07871befd4975d","type":"switch","z":"707bfa6aa3b4b4a0","name":"Max retries","property":"retry_counter","propertyType":"msg","rules":[{"t":"gte","v":"max_retries","vt":"msg"},{"t":"lt","v":"max_retries","vt":"msg"}],"checkall":"false","repair":false,"outputs":2,"x":970,"y":480,"wires":[[],["e956d04b0250dc23"]]},{"id":"e956d04b0250dc23","type":"function","z":"707bfa6aa3b4b4a0","name":"Increment","func":"msg.retry_counter++;\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":180,"y":480,"wires":[["cdd6af401125400f"]]},{"id":"cdd6af401125400f","type":"delay","z":"707bfa6aa3b4b4a0","name":"Delay","pauseType":"delayv","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":330,"y":480,"wires":[["a8f2302a0457caf4"]]},{"id":"a8f2302a0457caf4","type":"function","z":"707bfa6aa3b4b4a0","name":"Counter","func":"node.status({fill:\"grey\", shape:\"dot\", text: msg.retry_counter + \" / \" + msg.max_retries});\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":420,"wires":[["ae1ba7def011bb85"]]},{"id":"4e75650607404cca","type":"json","z":"707bfa6aa3b4b4a0","name":"JSON","property":"payload","action":"obj","pretty":false,"x":990,"y":420,"wires":[["9ef2c0242cd044e8"]]},{"id":"ee6a5a53b48ab846","type":"ui_text","z":"707bfa6aa3b4b4a0","group":"bae23f72ed5c5061","order":3,"width":6,"height":1,"name":"Période","label":"Période: ","format":"{{msg.payload}}","layout":"row-center","className":"","style":false,"font":"","fontSize":16,"color":"#000000","x":1660,"y":340,"wires":[]},{"id":"a0e837b0df61ef9f","type":"ui_text","z":"707bfa6aa3b4b4a0","group":"bae23f72ed5c5061","order":4,"width":2,"height":1,"name":"Bleu","label":"Bleu ","format":"{{msg.payload}}/300","layout":"col-center","className":"","style":false,"font":"","fontSize":16,"color":"#000000","x":1650,"y":380,"wires":[]},{"id":"aa1b810b75929c50","type":"ui_text","z":"707bfa6aa3b4b4a0","group":"bae23f72ed5c5061","order":5,"width":2,"height":1,"name":"Blanc","label":"Blanc","format":"{{msg.payload}}/43","layout":"col-center","className":"","style":false,"font":"","fontSize":16,"color":"#000000","x":1650,"y":420,"wires":[]},{"id":"9de9958095be18df","type":"ui_text","z":"707bfa6aa3b4b4a0","group":"bae23f72ed5c5061","order":6,"width":2,"height":1,"name":"Rouge","label":"Rouge","format":"{{msg.payload}}/22","layout":"col-center","className":"","style":false,"font":"","fontSize":16,"color":"#000000","x":1650,"y":460,"wires":[]},{"id":"aa3e8abc38212466","type":"mqtt out","z":"707bfa6aa3b4b4a0","name":"MQTT","topic":"","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"4c8b3ff1e27c2ef9","x":1650,"y":240,"wires":[]},{"id":"45b6751b593261a4","type":"tls-config","name":"no check server certificat","cert":"","key":"","ca":"","certname":"","keyname":"","caname":"","servername":"","verifyservercert":false,"alpnprotocol":""},{"id":"bae23f72ed5c5061","type":"ui_group","name":"EDF Tempo","tab":"b0a31a493b3eae92","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"4c8b3ff1e27c2ef9","type":"mqtt-broker","name":"Localhost","broker":"localhost","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"autoUnsubscribe":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closeRetain":"false","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willRetain":"false","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""},{"id":"b0a31a493b3eae92","type":"ui_tab","name":"EDF","icon":"dashboard","disabled":false,"hidden":false}]

Les ??? est normal entre 6h et 11h car le code couleur du lendemain n’est pas encore connu.
J’ai apporté quelques améliorations afin de mieux correspondre à la réalité. Le changement de code couleur se fait à 6h du matin. Même l’API RTE est foireuse sur ce détail. Par exemple, à 4h du matin, le code couleur du jour est celui applicable à partir de 6h alors qu’il faut prendre le code couleur de la veille pour connaître la situation exacte.