Scrape integration - multiple sensors from one source

Just FYI, so no question.
I have been experimenting with the Scrape sensor, and found something that might be of interest to others.
It is stated on the Scrape documentation page that “A list of sensors to create from the shared data” can be defined.
However, there is no example shown on that page for multiple sensors.
Initially I could not find a way to define multiple scraping sensors from one source without defining multiple independent scrape resources.
This would mean that for each sensor the source web page has to be loaded again, meaning multiple contacts to the same web server. Something like this:

# Example configuration.yaml entry
  - resource: https://www.home-assistant.io
    sensor:
      - name: Current version
        select: ".current-version h1"
        value_template: '{{ value.split(":")[1] }}'
  - resource: https://www.home-assistant.io
    sensor:
      - name: Release date
        select: "span"
        index: 1

Then I found the multiscrape project, that appears to be created especially to address this problem.
But before going that route I took a peak at the Scrape source code on GitHub, and I got the impression that multiple sensors indeed should be supported.
And after some more trials it appeared that it indeed is possible to define multiple sensors from one source, like this:

# Example configuration.yaml entry
  - resource: https://www.home-assistant.io
    sensor:
      - name: Current version
        select: ".current-version h1"
        value_template: '{{ value.split(":")[1] }}'
      - name: Release date
        select: "span"
        index: 1

So for anyone who wants to set-up multiple sensors from one web page: this is a way to do it.

This information may be beneficial for others. Thank you for your contribution.
However, it’s worth noting that this information is also documented

sensor map REQUIRED

A list of sensors to create from the shared data. All configuration settings that are supported by RESTful Sensor not listed above can be used here.

Additionally, it’s important to highlight that starting from version 2022.12, the scrape integration in Home Assistant can now be configured using the user interface (UI). Prior to version 2023.9.0, creating URLs with payload was not possible, but this issue has been resolved by the developers.

Thanks for your information.
As I wrote, I did read through the documentation, but it initially was not clear to me how to define the multiple sensors, especially due to a lacking example. Hence my post.
But again reading through the documentation it now became clear to me what is meant by “map” in this case.

1 Like

Why don’t you add an example to the documentation then?

Seriously, adding to the docs would be easy to find. This post, for all it’s undoubted value, will be hard to find in a forum this big.

I absolutely agree that it would be much better to add a multi-sensor example to the docs, so I will look into doing this.
However, it will be a first for me to work on the docs.
Would this have to be a Pull request or an Issue?

Be brave, PR.

Can assist when not on my tablet.

This is true but if you tried to do it, you noticed that it is tedious to follow the github rules of HA.
I did try to update the doc to replace the history stat sensor's exemples

Because this notation

start: "{{ now().replace(hour=0, minute=0, second=0, microsecond=0) }}"

or

start: "{{ now().replace(hour=6, minute=0, second=0, microsecond=0) }}"

Is better replaced with

start: "{{ today_at()  }}"

or

start: "{{ today_at('06:00:00')  }}"

But after editing, when trying to push request to github, I gave up with the amount of administrative work to do, approval, review, test, …