Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I use data sources that aren't RSS? #50

Open
Madelena opened this issue May 17, 2022 · 1 comment
Open

How can I use data sources that aren't RSS? #50

Madelena opened this issue May 17, 2022 · 1 comment

Comments

@Madelena
Copy link

I use ha-multiscrape for a few HTML tables and JSON files. I'm not too sure what value_template I should use to generate data that works for list-card.

For example:

The original JSON would look like this:

[
  {
    "product_id": "K04W",
    "issue_datetime": "2022-05-16 05:00:24.337",
    "message": "Space Weather Message Code: WARK04\r\nSerial Number: 4102\r\nIssue Time: 2022 May 16 0500 UTC\r\n\r\nWARNING: Geomagnetic K-index of 4 expected\r\nValid From: 2022 May 16 0500 UTC\r\nValid To: 2022 May 16 0900 UTC\r\nWarning Condition: Onset\r\n\r\nNOAA Space Weather Scale descriptions can be found at\r\nwww.swpc.noaa.gov\/noaa-scales-explanation\r\n\r\nPotential Impacts: Area of impact primarily poleward of 65 degrees Geomagnetic Latitude.\r\nInduced Currents - Weak power grid fluctuations can occur.\r\nAurora - Aurora may be visible at high latitudes such as Canada and Alaska."
  },
  {
    "product_id": "K04A",
    "issue_datetime": "2022-05-15 02:53:30.973",
    "message": "Space Weather Message Code: ALTK04\r\nSerial Number: 2295\r\nIssue Time: 2022 May 15 0253 UTC\r\n\r\nALERT: Geomagnetic K-index of 4\r\nThreshold Reached: 2022 May 15 0247 UTC\r\nSynoptic Period: 0000-0300 UTC\r\n \r\nActive Warning: Yes\r\n\r\nNOAA Space Weather Scale descriptions can be found at\r\nwww.swpc.noaa.gov\/noaa-scales-explanation\r\n\r\nPotential Impacts: Area of impact primarily poleward of 65 degrees Geomagnetic Latitude.\r\nInduced Currents - Weak power grid fluctuations can occur.\r\nAurora - Aurora may be visible at high latitudes such as Canada and Alaska."
  },
  {
    "product_id": "K04W",
    "issue_datetime": "2022-05-15 02:30:15.460",
    "message": "Space Weather Message Code: WARK04\r\nSerial Number: 4101\r\nIssue Time: 2022 May 15 0230 UTC\r\n\r\nWARNING: Geomagnetic K-index of 4 expected\r\nValid From: 2022 May 15 0229 UTC\r\nValid To: 2022 May 15 1500 UTC\r\nWarning Condition: Onset\r\n\r\nNOAA Space Weather Scale descriptions can be found at\r\nwww.swpc.noaa.gov\/noaa-scales-explanation\r\n\r\nPotential Impacts: Area of impact primarily poleward of 65 degrees Geomagnetic Latitude.\r\nInduced Currents - Weak power grid fluctuations can occur.\r\nAurora - Aurora may be visible at high latitudes such as Canada and Alaska."
  }
]

So I configured multiscrape to do this:

- name: NOAA Space Weather - Alerts
  resource: https://services.swpc.noaa.gov/products/alerts.json
  scan_interval: 3600
  sensor:
    - unique_id: noaa_space_weather_alerts
      name: NOAA Space Weather - Alerts
      value_template: '{{ value_json[0]["product_id"] }}'
      attributes:
        - name: Entries
          value_template: |
            {% set temp = '' %}
            {% for message in value_json %}
            - product_id: {{ message.product_id }}
              issue_datetime: {{ message.issue_datetime }}
              message: {{ message.message }}
            {% endfor %}

It would generate something that looks like a feed, but it wouldn't work:

friendly_name: NOAA Space Weather - Alerts
entries: - product_id: K04W
  issue_datetime: 2022-05-16 05:00:24.337
  message: Space Weather Message Code: WARK04
Serial Number: 4102
Issue Time: 2022 May 16 0500 UTC

WARNING: Geomagnetic K-index of 4 expected
Valid From: 2022 May 16 0500 UTC
Valid To: 2022 May 16 0900 UTC
Warning Condition: Onset

NOAA Space Weather Scale descriptions can be found at
www.swpc.noaa.gov/noaa-scales-explanation

Potential Impacts: Area of impact primarily poleward of 65 degrees Geomagnetic Latitude.
Induced Currents - Weak power grid fluctuations can occur.
Aurora - Aurora may be visible at high latitudes such as Canada and Alaska.

- product_id: K04A
  issue_datetime: 2022-05-15 02:53:30.973
  message: Space Weather Message Code: ALTK04
Serial Number: 2295
Issue Time: 2022 May 15 0253 UTC

ALERT: Geomagnetic K-index of 4
Threshold Reached: 2022 May 15 0247 UTC
Synoptic Period: 0000-0300 UTC
 
Active Warning: Yes

NOAA Space Weather Scale descriptions can be found at
www.swpc.noaa.gov/noaa-scales-explanation

Potential Impacts: Area of impact primarily poleward of 65 degrees Geomagnetic Latitude.
Induced Currents - Weak power grid fluctuations can occur.
Aurora - Aurora may be visible at high latitudes such as Canada and Alaska.

- product_id: K04W
  issue_datetime: 2022-05-15 02:30:15.460
  message: Space Weather Message Code: WARK04
Serial Number: 4101
Issue Time: 2022 May 15 0230 UTC

WARNING: Geomagnetic K-index of 4 expected
Valid From: 2022 May 15 0229 UTC
Valid To: 2022 May 15 1500 UTC
Warning Condition: Onset

NOAA Space Weather Scale descriptions can be found at
www.swpc.noaa.gov/noaa-scales-explanation

Potential Impacts: Area of impact primarily poleward of 65 degrees Geomagnetic Latitude.
Induced Currents - Weak power grid fluctuations can occur.
Aurora - Aurora may be visible at high latitudes such as Canada and Alaska.

@versile2
Copy link

Looking at the code base I'm pretty sure your original json should work as an input. The problem with value templates is they only allow 255 characters though. Perhaps look at making a sensor that contains the data hardcoded in configuration.yaml? I would be interested in helping if you still need this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants