Cette phrase :
Car dans le code, seule l’entité sensor.date
est pré-requis.
@j5lien, peut être remplacer sensor.date
par now().strftime("%Y-%m-%d")
pour ne plus avoir de dépendance ?
ce qui donne :
# Vaccination Doctolib
- platform: rest
resource_template: >-
{{
'https://www.doctolib.fr/availabilities.json?'
~ 'start_date=' ~ now().strftime("%Y-%m-%d")
~ '&visit_motive_ids=2622608'
~ '&agenda_ids=424738'
~ '&practice_ids=170990'
~ '&insurance_sector=public'
~ '&destroy_temporary=true'
~ '&limit=7'
}}
method: GET
name: Vaccination available slots Arena - temp
value_template: "{{ value_json.total }}"
scan_interval: 60
timeout: 10
unit_of_measurement: appointments
json_attributes:
- next_slot
- availabilities
- reason
- message
Comme le dit @JournaldeThomas , il faut l’une des dernière version pour cela ( 2021.4 je crois).
Si tu es en ancienne, tu peux l’écrire ainsi :
binary_sensor:
- platform: template
sensors:
appointment_available_arena:
friendly_name: "Appointment available Arena"
value_template: >-
{%- set days = state_attr('sensor.vaccination_available_slots_arena', 'availabilities') -%}
{%- set max_date = (now() + timedelta(days=2)).replace(hour=0, minute=0, second=0, microsecond=0)|as_timestamp -%}
{%- set ns = namespace() -%}
{%- set ns.slots = [] -%}
{%- for day in days if day.slots|length > 0 -%}
{%- set ns.slots =
ns.slots +
day.slots|map(attribute='start_date')|map('as_timestamp')|select('<', max_date)|list
-%}
{%- endfor -%}
{{ ns.slots|length > 0 }}
attribute_templates:
days: >-
{%- set days = state_attr('sensor.vaccination_available_slots_arena', 'availabilities') -%}
{%- set max_date = (now() + timedelta(days=2)).replace(hour=0, minute=0, second=0, microsecond=0)|as_timestamp -%}
{%- set ns = namespace() -%}
{%- set ns.days = [] -%}
{%- for day in days if day.slots|length > 0 -%}
{%- set slots = day.slots
|map(attribute='start_date')
|map('as_timestamp')
|select('<', max_date)
|map('timestamp_custom', '%H:%M', true)
|list
-%}
{%- if slots|length > 0 -%}
{%- set ns.days = ns.days + [{
"date": day.date,
"slots": slots
}] -%}
{%- endif -%}
{%- endfor -%}
{{ ns.days }}