Get EDF Tempo information

Salut, merci pour les exemples :slight_smile:

So I tried to update the above to what seems considered “modern syntax”. It’s a bit hard to make it look like what I want, and the documentation is inconsistent.

The following can go in a rest: block. Don’t forget the rest: part.

- resource_template: https://particulier.edf.fr/bin/edf_rc/servlets/ejptemponew?Date_a_remonter={{now().strftime("%Y-%m-%d")}}&TypeAlerte=TEMPO
  scan_interval: 3600
  headers:
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
    Content-Type: application/json
    User-Agent: Wget/1.20.3 (linux-gnu)
  sensor:
    - name: "edf_tempo_today"
      device_class: monetary
      value_template: >
          {% if value_json.JourJ.Tempo in ['TEMPO_BLEU','TEMPO_BLANC','TEMPO_ROUGE'] %}
            {{ value_json.JourJ.Tempo |regex_replace(find='^TEMPO_', replace='') }}
          {% else %}
            unknown
          {% endif %}
    - name: "edf_tempo_tomorrow"
      device_class: monetary
      value_template: >
          {% if value_json.JourJ1.Tempo in ['TEMPO_BLEU','TEMPO_BLANC','TEMPO_ROUGE'] %}
            {{ value_json.JourJ1.Tempo |regex_replace(find='^TEMPO_', replace='') }}
          {% else %}
            unknown
          {% endif %}

- resource: https://particulier.edf.fr/bin/edf_rc/servlets/ejptempodaysnew?TypeAlerte=TEMPO
  scan_interval: 3600
  headers:
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
    Content-Type: application/json
    User-Agent: Wget/1.20.3 (linux-gnu)
  sensor:
        - name: edf_tempo_blue_remaining
          value_template: "{{ value_json.PARAM_NB_J_BLEU | int }}"
          unit_of_measurement: "d"
        - name: edf_tempo_white_remaining
          value_template: "{{ value_json.PARAM_NB_J_BLANC | int }}"
          unit_of_measurement: "d"
        - name: edf_tempo_red_remaining
          value_template: "{{ value_json.PARAM_NB_J_ROUGE | int }}"
          unit_of_measurement: "d"

(edit: I improved it a bit by forcing int, and detecting unknown states)

That seems to be working, but I can’t use unique_ids. I am not sure using a modern-syntax templated rest sensor is really better, but at least the version above also reduces the number of requests to one per endpoint.

Custom user-friendly names can be given trough the customization interface.

Doing only two requests was also possible with the old API, here’s one of my drafts:

Former approach with an older syntax, untested work-in-progress
- platform: rest
  #name: EDF_TEMPO_report_daily
  resource_template: https://particulier.edf.fr/bin/edf_rc/servlets/ejptemponew?Date_a_remonter={{now().strftime("%Y-%m-%d")}}&TypeAlerte=TEMPO
  json_attributes:
    - JourJ1
    - JourJ
  scan_interval: 3600
  headers:
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
    Content-Type: application/json
    User-Agent: Wget/1.20.3 (linux-gnu)
- platform: rest
  name: EDF_TEMPO_report_remaining
  resource: https://particulier.edf.fr/bin/edf_rc/servlets/ejptempodaysnew?TypeAlerte=TEMPO
  scan_interval: 3600
  json_attributes:
    - PARAM_NB_J_ROUGE
    - PARAM_NB_J_BLANC
    - PARAM_NB_J_BLEU
  headers:
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
    Content-Type: application/json
    User-Agent: Wget/1.20.3 (linux-gnu)

- platform: template
  - sensor:
    name: today
    state: >
          {% if is_state('EDF_TEMPO_report_daily', 'TEMPO_BLEU') %}
            BLEU
          {% elif is_state('EDF_TEMPO_report_daily', 'TEMPO_BLANC') %}
            BLANC
          {% elif is_state('EDF_TEMPO_report_daily', 'TEMPO_ROUGE') %}
            ROUGE
          {% else %}
            INCONNU
          {% endif %}
  - sensor:
    unique_id: blue_remaining
    state: "{{ state_attr('sensor.EDF_TEMPO_report_daily', 'PARAM_NB_J_BLEU') }}"
    name: "Jours Bleus Restant"
    unit_of_measurement: "d"
  - sensor:
    unique_id: white_remaining
    state: "{{ state_attr('sensor.EDF_TEMPO_report_daily', 'PARAM_NB_J_BLANC') }}"
    name: "Jours Blancs Restant"
    unit_of_measurement: "d"
  - sensor:
    unique_id: red_remaining
    state: "{{ state_attr('sensor.EDF_TEMPO_report_daily', 'PARAM_NB_J_ROUGE') }}"
    friendly_name: "Jours Rouges Restant"
    name: "d"
1 Like

Thank you for the coding lesson. Yes, it reduces the number of requests, and this is a good point and it is also cleaner for reading.
I will use this example to modernize my syntax. :wink:

Dear @c4rr3r4,

can you share you code for the sensor and the display?

thank you
regards

Hello.

I have succeed to retreive the TEMPO day :

https://data.rte-france.com/catalog/-/api/consumption/Tempo-Like-Supply-Contract/v1.1#

FAQ - API Data RTE and especially the PDF.

basically two steps : retreive the OATH token, the use it on the TEMPO api. As a reminder TEMPO days are set by RTE, not EDF.
I will try to reuse existing code to make it work with this API

1 Like

Hello
I discovered this huge API library on RTE website and no one seems to have integrated this in HA yet.
Can you tell how you manage to do OAUTH2 requests to RTE API in HomeAssistant ?
I have little to no knowledge about coding API calls, so RTE tutorial is of no help for getting it work with HA
Regards

Updated my code to remove device_class: date, as this now expects a python date object.

Hello, thanks all for contributions. Sorry i didn’t succeed to replace old “style” with new rest part ! it give error platform rest. what is the complete code to put on sensor file please !
Thanks a lot

code below didn’t work when i put it in an yaml file on the sensor folder.

  • resource_template: https://particulier.edf.fr/bin/edf_rc/servlets/ejptemponew?Date_a_remonter={{now().strftime("%Y-%m-%d")}}&TypeAlerte=TEMPO
    scan_interval: 3600
    headers:
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8
    Content-Type: application/json
    User-Agent: Wget/1.20.3 (linux-gnu)
    sensor:

    • name: “edf_tempo_today”
      device_class: monetary
      value_template: >
      {% if value_json.JourJ.Tempo in [‘TEMPO_BLEU’,‘TEMPO_BLANC’,‘TEMPO_ROUGE’] %}
      {{ value_json.JourJ.Tempo |regex_replace(find=’^TEMPO_’, replace=’’) }}
      {% else %}
      unknown
      {% endif %}
    • name: “edf_tempo_tomorrow”
      device_class: monetary
      value_template: >
      {% if value_json.JourJ1.Tempo in [‘TEMPO_BLEU’,‘TEMPO_BLANC’,‘TEMPO_ROUGE’] %}
      {{ value_json.JourJ1.Tempo |regex_replace(find=’^TEMPO_’, replace=’’) }}
      {% else %}
      unknown
      {% endif %}
  • resource: https://particulier.edf.fr/bin/edf_rc/servlets/ejptempodaysnew?TypeAlerte=TEMPO
    scan_interval: 3600
    headers:
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8
    Content-Type: application/json
    User-Agent: Wget/1.20.3 (linux-gnu)
    sensor:
    - name: edf_tempo_blue_remaining
    value_template: “{{ value_json.PARAM_NB_J_BLEU | int }}”
    unit_of_measurement: “d”
    - name: edf_tempo_white_remaining
    value_template: “{{ value_json.PARAM_NB_J_BLANC | int }}”
    unit_of_measurement: “d”
    - name: edf_tempo_red_remaining
    value_template: “{{ value_json.PARAM_NB_J_ROUGE | int }}”
    unit_of_measurement: “d”

  • resource_template: https://particulier.edf.fr/bin/edf_rc/servlets/ejptemponew?Date_a_remonter={{now().strftime("%Y-%m-%d")}}&TypeAlerte=TEMPO
    scan_interval: 3600
    headers:
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8
    Content-Type: application/json
    User-Agent: Wget/1.20.3 (linux-gnu)
    sensor:

    • name: “edf_tempo_today”
      device_class: monetary
      value_template: >
      {% if value_json.JourJ.Tempo in [‘TEMPO_BLEU’,‘TEMPO_BLANC’,‘TEMPO_ROUGE’] %}
      {{ value_json.JourJ.Tempo |regex_replace(find=’^TEMPO_’, replace=’’) }}
      {% else %}
      unknown
      {% endif %}
    • name: “edf_tempo_tomorrow”
      device_class: monetary
      value_template: >
      {% if value_json.JourJ1.Tempo in [‘TEMPO_BLEU’,‘TEMPO_BLANC’,‘TEMPO_ROUGE’] %}
      {{ value_json.JourJ1.Tempo |regex_replace(find=’^TEMPO_’, replace=’’) }}
      {% else %}
      unknown
      {% endif %}
  • resource: https://particulier.edf.fr/bin/edf_rc/servlets/ejptempodaysnew?TypeAlerte=TEMPO
    scan_interval: 3600
    headers:
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8
    Content-Type: application/json
    User-Agent: Wget/1.20.3 (linux-gnu)
    sensor:
    - name: edf_tempo_blue_remaining
    value_template: “{{ value_json.PARAM_NB_J_BLEU | int }}”
    unit_of_measurement: “d”
    - name: edf_tempo_white_remaining
    value_template: “{{ value_json.PARAM_NB_J_BLANC | int }}”
    unit_of_measurement: “d”
    - name: edf_tempo_red_remaining
    value_template: “{{ value_json.PARAM_NB_J_ROUGE | int }}”
    unit_of_measurement: “d”

Hello @Dartymath
It was the same for me, I was never able to transform my code with this lighter version.
So I kept what I did and just used regex_replace command to remove the “TEMPO_” text.
This is the code I’m actually use in sensor.yaml:

  - platform: rest
    name: 'Tempo Demain'
    resource_template: https://particulier.edf.fr/bin/edf_rc/servlets/ejptemponew?Date_a_remonter={{now().strftime("%Y-%m-%d")}}&TypeAlerte=TEMPO
    value_template: "{{ value_json.JourJ1.Tempo |regex_replace(find='^TEMPO_', replace='') }}"
    scan_interval: 3600
    headers:
      Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
      Content-Type: application/json
      User-Agent: Wget/1.20.3 (linux-gnu)
  - platform: rest
    name: "Tempo Aujourd'hui"
    resource_template: https://particulier.edf.fr/bin/edf_rc/servlets/ejptemponew?Date_a_remonter={{now().strftime("%Y-%m-%d")}}&TypeAlerte=TEMPO
    value_template: "{{ value_json['JourJ'].Tempo|regex_replace(find='^TEMPO_', replace='') }}"
    scan_interval: 3600
    headers:
      Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
      Content-Type: application/json
      User-Agent: Wget/1.20.3 (linux-gnu)

  - platform: rest
    name: 'Jours Rouge restants'
    resource: https://particulier.edf.fr/bin/edf_rc/servlets/ejptempodaysnew?TypeAlerte=TEMPO
    value_template: '{{ value_json.PARAM_NB_J_ROUGE }}'
    scan_interval: 3600
    headers:
      Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
      Content-Type: application/json
      User-Agent: Wget/1.20.3 (linux-gnu)
  - platform: rest
    name: 'Jours Blanc restants'
    resource: https://particulier.edf.fr/bin/edf_rc/servlets/ejptempodaysnew?TypeAlerte=TEMPO
    value_template: '{{ value_json.PARAM_NB_J_BLANC }}'
    scan_interval: 3600
    headers:
      Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
      Content-Type: application/json
      User-Agent: Wget/1.20.3 (linux-gnu)
  - platform: rest
    name: 'Jours Bleu restants'
    resource: https://particulier.edf.fr/bin/edf_rc/servlets/ejptempodaysnew?TypeAlerte=TEMPO
    value_template: '{{ value_json.PARAM_NB_J_BLEU }}'
    scan_interval: 3600
    headers:
      Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
      Content-Type: application/json
      User-Agent: Wget/1.20.3 (linux-gnu)

The scan interval is set to 3600 seconds and my IP was never banned from edf.fr site anymore.

1 Like

Thanks Patrice,
i just see that my Ip was ban this afternoon after only 5 hours !
How did you recover the possibility to connect to edf.fr ?
Thanks

If you don’t have a fixed IP, you may just restart your box to get a new IP. If it is fixed, you will have to wait few hours before you could get the service back.

Thanks Patrice, still blocked this morning i move to 14400s, will see if i recover access tomorrow ! Edf app also blocked now ! i have a fixed ip

Hello

The URL above give an error 404
https://particulier.edf.fr/bin/edf_rc/servlets/ejptemponew?Date_a_remonter=2022-06-11&TypeAlerte=TEMPO

The following seems to be working now:
https://particulier.edf.fr/services/rest/referentiel/searchTempoStore?dateRelevant=2022-6-11

1 Like

Hello jpty,

Thank you very much for the new working URL for Tempo.
Do you know if there is also the same alternative URL for EJP ?

For TEMPO, this is currently working for me :slight_smile:

Hello,
This is not the first year that the service has stopped working during the summer and then become available again.
I would recommend that you wait before making any changes.

Hello Florent

as tu réussi a intégrer cette API?
je n’arrive pas a trouver comment faire fonctionner!

Hello.

No i did not tried the RTE API, my message above is regarding the EDF API, which is working.

Hi c4rr3r4

have you find a solution to integrate the RTE Api ?
can you share you code for the sensor and the display?
thank you

Here the last code I use :

configuration.yaml

rest: !include rest.yaml

rest.yaml

- resource_template: https://particulier.edf.fr/services/rest/referentiel/searchTempoStore?dateRelevant={{now().strftime("%Y-%m-%d")}}
  scan_interval: 3600
  sensor:
    - name: "Tempo Demain"
      value_template: "{{ value_json.couleurJourJ1 }}"
    - name: "Tempo Aujourd'hui"
      value_template: "{{ value_json.couleurJourJ }}"
- resource: https://particulier.edf.fr/services/rest/referentiel/getNbTempoDays?TypeAlerte=TEMPO
  scan_interval: 3600
  sensor:
    - name: "Jours Rouge restants"
      value_template: "{{ value_json.PARAM_NB_J_ROUGE }}"
    - name: "Jours Blanc restants"
      value_template: "{{ value_json.PARAM_NB_J_BLANC }}"
    - name: "Jours Bleu restants"
      value_template: "{{ value_json.PARAM_NB_J_BLEU }}"

Using rest in place of sensors permits to get all data from one API call.

5 Likes

Hello,

L’API d’EDF n’a pas l’air fameuse et semble surtout en retard par rapport Ă  RTE (ce qui est logique car c’est eux qui dĂ©finissent la couleur du jour il me semble).

J’ai fait quelque tests et comme l’indique @Florent_Coste il est assez simple de rĂ©cuprer les infos depuis l’api RTE. En revanche il faut nĂ©cessairement faire une integration dĂ©diĂ© pour gĂ©rer l’Oauth2 il me semble.

S’il y en a qui ont de l’expĂ©rience dans l’écriture d’une intĂ©gration HA et qui veulent m’aider je veux bien essayer de coder la partie authentification et rĂ©cupĂ©ration de datas

Fred