Help with Corona Scrape Sensor

sensor.yaml, the sensor section of your configuration.yaml.

Would this help? I found this and was able to pull up the State of Kansas and it list all the Counties and current stats. The card you shared above that shows distance is not working for me anymore now that more data is being collected. Mine shows 119 miles away and looking at the John Hopkins map, It’s a lot closer than that. I just don’t know anything about json queries really. Not sure if this would help with anything or not.

https://services9.arcgis.com/N9p5hsImWXAccRNI/arcgis/rest/services/Nc2JKvYFoAEOFCG5JSI6/FeatureServer/1/query?f=json&where=(Country_Region%3D'US')%20AND%20(Province_State%3D'Kansas')&returnGeometry=false&spatialRel=esriSpatialRelIntersects&outFields=*&orderByFields=Confirmed%20desc%2CCountry_Region%20asc%2CProvince_State%20asc&outSR=102100&resultOffset=0&resultRecordCount=200&cacheHint=true

Yes, it looks like it will. It has ‘Admin2’ being returned. What doesn’t make sense to me is WHY you’re getting ‘Admin2’ populated when your query doesn’t appear to request it. I’ll have to compare some things tonight when I get home.

EDIT: As for the queries they are pretty simple. There’s just a syntax to them. All the %xx’s in the URL are escaped characters because URL’s only accept specific characters. So %20 is space, and %3D is =.

1 Like

so after comparing our urls, the only difference is the starting portion of the URL and nothing about the query or data sorting is different. It seems the URL you are using is returning the extra information. What’s odd is that I cannot change the URL to another state. All other states but Kansas return invalid requests.

@iamhueman

OK last reply, Figured it out. It’s a different server. Took me a while to find it:

SO:

Basically add these together into 1 URL to make your URL

First part, this should not change for anyone, and this is only data in the US.

https://services1.arcgis.com/0MSEUqKaxRlEPj5g/arcgis/rest/services/ncov_cases_US/FeatureServer/0/query?f=json&where=

Next add this for the query to find any confirmed cases

(Confirmed%20%3E%200)

This translates to (Confirmed > 0)

Next add this to the query to find your state:

%20AND%20(Province_State%3D%27New%20York%27)

this translates to AND (Province_State='New York'). So just replace your state between the two %27's. If you have a space in your state name, replace your space with %20

Next add this to the query to find your county:

%20AND%20(Admin2%3D%27XXXXXXXX%27)

this translates to AND (Admin2='XXXXXXXX'). So just replace your state between the two %27's. If you have a space in your state name, replace your space with %20

Lasty, just add this bit to finish. I’m sure this can be shortened because this should only get a single county but I don’t feel like reverse engineering all the calls and proper variables.

&returnGeometry=false&spatialRel=esriSpatialRelIntersects&outFields=*&orderByFields=Confirmed%20desc%2CCountry_Region%20asc%2CProvince_State%20asc&outSR=102100&resultOffset=0&resultRecordCount=250&cacheHint=true

The resulting URL in this example is:

https://services1.arcgis.com/0MSEUqKaxRlEPj5g/arcgis/rest/services/ncov_cases_US/FeatureServer/0/query?f=json&where=(Confirmed%20%3E%200)%20AND%20(Province_State%3D%27New%20York%27)%20AND%20(Admin2%3D%27XXXXXXXX%27)&returnGeometry=false&spatialRel=esriSpatialRelIntersects&outFields=*&orderByFields=Confirmed%20desc%2CCountry_Region%20asc%2CProvince_State%20asc&outSR=102100&resultOffset=0&resultRecordCount=250&cacheHint=true
1 Like

Hmmm, returns…

{“objectIdFieldName”:“OBJECTID”,“uniqueIdField”:{“name”:“OBJECTID”,“isSystemMaintained”:true},“globalIdFieldName”:"",“features”:[]}

From this…

https://services1.arcgis.com/0MSEUqKaxRlEPj5g/arcgis/rest/services/ncov_cases_US/FeatureServer/0/query?f=json&where=(Confirmed%20%3E%200)%20AND%20(Province_State%3D%27Kansas%27)%20AND%20(Admin2%3D%27Kansas%27)&returnGeometry=false&spatialRel=esriSpatialRelIntersects&outFields=*&orderByFields=Confirmed%20desc%2CCountry_Region%20asc%2CProvince_State%20asc&outSR=102100&resultOffset=0&resultRecordCount=250&cacheHint=true

It didn’t find one of your attributes. So either your state or county name is incorrect.

EDIT: Looking at the url and removing the county bit, it’s clear that your county name is incorrect. Now remember, this is filtering out counties with zero confirmed.

EDIT2: There is no Kansas county in their database. So that’s ultimately your problem.

Admin2 field is where County goes?

Yes see this portion of my last post

1 Like

Thanks,
I’ll play around with it this evening, There is definitely no cases in my county and must be why it doesn’t return anything for me. I’ll try to add it to the button card you shared that shows closest cases and distance away and see if I can get it to work. I know there are cases within 40-50 miles but it still shows 119 miles.

Thanks for working on this.

If you omit the query on the county, then it should work:

https://services1.arcgis.com/0MSEUqKaxRlEPj5g/arcgis/rest/services/ncov_cases_US/FeatureServer/0/query?f=json&where=(Confirmed%20%3E%200)%20AND%20(Province_State%3D%27Kansas%27)&returnGeometry=false&spatialRel=esriSpatialRelIntersects&outFields=*&orderByFields=Confirmed%20desc%2CCountry_Region%20asc%2CProvince_State%20asc&outSR=102100&resultOffset=0&resultRecordCount=250&cacheHint=true

Also gotta remember that the site might be missing data.

1 Like

That worked, Thanks

Trying this now to see if it works on the Button Card you shared above for closest distance.

https://services1.arcgis.com/0MSEUqKaxRlEPj5g/arcgis/rest/services/ncov_cases_US/FeatureServer/0/query?f=json&where=(Confirmed%20%3E%200)%20AND%20(Country_Region%3D%27US%27)&returnGeometry=false&spatialRel=esriSpatialRelIntersects&outFields=*&orderByFields=Confirmed%20desc%2CCountry_Region%20asc%2CProvince_State%20asc&outSR=102100&resultOffset=0&resultRecordCount=250&cacheHint=true

edit: It worked! I think, it did change from 119 miles in Kansas to 66 miles in Oklahoma. Now I just got to figure out how to get this rest sensor to update. I don’t know why but this sensor does not update automatically. I have to reboot my RPI to get this to update.

image

- platform: rest
  name: Corona Virus Rest
  resource: "https://services1.arcgis.com/0MSEUqKaxRlEPj5g/arcgis/rest/services/ncov_cases_US/FeatureServer/0/query?f=json&where=(Confirmed%20%3E%200)%20AND%20(Country_Region%3D%27US%27)&returnGeometry=false&spatialRel=esriSpatialRelIntersects&outFields=*&orderByFields=Confirmed%20desc%2CCountry_Region%20asc%2CProvince_State%20asc&outSR=102100&resultOffset=0&resultRecordCount=250&cacheHint=true"
  scan_interval: 3600  #seconds
  value_template: "{{ value_json.features | length }}"
  json_attributes:
    - features

Add

entity_id: sensor.whatever_your_rest_sensor_is

at the same indentation on your template sensor.

1 Like

Its the rest sensor itself that doesn’t appear to be updating. If I just let it go and not reboot my RPI it will say show the last update 2-3 days ago. As soon as I reboot it will update and have new values for confirmed cases with a new timestamp.

I hate to keep bothering you but I am curious. On the button card, can those icons I have circled be spaced out? Is that even possible?

image

No, you can add spaces between them but it’s essentially text, not objects.

Then that means your rest sensor isn’t updating the main state and home assistant is suppressing the changes. You should be outputting the last time it was updated.

  - platform: rest
    resource: "https://services1.arcgis.com/0MSEUqKaxRlEPj5g/arcgis/rest/services/ncov_cases_US/FeatureServer/0/query?f=json&where=(Confirmed%20%3E%200)%20AND%20(Country_Region%3D%27US%27)&returnGeometry=false&spatialRel=esriSpatialRelIntersects&outFields=*&orderByFields=Confirmed%20desc%2CCountry_Region%20asc%2CProvince_State%20asc&outSR=102100&resultOffset=0&resultRecordCount=250&cacheHint=true"
    name: Corona Virus Rest
    value_template: >
      {%- set last_updated = value_json.features | map(attribute='attributes.Last_Update') | list | max / 1000 %}
      {{ last_updated | timestamp_custom('%Y-%m-%dT%H:%M:%S.%f+00:00') }}
    json_attributes:
      - features
1 Like

Petro and web experts:

Any way these maps (only) can be integrated in HA?
CALIFORNIA


MASS
https://www.wcvb.com/app/coronavirus-covid-19-in-massachusetts-data-charts/31279863

iframe card

I only need the maps. :smile: