Exemple avec Node Red:
[{"id":"53065ee3236d9e68","type":"http request","z":"6aa76aa605dbd61c","name":"Get Auth Token","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://digital.iservices.rte-france.com/token/oauth","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[{"keyType":"other","keyValue":"content-type","valueType":"other","valueValue":"application/x-www-form-urlencoded"},{"keyType":"other","keyValue":"Authorization","valueType":"other","valueValue":"Basic XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"}],"x":280,"y":100,"wires":[["03d1692c44acbde0"]]},{"id":"1b12b159637da09c","type":"http request","z":"6aa76aa605dbd61c","name":"Get data","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://digital.iservices.rte-france.com/open_api/ecowatt/v4/signals","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[{"keyType":"other","keyValue":"Authorization","valueType":"msg","valueValue":"payload"},{"keyType":"other","keyValue":"Content-Type","valueType":"other","valueValue":"application/soap+xml;charset=UTF-8"}],"x":600,"y":100,"wires":[["994371fb027003a4"]]},{"id":"03d1692c44acbde0","type":"function","z":"6aa76aa605dbd61c","name":"Bearer Token","func":"msg.payload = msg.payload['token_type']+ ' ' + msg.payload['access_token']\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":450,"y":100,"wires":[["1b12b159637da09c"]]},{"id":"994371fb027003a4","type":"ha-sensor","z":"6aa76aa605dbd61c","name":"myecowatt2","entityConfig":"e9a719eb51690897","version":0,"state":"payload['signals'][0]['message']","stateType":"msg","attributes":[{"property":"signals","value":"payload['signals']","valueType":"msg"}],"inputOverride":"allow","outputProperties":[],"x":750,"y":100,"wires":[[]]},{"id":"8c3f9455728dfac5","type":"cronplus","z":"6aa76aa605dbd61c","name":"Every hour","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output1","outputs":1,"options":[{"name":"schedule1","topic":"topic1","payloadType":"bool","payload":"true","expressionType":"cron","expression":"0 0 0/1 * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":110,"y":100,"wires":[["53065ee3236d9e68"]]},{"id":"e9a719eb51690897","type":"ha-entity-config","server":"c4ecaf2.db61b5","deviceConfig":"","name":"myecowatt2","version":"6","entityType":"sensor","haConfig":[{"property":"name","value":"Ecowatt Node Red"},{"property":"icon","value":"mdi:lightning-bolt"},{"property":"entity_category","value":""},{"property":"device_class","value":""},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""}],"resend":false,"debugEnabled":false}]
Avec XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX à remplacer par la clé en base 64 récupérée sur le site de RTE.
Ou alors, via un script python + MQTT qui est ensuite exécuté à intervalle régulier via une entrée dans le crontab (on peut le voir comme un ecowatt2mqtt
):
#!/usr/bin/env python3
import requests
import json
import paho.mqtt.client as mqtt
host="digital.iservices.rte-france.com"
oauth_url="/token/oauth/"
ecowatt_url="/open_api/ecowatt/v4/signals"
#ecowatt_url="/open_api/ecowatt/v4/sandbox/signals"
api_key='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
token_headers = {'content-type': 'application/x-www-form-urlencoded', 'Authorization': 'Basic '+api_key}
r = requests.get('https://'+host+oauth_url, headers=token_headers)
if r.status_code != requests.codes.ok:
print("Error: failed to get Auth token: {}".format(r.status_code))
exit(1)
print("Got Auth token")
rep = r.json()
ecowatt_headers = {'Content-Type': 'application/soap+xml;charset=UTF-8', 'Authorization': 'Bearer '+rep["access_token"]}
r = requests.get('https://'+host+ecowatt_url, headers=ecowatt_headers)
if r.status_code != requests.codes.ok:
print("Error: failed to get ecowatt data: {}".format(r.status_code))
print(r.headers)
print(r.text)
exit(1)
print("Got ecowatt data")
attributes=r.json()
state=attributes['signals'][0]['message']
print(state)
attributes["icon"] = "mdi:lightning-bolt"
attributes["friendly_name"] = "Météo Enedis"
print(attributes)
client = mqtt.Client('ecowatt')
client.connect("ADRESSE IP DU SERVEUR MQTT", 1883)
sensor_t = "homeassistant/sensor/myecowatt"
config_t = sensor_t + "/config"
state_t = sensor_t + "/state"
attr_t = sensor_t + "/attributes"
config_p = '{"name": "myecowatt", "uniq_id": "myecowatt_202301161823", "stat_t": "'+state_t+'", "json_attr_t": "'+attr_t+'", "device": {"identifiers": ["MyEcowatt
"], "name": "Météo Ecowatt RTE", "model": "Ecowatt 4.0", "manufacturer": "RTE"}}'
client.publish(config_t, config_p, 1, True)
client.publish(state_t, state, 1, True)
client.publish(attr_t, json.dumps(attributes), 1, True)
client.disconnect()
Et pour le crontab une ligne du genre pour exécution toutes les 2 heures:
0 */2 * * * /home/user/ecowatt.py 1>/home/user/ecowatt.log 2>&1