un exemple de mes sensors
#Antony
# https://www.doctolib.fr/availabilities.json?start_date=2021-05-12&visit_motive_ids=2687950&agenda_ids=454956-468305-455745-454959-450749-450520-450523-450517-454957-436450&insurance_sector=public&practice_ids=175970&destroy_temporary=true&limit=1
# https://www.doctolib.fr/vaccination-covid-19/antony-antony
# https://www.doctolib.fr/vaccination-covid-19/antony?ref_visit_motive_ids[]=6970&ref_visit_motive_ids[]=7005&force_max_limit=2
- platform: rest
resource_template: >-
{{
'https://www.doctolib.fr/availabilities.json?'
~ 'start_date=' ~ states('sensor.date')
~ '&visit_motive_ids=2687950'
~ '&agenda_ids=454956-468305-455745-454959-450749-450520-450523-450517-454957-436450'
~ '&practice_ids=175970'
~ '&insurance_sector=public'
~ '&destroy_temporary=true'
~ '&limit=3'
}}
method: GET
name: Vaccination disponibilites Antony
value_template: "{{ value_json.total }}"
scan_interval: 60
timeout: 10
unit_of_measurement: appointments
json_attributes:
- next_slot
- availabilities
- reason
- message
#Clamart
# https://www.doctolib.fr/availabilities.json?start_date=2021-05-12&visit_motive_ids=2546765&agenda_ids=461477-466339-461481-461476&insurance_sector=public&practice_ids=164369&destroy_temporary=true&limit=4
# https://www.doctolib.fr/centre-de-sante/clamart/centre-de-vaccination-covid-de-la-ville-de-clamart?highlight%5Bspeciality_ids%5D%5B%5D=5494
- platform: rest
resource_template: >-
{{
'https://www.doctolib.fr/availabilities.json?'
~ 'start_date=' ~ states('sensor.date')
~ '&visit_motive_ids=2546765'
~ '&agenda_ids=410086-410087-466361-410085-466337-410349-466169-466339-461477-461473-461470-466336-461481-461476-410080-410083'
~ '&practice_ids=164369'
~ '&insurance_sector=public'
~ '&destroy_temporary=true'
~ '&limit=3'
}}
method: GET
name: Vaccination disponibilites Clamart
value_template: "{{ value_json.total }}"
scan_interval: 60
timeout: 10
unit_of_measurement: appointments
json_attributes:
- next_slot
- availabilities
- reason
- message
un exemple de mes binary sensors
- binary_sensor:
- name: Disponibilités Antony
state: >-
{%- set days = state_attr('sensor.Vaccination_disponibilites_Antony', '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 }}
attributes:
days: >-
{%- set days = state_attr('sensor.Vaccination_disponibilites_Antony', '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 }}
- name: Disponibilités Clamart
state: >-
{%- set days = state_attr('sensor.Vaccination_disponibilites_Clamart', '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 }}
attributes:
days: >-
{%- set days = state_attr('sensor.Vaccination_disponibilites_Clamart', '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 }}
et pour finir les notifications
- id: Covid_19_Notification_Antony
alias: "Disponibilités Vaccin Antony"
trigger:
- platform: state
entity_id: binary_sensor.Disponibilites_Antony
from: 'off'
to: 'on'
action:
- service: notify.DIFFUSION_LAURENT
data:
title: "Disponibilité Vaccin Antony à {{ now().strftime('%H:%M') }}"
message: >
{%- set days = state_attr('binary_sensor.Disponibilites_Antony', 'days') -%}
{%- for day in days -%}
{{ day.date }} :
{%- for slot in day.slots %}
- {{ slot.start_date|as_timestamp|timestamp_custom('%H:%M', true) }}
{%- endfor -%}
{%- endfor -%}
data:
color: red
sticky: 'true'
- service: notify.logfilenotify
data_template:
message: >
{{ now().strftime('%H:%M:%S') }};Disponibilité Vaccin Antony.
- id: Covid_19_Notification_Massy
alias: "Disponibilités Vaccin Massy"
trigger:
- platform: state
entity_id: binary_sensor.Disponibilites_Massy
from: 'off'
to: 'on'
action:
- service: notify.DIFFUSION_LAURENT
data:
title: "Disponibilité Vaccin Massy à {{ now().strftime('%H:%M') }}"
message: >
{%- set days = state_attr('binary_sensor.Disponibilites_Massy', 'days') -%}
{%- for day in days -%}
{{ day.date }} :
{%- for slot in day.slots %}
- {{ slot.start_date|as_timestamp|timestamp_custom('%H:%M', true) }}
{%- endfor -%}
{%- endfor -%}
data:
color: red
sticky: 'true'
- service: notify.logfilenotify
data_template:
message: >
{{ now().strftime('%H:%M:%S') }};Disponibilité Vaccin Massy.
Mon code n’est pas optimisé, j’ai dupliqué le code pour lancer des notifications pour chaque centre.
Bon courage