Salut, merci pour les exemples
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"