[NODE-RED] TEMPO EDF via RTE API

Hello and happy new year,

Inspired by @laguiche’s feed, I recreated a new TEMPO EDF feed using RTE’s API.

1) To get started, you need to register on RTE’s website: https://data.rte-france.com
and subscribe to the TEMPO API: Catalogue API - API Data RTE

2) Here is my Node-Red flow:

[{"id":"9443ff4a5a79f131","type":"tab","label":"TEMPO-RTE to 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":"token call","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":"tempo day call","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 Blue","topic":"Topic Blue tomorrow","qos":"0","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"ca0557c2.d52418","x":1910,"y":40,"wires":[]},{"id":"a76615232a02d870","type":"function","z":"9443ff4a5a79f131","name":"year calculation","func":"let year\nlet yearCalculation = (new Date().getMonth() + new Date().getFullYear()) - (new Date().getFullYear() + 8);\n\nif (yearCalculation < 0) {\n    year = (new Date().getFullYear() - 1);\n} \nelse {\n    year = 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 = year + \"-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":"Manual","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":"number of 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":"number of 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":"number of 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 White","topic":"Topic White tomorrow","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 Red","topic":"Topic Red tomorrow","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 number of Blue","topic":"Topic number of blue","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 number of White","topic":"number of white","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 number of Red","topic":"Topic number of Red","qos":"0","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"ca0557c2.d52418","x":1180,"y":400,"wires":[]}]Enter the token (base64 button on the API page when you are logged into your RTE session) in both "set payload and headers" nodes.

**3) Gladys** In Gladys, I had to tinker a bit to get this:
![image|471x500](upload://obvPOnzW6zdllptviJJapwMr1sw.png)

**4) Scenes** Thanks to this flow, we can have notifications via Telegram or trigger relays.

Conclusion: It does the job but it's still a bit of a hack. As you can see, I have a coding level of a 5th grader, but with Node-RED, you can easily retrieve information from APIs. Ultimately, the least clean part is the integration into Gladys, and I was thinking it would be great to be able to integrate MQTT data into custom boxes like "ecowatt". For the color of the day, it's better to be connected between Gladys and a Linky TIC because I'm not sure that the switch is exactly 6:00 every day.

Great tutorial, thanks @Fabic!

Indeed it’s always better when it’s done natively, but this does the job :slight_smile:

Thanks @pierre-gilles.

If I understood Tuesday’s live correctly, the écowatt service calls an API that is queried by gladys plus. Then gladys plus provides the data to all gladys instances. So does that mean that gladys plus has an account with the data provider that gives it a (single) token to query the API?

If that’s the case, that’s really cool as an approach because there’s no need for a new account or to mess with API keys for the end user.
In that case it would really be worth it for the TEMPO service that I’m trying to copy from the écowatt service because the operation is almost identical, with only one query per day and data valid for everyone.

By the way, your data provider for écowatt wouldn’t happen to be RTE: Catalogue API - API Data RTE

Yes, that’s the case!

yes!

Hello, Fabic
just to say thank you for this tutorial, I further adapted your flow for my use in my Victron inverter.
I was using the EDF API which is down for the dynamic management of the inverter.
I’m waiting for the first red days to see if my porting works
See you