I currently use the Coronavirus integration for stats and it works great, but I think it’d be better if we could also get a vaccine count to go alongside it.
I’ve tried setting this up as a sensor using scrape but I’ve never done it before and I’m getting nowhere.
The data for the UK is available here (which is what I’m trying to get), taken from a list of available sources here .
I’m reading the documentation for scrape sensors and such to try get this working, however I was wondering if anyone already has a working example?
Edit: There’s also a CSV available here - I’m wondering if that’d be easier to parse for Home Assistant?
For anyone interested, I eventually noticed there’s an API to be used for this.
- platform: rest
resource: https://api.coronavirus.data.gov.uk/v1/data?filters=areaType=overview&structure={%22date%22:%22date%22,%22newPeopleVaccinatedFirstDoseByPublishDate%22:%22newPeopleVaccinatedFirstDoseByPublishDate%22,%22newPeopleVaccinatedSecondDoseByPublishDate%22:%22newPeopleVaccinatedSecondDoseByPublishDate%22,%22cumPeopleVaccinatedFirstDoseByPublishDate%22:%22cumPeopleVaccinatedFirstDoseByPublishDate%22,%22cumPeopleVaccinatedSecondDoseByPublishDate%22:%22cumPeopleVaccinatedSecondDoseByPublishDate%22}
name: Vaccinations
json_attributes_path: "$.[0]"
json_attributes:
- date
- cumPeopleVaccinatedFirstDoseByPublishDate
- cumPeopleVaccinatedSecondDoseByPublishDate
- newPeopleVaccinatedFirstDoseByPublishDate
- newPeopleVaccinatedSecondDoseByPublishDate
value_template: "{{ value_json['data'][0]['cumPeopleVaccinatedFirstDoseByPublishDate'] }}"
Here are some of the template sensors.
- platform: template
sensors:
firstdose:
friendly_name: "First Dose"
value_template: "{{ '{0:,.0f}'.format(state_attr('sensor.vaccinations', 'cumPeopleVaccinatedFirstDoseByPublishDate')) }}"
seconddose:
friendly_name: "Second Dose"
value_template: "{{ '{0:,.0f}'.format(state_attr('sensor.vaccinations', 'cumPeopleVaccinatedSecondDoseByPublishDate')) }}"
vaccinedate:
friendly_name: "Data Last Updated"
value_template: "{{ (state_attr('sensor.vaccinations', 'date')) }}"
populationfirstvaccination:
friendly_name: "Percentage received first dose"
value_template: "{{ ((state_attr('sensor.vaccinations', 'cumPeopleVaccinatedFirstDoseByPublishDate')) | float / 52632729 * 100) | round }}"
unit_of_measurement: '%'
populationsecondvaccination:
friendly_name: "Percentage received second dose"
value_template: "{{ ((state_attr('sensor.vaccinations', 'cumPeopleVaccinatedSecondDoseByPublishDate')) | float / 52632729 * 100) | round }}"
unit_of_measurement: '%'
newfirstdose:
friendly_name: "Daily Vaccinations (First dose)"
value_template: "{{ '{0:,.0f}'.format(state_attr('sensor.vaccinations', 'newPeopleVaccinatedFirstDoseByPublishDate')) }}"
newseconddose:
friendly_name: "Daily Vaccinations (Second dose)"
value_template: "{{ '{0:,.0f}'.format(state_attr('sensor.vaccinations', 'newPeopleVaccinatedSecondDoseByPublishDate')) }}"
Which I’ve formatted to look like this on the frontend
Just a basic entity card.
type: entities
entities:
- entity: sensor.vaccinedate
icon: 'mdi:update'
name: Data last published
- entity: sensor.firstdose
icon: 'mdi:needle'
name: Total received first dose
- entity: sensor.seconddose
icon: 'mdi:needle'
name: Total received second dose
- entity: sensor.newfirstdose
icon: 'mdi:counter'
name: New first doses
- entity: sensor.newseconddose
icon: 'mdi:counter'
name: New second doses
- entity: sensor.populationfirstvaccination
icon: 'mdi:account-multiple-check'
name: Percentage received first dose
- entity: sensor.populationsecondvaccination
name: Percentage fully vaccinated
icon: 'mdi:account-multiple-check'
title: COVID-19 Vaccinations UK
4 Likes
Thanks for the inspiration Tom. I’ve set up a vaccine count for my city of Philadelphia, PA based on your example.
I get the data from the City of Philadelphia’s Open Data Explorer for Covid-19 and like you, created an entity using the REST API in Home Assistant.
- platform: rest
resource: 'https://phl.carto.com/api/v2/sql?q=SELECT%20*%20FROM%20covid_vaccine_totals'
name: PHL Vaccinations
scan_interval: 3600
json_attributes_path: "$.rows[0]"
json_attributes:
- total_count
- first_dose
- second_dose
- etl_timestamp
value_template: "{{ value_json['rows'][0]['total_count'] }}"
1 Like
Cool! Glad to have helped in some fashion.
1 Like
baz123
(Brian)
March 22, 2021, 9:17pm
6
Something not quite right with the date.
[edit]
That is the date returned by the API - doesn’t match the dashboard date though.
[edit]
Obvious really, the date is the data date rather than the ‘published’ date so on the 22nd you are seeing the data from the 21st. You could not really expect it any quicker but using ‘published’ date is a little misleading.
1 Like
Agreed, this could be worded better. Sorry for the confusion.
1 Like
baz123
(Brian)
March 22, 2021, 9:45pm
8
sacredshapes:
Sorry for the confusion.
No bother. The official site doesn’t make it that clear really.
hannesbe
(Hannes Van de Vel)
March 23, 2021, 4:17am
9
Here’s something similar for Belgium.
YAML sensors:
sensor:
- platform: rest
name: COVID Vaccinatie BE - Last Updated
resource: https://covid-vaccinatie.be/api/v1/last-updated.json
value_template: '{{ value_json.result.last_updated.updated }}'
- platform: rest
name: COVID Vaccinatie BE - Administered Partially
resource: https://covid-vaccinatie.be/api/v1/administered.json
value_template: '{{ value_json.result.administered | sum(attribute="first_dose") }}'
- platform: rest
name: COVID Vaccinatie BE - Administered Fully
resource: https://covid-vaccinatie.be/api/v1/administered.json
value_template: '{{ value_json.result.administered | sum(attribute="second_dose") }}'
- platform: rest
name: COVID Vaccinatie BE - Delivered Doses
resource: https://covid-vaccinatie.be/api/v1/delivered.json
value_template: '{{ value_json.result.delivered | sum(attribute="amount") }}'
- platform: template
sensors:
covid_vaccinatie_be_administered_partially_percentage:
friendly_name: "COVID Vaccinatie BE - Administered Partially Population Percentage"
value_template: "{{ ((states('sensor.covid_vaccinatie_be_administered_partially')) | float /11492641*100) | round(1)}}"
unit_of_measurement: '%'
covid_vaccinatie_be_administered_fully_percentage:
friendly_name: "COVID Vaccinatie BE - Administered Fully Population Percentage"
value_template: "{{ ((states('sensor.covid_vaccinatie_be_administered_fully')) | float /11492641*100) | round(1) }}"
unit_of_measurement: '%'
Lovelace:
type: entities
entities:
- entity: sensor.covid_vaccinatie_be_last_updated
icon: 'mdi:update'
name: Data last published
- entity: sensor.covid_vaccinatie_be_delivered_doses
icon: 'mdi:truck-delivery'
name: Delivered doses
- entity: sensor.covid_vaccinatie_be_administered_partially
icon: 'mdi:needle'
name: Total administered partially
- entity: sensor.covid_vaccinatie_be_administered_partially_percentage
icon: 'mdi:chart-timeline-variant'
name: Percentage administered partially
- entity: sensor.covid_vaccinatie_be_administered_fully
icon: 'mdi:needle'
name: Total administered fully
- entity: sensor.covid_vaccinatie_be_administered_fully_percentage
name: Percentage administered fully
icon: 'mdi:chart-timeline-variant'
title: COVID-19 Vaccinations BE
1 Like