Salut à tous,
J’étais tombé sur ce fil et l’API ne fonctionnait plus.
J’ai utilisé l’API https://www.api-couleur-tempo.fr/api
pour récupérer les infos, ça donne ça:
# TEMPO EDF
# Fichier custom/edf_tempo.yaml
- name: rte_today
resource: https://www.api-couleur-tempo.fr/api/jourTempo/today
scan_interval: 3600
headers:
Accept: application/json;q=0.9,image/webp,*/*;q=0.8
Content-Type: application/json
User-Agent: Wget/1.20.3 (linux-gnu)
sensor:
- unique_id: rte_tempo_today
name: Tempo couleur jour
icon: mdi:flash
value_template: >-
{% from 'edf_tempo.jinja' import tempo_day_code_to_string %}
{{ tempo_day_code_to_string(value_json.codeJour) }}
- unique_id: rte_tempo_today_price_heure_creuse
name: Prix kWh heure creuse du jour
icon: mdi:currency-eur-off
value_template: >-
{% from 'edf_tempo.jinja' import tempo_day_code_to_price_hc %}
{{ tempo_day_code_to_price_hc(value_json.codeJour) }}
- unique_id: rte_tempo_today_price_heure_pleine
name: Prix kWh heure pleine du jour
icon: mdi:currency-eur
value_template: >-
{% from 'edf_tempo.jinja' import tempo_day_code_to_price_hp %}
{{ tempo_day_code_to_price_hp(value_json.codeJour) }}
- name: rte_tomorrow
resource: https://www.api-couleur-tempo.fr/api/jourTempo/tomorrow
scan_interval: 3600
headers:
Accept: application/json;q=0.9,image/webp,*/*;q=0.8
Content-Type: application/json
User-Agent: Wget/1.20.3 (linux-gnu)
sensor:
- unique_id: rte_tempo_tomorrow
name: Tempo couleur demain
icon: mdi:flash-outline
value_template: >-
{% from 'edf_tempo.jinja' import tempo_day_code_to_string %}
{{ tempo_day_code_to_string(value_json.codeJour) }}
- name: rte_tempo_planning_bleu
resource_template: >-
{% from 'edf_tempo.jinja' import tempo_api_timeframe_param %}
https://www.api-couleur-tempo.fr/api/joursTempo?codeJour=1&periode={{ tempo_api_timeframe_param() }}
scan_interval: 3600
headers:
Accept: application/json;q=0.9,image/webp,*/*;q=0.8
Content-Type: application/json
User-Agent: Wget/1.20.3 (linux-gnu)
sensor:
- unique_id: rte_tempo_planning_bleu
name: Tempo jours bleu restant
icon: mdi:flash-outline
value_template: "{{ value_json|length }}"
- name: rte_tempo_planning_blanc
resource_template: >-
{% from 'edf_tempo.jinja' import tempo_api_timeframe_param %}
https://www.api-couleur-tempo.fr/api/joursTempo?codeJour=2&periode={{ tempo_api_timeframe_param() }}
scan_interval: 3600
headers:
Accept: application/json;q=0.9,image/webp,*/*;q=0.8
Content-Type: application/json
User-Agent: Wget/1.20.3 (linux-gnu)
sensor:
- unique_id: rte_tempo_planning_blanc
name: Tempo jours blanc restant
icon: mdi:flash
value_template: "{{ value_json|length }}"
- name: rte_tempo_planning_rouge
resource_template: >-
{% from 'edf_tempo.jinja' import tempo_api_timeframe_param %}
https://www.api-couleur-tempo.fr/api/joursTempo?codeJour=3&periode={{ tempo_api_timeframe_param() }}
scan_interval: 3600
headers:
Accept: application/json;q=0.9,image/webp,*/*;q=0.8
Content-Type: application/json
User-Agent: Wget/1.20.3 (linux-gnu)
sensor:
- unique_id: rte_tempo_planning_rouge
name: Tempo jours rouge restant
icon: mdi:flash-alert
value_template: "{{ value_json|length }}"
Avec les macros suivantes pour ne pas se répéter:
# Fichier custom_templates/edf_tempo.jinja
{#
Reload templates at
http://homeassistant.local:8123/developer-tools/service?service=homeassistant.reload_custom_templates
From: https://www.home-assistant.io/docs/configuration/templating/#reusing-templates
#}
{%- macro tempo_day_code_to_string(day_code) -%}
{%- if day_code == 1 -%}
bleu
{%- elif day_code == 2 -%}
blanc
{%- elif day_code == 3 -%}
rouge
{%- else -%}
unknown
{%- endif -%}
{%- endmacro -%}
{%- macro tempo_day_code_to_price_hc(day_code) -%}
{%- if day_code == 1 -%}
0.1296
{%- elif day_code == 2 -%}
0.1486
{%- elif day_code == 3 -%}
0.1568
{%- else -%}
unknown
{%- endif -%}
{%- endmacro -%}
{%- macro tempo_day_code_to_price_hp(day_code) -%}
{%- if day_code == 1 -%}
0.1609
{%- elif day_code == 2 -%}
0.1894
{%- elif day_code == 3 -%}
0.7562
{%- else -%}
unknown
{%- endif -%}
{%- endmacro -%}
{%- macro tempo_api_timeframe_param() -%}
{%- set month = now().strftime("%M") | int -%}
{%- if month < 9 -%}
{{ (now().strftime("%Y") | int) - 1 }}-{{ (now().strftime("%Y") | int) }}
{%- else -%}
{{ (now().strftime("%Y") | int) }}-{{ (now().strftime("%Y") | int) + 1 }}
{%- endif -%}
{%- endmacro -%}
et enfin, dans configuration.yaml
# Fetch data from RTE
multiscrape: !include custom/edf_tempo.yaml
Si ça peut aider quelqu’un