[NODE-RED] TEMPO EDF via API RTE

Bonjour et bonne année,

En m’inspirant du flux de @laguiche, j’ai recréé un nouveau flux TEMPO EDF avec l’API de RTE.

1) Pour commencer, il faut s’inscrire sur le site de RTE : https://data.rte-france.com
et s’abonner à l’API TEMPO : Catalogue API - API Data RTE

2) Voici mon flux Node-Red :

[{"id":"9443ff4a5a79f131","type":"tab","label":"TEMPO-RTE vers GLADYS","disabled":false,"info":"","env":[]},{"id":"8937d0bafb92a33f","type":"function","z":"9443ff4a5a79f131","name":"set payload and headers","func":"msg.payload = \"data to post\";\nmsg.headers = {};\nmsg.headers['Authorization'] = 'Basic coller-le-TOKENBASE64-de-l-API-RTE';\nmsg.headers['Content-Type'] = 'application / x - www - form - urlencoded';\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":390,"y":100,"wires":[["d58f9fa68b1decba"]]},{"id":"d58f9fa68b1decba","type":"http request","z":"9443ff4a5a79f131","name":"appel token","method":"POST","ret":"obj","paytoqs":"ignore","url":"https://digital.iservices.rte-france.com/token/oauth/","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"headers":[],"x":610,"y":100,"wires":[["dae09d6321ce5d29"]]},{"id":"03ffe62092a6cb61","type":"debug","z":"9443ff4a5a79f131","name":"","active":true,"console":"false","complete":"false","x":1870,"y":260,"wires":[]},{"id":"dae09d6321ce5d29","type":"function","z":"9443ff4a5a79f131","name":"function 1","func":"msg.headers = {};\nmsg.headers['Authorization'] = 'Bearer ' + msg.payload.access_token;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":800,"y":100,"wires":[["5eac999b56d9fda0","7807eecd4a9aeb66","4b72e56274906e4b"]]},{"id":"7807eecd4a9aeb66","type":"http request","z":"9443ff4a5a79f131","name":"appel jour tempo","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://digital.iservices.rte-france.com/open_api/tempo_like_supply_contract/v1/tempo_like_calendars","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"headers":[],"x":1070,"y":100,"wires":[["97e55fd9a406c57f","03ffe62092a6cb61"]]},{"id":"5eac999b56d9fda0","type":"change","z":"9443ff4a5a79f131","name":"","rules":[{"t":"move","p":"headers","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1070,"y":160,"wires":[[]]},{"id":"97e55fd9a406c57f","type":"json","z":"9443ff4a5a79f131","name":"","property":"payload","action":"","pretty":false,"x":1310,"y":100,"wires":[["5d3dc23c649cbca3","1460364ea83be2ce","95af60c1a7664e0d","03ffe62092a6cb61"]]},{"id":"488fa35338e7915f","type":"mqtt out","z":"9443ff4a5a79f131","name":" gladys Bleu","topic":"Topic Bleu demain","qos":"0","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"ca0557c2.d52418","x":1910,"y":40,"wires":[]},{"id":"a76615232a02d870","type":"function","z":"9443ff4a5a79f131","name":"calcul de l'année","func":"let annee\nlet calculannee = (new Date().getMonth() + new Date().getFullYear()) - (new Date().getFullYear() + 8);\n\nif (calculannee < 0) {\n    annee = (new Date().getFullYear() - 1);\n} \nelse {\n    annee = new Date().getFullYear();\n}\n\nvar date = new Date();\n\nvar date1 = date.setDate(date.getDate() + 2);\nvar date2 = new Date (date1);\nvar yearend = date2.getFullYear();\nvar moisend = date2.getMonth() + 1;\nvar jourend = date2.getDate();\n\nlet startdate = annee + \"-09-01\";\nvar enddate = `${yearend}-${moisend}-${jourend}`;\n\n\n//msg.payload = { timestamp: startdate };\nmsg.url = \"https://digital.iservices.rte-france.com/open_api/tempo_like_supply_contract/v1/tempo_like_calendars?start_date=\" + startdate + \"T00:00:00%2B02:00&end_date=\" + enddate + \"T00:00:00%2B02:00&fallback_status=true\"\nmsg.headers = {};\nmsg.headers['Authorization'] = 'Bearer ' + msg.payload.access_token;\n\nmsg.payload = msg.url;\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":410,"y":240,"wires":[["49ce373730a4bfc3"]]},{"id":"4b72e56274906e4b","type":"delay","z":"9443ff4a5a79f131","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":180,"y":240,"wires":[["a76615232a02d870"]]},{"id":"0bdd3eca3a09213b","type":"inject","z":"9443ff4a5a79f131","name":"Manuel","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":40,"wires":[["8937d0bafb92a33f"]]},{"id":"09d5afc29e782cde","type":"function","z":"9443ff4a5a79f131","name":"nb RED","func":"msg.payload = (msg.payload.match(/RED/g) || []).length;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":880,"y":400,"wires":[["9f153afa1eaae4a9"]]},{"id":"49ce373730a4bfc3","type":"http request","z":"9443ff4a5a79f131","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"headers":[],"x":670,"y":240,"wires":[["33688a4aa2bb6411","600e888e34bea8a6","09d5afc29e782cde","d47e75f680c6f725"]]},{"id":"600e888e34bea8a6","type":"function","z":"9443ff4a5a79f131","name":"nb WHITE","func":"msg.payload = msg.payload.split(\"WHITE\").length - 1;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":890,"y":320,"wires":[["039dd45c01cbc7c1"]]},{"id":"33688a4aa2bb6411","type":"function","z":"9443ff4a5a79f131","name":"nb BLUE","func":"msg.payload = (msg.payload.match(/BLUE/g) || []).length;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":880,"y":240,"wires":[["bf4c252fdd119155"]]},{"id":"c1519db3aef99d12","type":"cronplus","z":"9443ff4a5a79f131","name":"","outputField":"payload","timeZone":"Europe/Paris","persistDynamic":false,"commandResponseMsgOutput":"output1","outputs":1,"options":[{"name":"schedule1","topic":"topic1","payloadType":"default","payload":"","expressionType":"cron","expression":"0 41 10 * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":140,"y":100,"wires":[["8937d0bafb92a33f"]]},{"id":"2c10d6625989aaf3","type":"mqtt out","z":"9443ff4a5a79f131","name":" gladys Blanc","topic":"Topic Blanc demain","qos":"0","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"ca0557c2.d52418","x":1910,"y":100,"wires":[]},{"id":"69354c4743b03048","type":"mqtt out","z":"9443ff4a5a79f131","name":" gladys Rouge","topic":"Topic Rouge demain","qos":"0","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"ca0557c2.d52418","x":1920,"y":160,"wires":[]},{"id":"5d3dc23c649cbca3","type":"function","z":"9443ff4a5a79f131","name":"BLUE","func":"if (msg.payload.tempo_like_calendars.values[0].value == \"BLUE\") {\n    msg.payload = 1;\n} \nelse {\n    msg.payload = 0;\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1510,"y":40,"wires":[["488fa35338e7915f"]]},{"id":"1460364ea83be2ce","type":"function","z":"9443ff4a5a79f131","name":"WHITE","func":"if (msg.payload.tempo_like_calendars.values[0].value == \"WHITE\") {\n    msg.payload = 1;\n} \nelse {\n    msg.payload = 0;\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1520,"y":100,"wires":[["2c10d6625989aaf3"]]},{"id":"95af60c1a7664e0d","type":"function","z":"9443ff4a5a79f131","name":"RED","func":"if (msg.payload.tempo_like_calendars.values[0].value == \"RED\") {\n    msg.payload = 1;\n} \nelse {\n    msg.payload = 0;\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1510,"y":160,"wires":[["69354c4743b03048"]]},{"id":"bf4c252fdd119155","type":"mqtt out","z":"9443ff4a5a79f131","name":" gladys nb Bleu","topic":"Topic nb bleu","qos":"0","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"ca0557c2.d52418","x":1180,"y":240,"wires":[]},{"id":"039dd45c01cbc7c1","type":"mqtt out","z":"9443ff4a5a79f131","name":" gladys nb Blanc","topic":"nb blanc","qos":"0","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"ca0557c2.d52418","x":1180,"y":320,"wires":[]},{"id":"9f153afa1eaae4a9","type":"mqtt out","z":"9443ff4a5a79f131","name":" gladys nb Rouge","topic":"Topic nb rouge","qos":"0","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"ca0557c2.d52418","x":1190,"y":400,"wires":[]},{"id":"29e1b49f36fe51e7","type":"inject","z":"9443ff4a5a79f131","name":"Manuel","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":110,"y":620,"wires":[["3593abd5f6c0910b"]]},{"id":"85305e19bc990be1","type":"http request","z":"9443ff4a5a79f131","name":"","method":"GET","ret":"txt","paytoqs":false,"url":"","persist":false,"authType":"","senderr":false,"headers":[],"x":990,"y":520,"wires":[["06d47e93c0786904"]]},{"id":"14392aea6cc55850","type":"cronplus","z":"9443ff4a5a79f131","name":"","outputField":"payload","timeZone":"Europe/Paris","persistDynamic":false,"commandResponseMsgOutput":"output1","outputs":1,"options":[{"name":"schedule1","topic":"topic1","payloadType":"default","payload":"","expressionType":"cron","expression":"0 00 6 * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":140,"y":520,"wires":[["3593abd5f6c0910b"]]},{"id":"3593abd5f6c0910b","type":"function","z":"9443ff4a5a79f131","name":"set payload and headers","func":"msg.payload = \"data to post\";\nmsg.headers = {};\nmsg.headers['Authorization'] = 'Basic coller-le-TOKENBASE64-de-l-API-RTE';\nmsg.headers['Content-Type'] = 'application / x - www - form - urlencoded';\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":350,"y":520,"wires":[["92777f4ec2800db6"]]},{"id":"92777f4ec2800db6","type":"http request","z":"9443ff4a5a79f131","name":"appel token","method":"POST","ret":"obj","paytoqs":"ignore","url":"https://digital.iservices.rte-france.com/token/oauth/","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"headers":[],"x":570,"y":520,"wires":[["b866d32a33207c51"]]},{"id":"06d47e93c0786904","type":"json","z":"9443ff4a5a79f131","name":"","property":"payload","action":"","pretty":false,"x":1210,"y":520,"wires":[["aac03e8e1d9a0feb","95623376d5200efa","f3075f1ca23c7acf"]]},{"id":"b866d32a33207c51","type":"function","z":"9443ff4a5a79f131","name":"function 3","func":"var date = new Date();\n\nvar yearstart = date.getFullYear();\nvar moisstart = date.getMonth() + 1;\nvar jourstart = date.getDate();\n\nvar date1 = date.setDate(date.getDate() + 2);\nvar date2 = new Date (date1);\nvar yearend = date2.getFullYear();\nvar moisend = date2.getMonth() + 1;\nvar jourend = date2.getDate();\n\nvar startdate1 = `${yearstart}-${moisstart}-${jourstart}`;\nvar enddate1 = `${yearend}-${moisend}-${jourend}`;\n\nmsg.url = \"https://digital.iservices.rte-france.com/open_api/tempo_like_supply_contract/v1/tempo_like_calendars?start_date=\" + startdate1 + \"T00:00:00%2B02:00&end_date=\" + enddate1 + \"T00:00:00%2B02:00\"\nmsg.headers = {};\nmsg.headers['Authorization'] = 'Bearer ' + msg.payload.access_token;\n\nmsg.payload = msg.url;\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":780,"y":520,"wires":[["85305e19bc990be1"]]},{"id":"87c3ff3821e3511c","type":"debug","z":"9443ff4a5a79f131","name":"debug 13","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":680,"y":440,"wires":[]},{"id":"397e36b34944b9da","type":"mqtt out","z":"9443ff4a5a79f131","name":" gladys Bleu auj","topic":"Topic bleu auj","qos":"0","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"ca0557c2.d52418","x":1820,"y":460,"wires":[]},{"id":"253244c923c4fc5e","type":"mqtt out","z":"9443ff4a5a79f131","name":" gladys Blanc auj","topic":"Topic blanc auj","qos":"0","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"ca0557c2.d52418","x":1820,"y":520,"wires":[]},{"id":"917a6cc7692eb152","type":"mqtt out","z":"9443ff4a5a79f131","name":" gladys Rouge","topic":"Topic rouge auj","qos":"0","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"ca0557c2.d52418","x":1820,"y":580,"wires":[]},{"id":"aac03e8e1d9a0feb","type":"function","z":"9443ff4a5a79f131","name":"BLUE","func":"if (msg.payload.tempo_like_calendars.values[0].value == \"BLUE\") {\n    msg.payload = 1;\n} \nelse {\n    msg.payload = 0;\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1550,"y":460,"wires":[["397e36b34944b9da"]]},{"id":"95623376d5200efa","type":"function","z":"9443ff4a5a79f131","name":"WHITE","func":"if (msg.payload.tempo_like_calendars.values[0].value == \"WHITE\") {\n    msg.payload = 1;\n} \nelse {\n    msg.payload = 0;\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1560,"y":520,"wires":[["253244c923c4fc5e"]]},{"id":"f3075f1ca23c7acf","type":"function","z":"9443ff4a5a79f131","name":"RED","func":"if (msg.payload.tempo_like_calendars.values[0].value == \"RED\") {\n    msg.payload = 1;\n} \nelse {\n    msg.payload = 0;\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1550,"y":580,"wires":[["917a6cc7692eb152"]]},{"id":"d47e75f680c6f725","type":"json","z":"9443ff4a5a79f131","name":"","property":"payload","action":"","pretty":false,"x":650,"y":360,"wires":[["87c3ff3821e3511c"]]},{"id":"ca0557c2.d52418","type":"mqtt-broker","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

Entrer le token (bouton base64 sur la page de l’api quand vous êtes connecté à votre session RTE) dans les deux noeuds « set payload and headers ».

3) Gladys Dans Gladys, j’ai un peu bidouiller pour arriver à ça :

4) Scènes Grâce à ce flux, on peut avoir des notifications via telegram ou faire claquer des relais.

Conclusion : ça fait le taf mais ça reste du bricolage. Comme vous l’avez constaté, j’ai un niveau code de CM2 mais avec node-red on peut facilement récupérer des infos d’API. Finalement, le moins propre est l’intégration dans Gladys, et je me disais que ça serait pas mal de pouvoir intégrer les données MQTT dans des box personnalisées type « ecowatt ».
Pour la couleur du jour, il vaut mieux être connecté entre gladys et un TIC Linky car je ne suis pas certain que la bascule soit 6H tout pile tous les jours

1 Like

Super tuto, merci @Fabic !

Effectivement c’est toujours mieux quand c’est fait en natif, après là ça fait le boulot :slight_smile:

Merci @pierre-gilles .
Si j’ai bien compris le live de mardi, le service écowatt fait appel à une API qui est interrogée par gladys plus. Ensuite gladys plus fournit les données à toutes les instances gladys. Donc est-ce que ça veut dire que gladys plus à un compte chez le fournisseur de données qui lui donne un (seul) token pour interroger l’API ?

Si c’est le cas, c’est vraiment cool comme fonctionnement car pas besoin d’un nouveau compte ou de jouer avec des clés d’API pour l’utilisateur final.
Dans ce cas ça vaudrait vraiment le coup pour le service TEMPO que je tente une copie du service ecowatt car le fonctionnement est quasi identique avec une seule interrogation par jour et des données valables pour tout le monde.

D’ailleurs, ton fournisseur de données pour ecowatt, ça ne serait pas RTE : Catalogue API - API Data RTE

Oui c’est le cas !

oui !