How to scrape within a nested table

Hi, I’d like to scrape the radiation value of div id=“radio_table_row34602” from The situation at observation points. UHMC. How to set up the scrape sensor correctly? Would also be great to have an option to test scraping.

That’s not a <div>. The selector would be simple (tr#radio_table_row34602 td with an index of 2), but the data you want is not in the initial HTML of that resource, so scrape won’t work.

It must be in one of the source files that are loaded (F12 DevTools, Network tab) but I’m struggling to find it. Lots of references to the station, but I can’t yet see how the value on the table is sourced:

OK, found it.

rest:
  - resource_template: "https://www.meteo.gov.ua/_/m/radioday.js?{{ now().strftime('%Y-%m-%d-%H-%M') }}"
    scan_interval: 3600
    sensor:
      - name: "ZaporizhzhiaA exposure dose rate"
        value_template: "{{ value_json['34602']['VZ'] }}"
        unit_of_measurement: "nSv/hr"

1 Like

Amazing Toon! I could not have don this, thanks for converting it alredy into a sensor. Works like a charm!

1 Like

I’m not sure what’s the latest style of defining sensors, however mine were all under the formatting

sensor:
  - platform: 

so I converted it like this, in case someone else needs it, too:

  - platform: rest
    resource_template: "https://www.meteo.gov.ua/_/m/radioday.js?{{ now().strftime('%Y-%m-%d-%H-%M') }}"
    scan_interval: 3600
    name: "Radiation Zaporizhzhia"
    unique_id: "radiation_ukraine"
    value_template: "{{ value_json['34602']['VZ'] | float}}"
    unit_of_measurement: "nSv/h"
    icon: mdi:radioactive

Yeah, that’s fine. There are two ways:

I use the latter as it supports multiple sensors from one resource, so you could add another location without needing an extra request from the site. If you only need one, then what you’ve done is fine.

There’s no point adding the |float, as it’ll get stored as a string anyway: all states are strings.

1 Like

Thanks, that makes sense. I was trying with float or int to make the value trigger an alert, but somehow it doesn’t go off (at least when I change the values via the developer panel) thought that it might be because it’s interpreted as a string, but the history graph card works fine

alias: Alert Radiation
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.radiation_berlin
    above: 200
    value_template: ""
  - platform: numeric_state
    entity_id: sensor.radiation_ukraine
    above: 200
    value_template: ""
condition: []
action:
  - service: notify.notify
    data:
      title: "☢️ RADIATION ALERT ☢️ "
      message: Radiation Alert
  - service: notify.persistent_notification
    data:
      title: "☢️ RADIATION ALERT ☢️ "
      message: "{{ trigger.id }} above {{trigger.to_state}}"
    enabled: true
mode: single

Remove your value_template lines.

They are saying “take the value of the sensor, throw it away and use an empty string to compare against the number”.

lol, you’re right. drove me insane