0.106.3: Coronavirus integration (COVID-19), track the outbreak

Hi all

the solution proposed above by @scstraus works. However, the API which scrapes data from worldometers.info does not factor in that countries are ranked based on some criteria, which leads to country-specific json queries (e.g. https://covid-19-apis.herokuapp.com/update/country/23) to point towards a different country when such a displacement occurs.

The snippet below uses the all countries aggregate endpoint (https://covid-19-apis.herokuapp.com/allUpdate) and finds the correct country. So far, it appears to work. If you want to get data for another country, simply substitute ‘world’ with a country of your choice. You can also add additional attributes from the json response if that’s your thing.

rest:
  - scan_interval: 3600
    resource: https://covid-19-apis.herokuapp.com/allUpdate
    timeout: 60
    sensor:
      - name: covid_world
        json_attributes_path: '$.[?(@["Country,_Other"]=="World")]'
        json_attributes:
          - Active_Cases
          - New_Cases
          - Total_Cases
          - Total_Recovered
          - Total_Deaths
        value_template: 'Covid World'
      - name: covid_world_active_cases
        value_template: '{{ states.sensor.covid_world.attributes["Active_Cases"] | replace(",","")| int | round(0) }}'
        unit_of_measurement: '#'
      - name: covid_world_new_cases
        value_template: '{{ states.sensor.covid_world.attributes["New_Cases"] | replace(",","")| int | round(0) }}'
        unit_of_measurement: '#'
      - name: covid_world_total_cases
        value_template: '{{ states.sensor.covid_world.attributes["Total_Cases"] | replace(",","")| int | round(0) }}'
        unit_of_measurement: '#'
      - name: covid_world_total_recovered
        value_template: '{{ states.sensor.covid_world.attributes["Total_Recovered"] | replace(",","")| int | round(0) }}'
        unit_of_measurement: '#'
      - name: covid_world_total_deaths
        value_template: '{{ states.sensor.covid_world.attributes["Total_Deaths"] | replace(",","")| int | round(0) }}'
        unit_of_measurement: '#'

Combine this with the covid vaccination tracker here: COVID-19 Vaccination Tracker - #9 by Florian.Schmidt and you can have all the info you need.

3 Likes