Help with Corona Scrape Sensor

you’d have to use a different method. Mine dynamically finds the closest state to your home location with the value and only outputs the whole country. You can’t modify the code to get a specific state without performing a filtered look up based on the name. I.E. heavy changes, not a simple ‘change the item in the list’ change.

but under attributes of your rest sensor I see my state…can’t I just point to these attributes directly in lovelace?

I don’t expose the values for that. The exposed values are a summation of all provinces/states. It’s not selecting a state and displaying those.

You see how closest looks like alot of code? You’d need all that code and change this line to output Confirmed.

{{ features[loc.dist.index(loc.dist | min)].Province_State }}

So you’d need to add 3 new attributes: closest_recovered, closest_deaths, etc. using the modified code.

OK I’ll play around and see what I can find, I’m just curious to see if I can pull this through.

Thanks!

How do you get the sensor.latest_available_version and sensor.installed_version ?

Since the last update of multiple entity row, the secondary_info shows relative time.
Auswahl_301
Config from my post above.

  • Change in the rest sensor
value_template: "{{ (value_json.features[0].attributes.Last_Update / 1000) | int | timestamp_local }}"
  • Change in multiple-entity-row
                secondary_info:
                  entity: sensor.corona_virus_germany
                  name: false
                  format: relative

Ok I did what you said and managed to get it to work.

1 Like

I cannot get the style part to work. Everything looks fine. Copy pasted, retyped, spaces are fine. Icon color does not chage.

So your closest algorithm isn’t working all the time, it thinks I’m located closer to another province and messed all my numbers. Will try to make a simple for loop, something like:
For x through all features
{
If province_state == myprovince
{
Features[x].province_state
}
x++
}
Need to find how to code this in Hassio…

You need to install card-mod.

use selectattr, don’t loop it.

{%- set features = state_attr('sensor.corona_virus_rest', 'features') %}
{%- set features = features | map(attribute='attributes') | list %}
{%- set province = features | selectattr('Province_State', 'eq', 'blah') | first %}
{{ province.Province_State }}
1 Like

By the way, when does this code update the data? Every hour?

Hello, I don’t think there’s data on the Johns Hopkins site on the County Level. Can someone please help me figure out how to scrape the TOTAL and DEATHS on the Santa Clara County website? Here’s the page:

https://www.sccgov.org/sites/phd/DiseaseInformation/novel-coronavirus/Pages/home.aspx

Thanks in advance for your help!

whenever the rest sensor updates. You need to add it in the entity_id field for the updates to occur because the features attribute does not get monitored for changes.

Thanks for sharing this. I got it working on my setup. How do I get it to stay up to date?

Thanks

add ‘entity_id: sensor.whatever_your_rest_sensor’ is to the template sensor.

1 Like

Can someone show what I am doing wrong here please? This rest sensor only updates if I reboot Home Assistant. I have searched and tried every solution I could find and still cannot get it to update on its own. Does the scan_interval: have to be in a different location?

Thanks

- platform: rest
  name: Kansas Corona
  resource: "https://services1.arcgis.com/0MSEUqKaxRlEPj5g/arcgis/rest/services/ncov_cases/FeatureServer/1/query?f=json&where=(Country_Region%3D%27US%27)%20AND%20(Province_State%20LIKE%27Kansas%27)&outStatistics=%5B%7B%22statisticType%22%3A%22sum%22%2C%22onStatisticField%22%3A%22Confirmed%22%2C%22outStatisticFieldName%22%3A%22Confirmed%22%7D%2C%20%7B%22statisticType%22%3A%22sum%22%2C%22onStatisticField%22%3A%22Deaths%22%2C%22outStatisticFieldName%22%3A%22Deaths%22%7D%2C%20%7B%22statisticType%22%3A%22sum%22%2C%22onStatisticField%22%3A%22Recovered%22%2C%22outStatisticFieldName%22%3A%22Recovered%22%7D%5D"
  json_attributes_path: "$.features[0].attributes"
  scan_interval: 3600  #seconds
  value_template: "{{ value_json.features[0].attributes.Confirmed }}"
  unit_of_measurement: "Confirmed"
  json_attributes:
    - Confirmed
    - Deaths
    - Recovered
  
- platform: template
  sensors: 
    kansas_corona_deaths:
      value_template: "{{ state_attr('sensor.kansas_corona', 'Deaths') }}"
      friendly_name: 'Kansas Corona Deaths'
      entity_id: 'sensor.kansas_corona'

- platform: template
  sensors: 
    kansas_corona_recovered:
      value_template: "{{ state_attr('sensor.kansas_corona', 'Recovered') }}"
      friendly_name: 'Kansas Corona Recovered'
      entity_id: 'sensor.kansas_corona'

- platform: template
  sensors: 
    kansas_corona_confirmed:
      value_template: "{{ state_attr('sensor.kansas_corona', 'Confirmed') }}"
      friendly_name: 'Kansas Corona Confirmed Cases'
      entity_id: 'sensor.kansas_corona'

the rest sensor only updates every few hours…

The Johns Hopkins website now contains COUNTY level data in the US. Does anyone know how to get the data?

I don’t know enough about the API to answer that question, maybe @Johann_Edelmuller can share how he derived the resource link.

EDIT: It looks like the field “Admin2” is County but it’s always null in my queries. Not sure how to populate that field.