Help with Corona Scrape Sensor

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:

you’d need to get a custom card that displays embedded html

Looks great! Would you mind sharing your code for the card? I am trying to get the same results for Alberta. Thanks!

Can someone tell me what i have to put in the rest url to get the UK? So far I tried uk, united_kingdom, britain, gb, great_britain, england, brexit and now i’m running out of ideas what to call that country.

It’s case sensative, so have you tried United%20Kingdom?

1 Like

Also, what URL are you using… There’s a few in this thread that are US only.

That’s it. I was only using underscore, didn’t think that they would use spaces.
:cowboy_hat_face:

I have been tracking COVID-19 cases in my county. For the last_update I am pulling this:

value_template: “1586447628000”

How can I turn this into a real date/time? I have tried some things I have seen here in this thread but just cant get it to work.

- 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(Province_State%3D%27Michigan%27)%20AND%20(Admin2%3D%27Berrien%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 Berrien
  value_template: "{{ value_json.features[0].attributes.Recovered }}"
  json_attributes_path: "$.features[0].attributes"
  json_attributes:
    - Confirmed
    - Deaths
    - Recovered
    - Last_Update
  scan_interval: 3600  #seconds

and this

- platform: template
  sensors: 
    corona_virus_berrien_last_update:
      friendly_name: 'Berrien Last Update'      
      value_template: "{{ state_attr('sensor.corona_virus_berrien', 'Last_Update') }}"

Could someone help a newbie fix this? Thanks!

pretty much any post of mine has the solution. My most recent post here…

specifically, divide the result by 1000 and apply the timestamp() provided in that post.

if anyone is interested… I’ve had to heavily modify these templates to a point so that no errors are produced in the logs, here is the outcome:

rest

  - platform: rest
    resource: !secret corona_virus_county_url
    name: Corona Virus County 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', False) }}
    json_attributes:
      - features

templates

  - platform: template
    sensors:
      corona_virus_usa:
        friendly_name: Corona Virus USA
        entity_id: sensor.corona_virus_rest
        availability_template: >
          {%- set features = state_attr('sensor.corona_virus_rest', 'features') %}
          {%- set features = features | map(attribute='attributes') | list %}
          {{ features | length > 0 }}
        value_template: >
          {%- set features = state_attr('sensor.corona_virus_rest', 'features') %}
          {%- set last_updated = features | map(attribute='attributes.Last_Update') | list | max / 1000 %}
          {{ last_updated | timestamp_custom('%Y-%m-%dT%H:%M:%S.%f+00:00') }}
        attribute_templates:
          confirmed: >
            {%- set features = state_attr('sensor.corona_virus_rest', 'features') %}
            {{ features | map(attribute='attributes.Confirmed') | list | sum }}
          deaths: >
            {%- set features = state_attr('sensor.corona_virus_rest', 'features') %}
            {{ features | map(attribute='attributes.Deaths') | list | sum }}
          recovered: >
            {%- set features = state_attr('sensor.corona_virus_rest', 'features') %}
            {{ features | map(attribute='attributes.Recovered') | list | sum }}
          active: >
            {%- set features = state_attr('sensor.corona_virus_rest', 'features') %}
            {{ features | map(attribute='attributes.Active') | list | sum }}
      corona_virus_ny:
        friendly_name: Corona Virus New York
        entity_id: sensor.corona_virus_rest
        availability_template: >
          {%- set features = state_attr('sensor.corona_virus_rest', 'features') %}
          {%- set features = features | map(attribute='attributes') | list %}
          {{ features | length > 0 }}
        value_template: >
          {%- set features = state_attr('sensor.corona_virus_rest', 'features') %}
          {%- set features = features | map(attribute='attributes') | list %}
          {%- set items = features | selectattr('Province_State','eq','New York') | list %}
          {%- if items | length > 0 %}
            {%- set item = items | first %}
            {%- set last_updated = item.Last_Update | int / 1000 %}
            {{ last_updated | timestamp_custom('%Y-%m-%dT%H:%M:%S.%f+00:00', False) }}
          {%- else %}
            {{ states('sensor.corona_virus_ny') }}
          {%- endif %}
        attribute_templates:
          confirmed: >
            {%- set features = state_attr('sensor.corona_virus_rest', 'features') %}
            {%- set features = features | map(attribute='attributes') | list %}
            {%- set items = features | selectattr('Province_State','eq','New York') | list %}
            {%- if items | length > 0 %}
              {%- set item = items | first %}
              {{ item.Confirmed }}
            {%- else %}
              {{ state_attr('sensor.corona_virus_ny', 'confirmed') }}
            {%- endif %}
          deaths: >
            {%- set features = state_attr('sensor.corona_virus_rest', 'features') %}
            {%- set features = features | map(attribute='attributes') | list %}
            {%- set items = features | selectattr('Province_State','eq','New York') | list %}
            {%- if items | length > 0 %}
              {%- set item = items | first %}
              {{ item.Deaths }}
            {%- else %}
              {{ state_attr('sensor.corona_virus_ny', 'deaths') }}
            {%- endif %}
          recovered: >
            {%- set features = state_attr('sensor.corona_virus_rest', 'features') %}
            {%- set features = features | map(attribute='attributes') | list %}
            {%- set items = features | selectattr('Province_State','eq','New York') | list %}
            {%- if items | length > 0 %}
              {%- set item = items | first %}
              {{ item.Recovered }}
            {%- else %}
              {{ state_attr('sensor.corona_virus_ny', 'recovered') }}
            {%- endif %}
          active: >
            {%- set features = state_attr('sensor.corona_virus_rest', 'features') %}
            {%- set features = features | map(attribute='attributes') | list %}
            {%- set items = features | selectattr('Province_State','eq','New York') | list %}
            {%- if items | length > 0 %}
              {%- set item = items | first %}
              {{ item.Active }}
            {%- else %}
              {{ state_attr('sensor.corona_virus_ny', 'active') }}
            {%- endif %}

hi Petro! I have been watching you helping out with the Corona Scrapes - and just wanted to say that your efforts are appreciated - by more of us than you know! Thanks!

1 Like

Petro,
Is there a way to see only the daily values instead of the total ones?
Thanks

Cristian