COVID-19 Vaccination Tracker

I use the COVID-19 integration. There is publically available data on the number of vaccines given. Is it possible to add this to the integration? Some good news for once?

https://www.bloomberg.com/graphics/covid-vaccine-tracker-global-distribution/

Actually Johns Hopkins (the source for the COVID-19 tracker data) supplies this information too. So it shouldn’t be too hard.

I’ve been getting data from Johns Hopkins for some time now.

I’ve built this simple python script.
Feel free to use it (remember to replace your country’s name).
You can implement it in HA, as a command_line sensor.

import requests
import json

p = 'https://jhucoronavirus.azureedge.net/jhucoronavirus/global_vaccines.json'

page = requests.get(p)
data = json.loads(page.content)

counter = 0
def find():
    global counter
    if(data[counter]['country'] == 'Greece'):
                x = data[counter]
                doses = int(x['data']['doses_admin'])
                full = int(x['data']['raw_full_vac'])
                per = x['data']['percent_full_vac']
                percent = round(float(per),1)
                f = json.dumps({"Percent":percent,"Doses":doses,"Completed":full})
                print (f)
    else:
                counter = counter + 1
                find()
find ()

Thank you very much! Used this idea to get data for Germany.

Here are the configuration.yaml entries:

  # Corona vaccination
  - platform: rest
    name: covid_vaccination_germany
    resource: https://jhucoronavirus.azureedge.net/jhucoronavirus/global_vaccines.json
    json_attributes_path: "$.[56].data"
    json_attributes:
      - doses_admin
      - raw_full_vac
      - percent_full_vac
      - date
    value_template: 'Germany'
  - platform: template
    sensors:
      covid_germany_administered:
        value_template: '{{ states.sensor.covid_vaccination_germany.attributes["doses_admin"] | round(0) }}'
        unit_of_measurement: '#'
      covid_germany_raw_full:
        value_template: '{{ states.sensor.covid_vaccination_germany.attributes["raw_full_vac"] | round(0) }}'
        unit_of_measurement: '#'
      covid_germany_percent_full:
        value_template: '{{ states.sensor.covid_vaccination_germany.attributes["percent_full_vac"] | round(2) }}'
        unit_of_measurement: '%'

Sensor cards configuration:

cards:
  - type: sensor
    graph: line
    entity: sensor.covid_germany_administered
    icon: 'mdi:needle'
    name: Impfungen
  - type: sensor
    graph: line
    entity: sensor.covid_germany_raw_full
    name: Voll geimpft
    icon: 'mdi:needle'
  - type: sensor
    graph: line
    entity: sensor.covid_germany_percent_full
    name: Voll geimpft
    icon: 'mdi:needle'
type: vertical-stack

Getting these sensor cards in home assistant:

For anyone trying to get this working for the US you need to change json_attributes_path: "$.[56].data" to json_attributes_path: "$.[150].data" I found the object number by pasting the json from https://jhucoronavirus.azureedge.net/jhucoronavirus/global_vaccines.json into http://jsonviewer.stack.hu/ and was able to browse it in the viewer by payload and numbers. Anyone needing any other country can use the same site to explore the payload numbers

1 Like

:+1:t2: Actually Germany changed to 53 and I needed to change my YAML multiple times.

On my iPad I’m using the “search on page” function and search "country“. When I’ve found Germany the counted result minus 1 is the necessary number. :wink:

It’s my actual workaround as I didn’t had the time to find out how JSON could be checked for needed country yet. Perhaps some experts can provide us a useful hint before. :hugs:

If you paste the json from https://jhucoronavirus.azureedge.net/jhucoronavirus/global_vaccines.json into http://jsonviewer.stack.hu/ you will be able to browse it in the web viewer graphically by payload and numbers. Anyone needing any other country can use the same site to explore the payload numbers

During the last days the country position changed several times. This lead me to read some more documentation and make some more tests to find the generic way to filter a country.

Here‘s the resulting configuration.yaml:

- platform: rest
  name: covid_vaccination_germany
  resource: https://jhucoronavirus.azureedge.net/jhucoronavirus/global_vaccines.json
  json_attributes_path: '$.[?(@.country == "Germany")].data'
  json_attributes:
    - doses_admin
    - raw_full_vac
    - percent_full_vac
    - date
  value_template: 'Germany'
- platform: template
  sensors:
    covid_germany_administered:
      value_template: '{{ states.sensor.covid_vaccination_germany.attributes["doses_admin"] | round(0) }}‘
      unit_of_measurement: '#'
    covid_germany_raw_full:
      value_template: '{{ states.sensor.covid_vaccination_germany.attributes["raw_full_vac"] | round(0) }}'
      unit_of_measurement: '#'
    covid_germany_first:
      value_template: "{{ states('sensor.covid_germany_administered') | int - states('sensor.covid_germany_raw_full') | int }}"
      unit_of_measurement: '#'
    covid_germany_percent_full
      value_template: '{{ states.sensor.covid_vaccination_germany.attributes["percent_full_vac"] | round(2) }}'
      unit_of_measurement: '%'

Just replace “Germany” by any country of your choice, which is include in the JSON.

1 Like

What is number for slovenia please!

I found a solution:
json_attributes_path: '$.[?(@.country == "Slovenia")].data'

Hi,

Sorry if my comments below might be controversial or offending. I haven’t been on here long so hope it’s not taken as spam or as a bot … etc etc

If anyone has researched the true science of what is going lately it looks like the Covid Pandemic is rapidly evolving into an Endemic…

What does that mean. ?

You can now go back to your life again . Enjoy life and have some fun before you forget what fun is.

Having an actual “App” on HA just for Covid is getting into “over fear” territory if you ask me , but that’s just my opinion. You only have to turn the TV on every day to get showered but that stuff 24/7…

Do you really need (up to the nearest second) updates on your HA Dashboard, or have your lights automatically turn on when a new Covid case comes up with in the last 10 minute . Lol. Really …

There are a billion things out there trying to kill you every day…

Driving a car, riding a motorcycle, drinking alcohol, smoking, mother Nature in general… Those are more likely to statistically kill you than Covid…

Maybe this App has had its day… Just saying …. why do you have it ?

Cheers Russ