Just starting to play with the scrape sensor. For a simple test, I tried to scrape the WeatherUnderground page for my location. I was able to get the right selection, but it returns a string containing the numeric temperature PLUS the “degree” symbol.
So when I display it along with other temperature sensors I have, it’s taken as a string instead of a number.
I tried using value_template, but apparently I’m not getting the syntax right. Is that the easiest way to go? What would the syntax look like?
It’s returning 0.0 because that’s the default value float reports when it can’t convert the supplied string.
You can’t use float to convert a string containing non-numeric text. In the example below, the F in the string can’t be converted by float so it reports its default value of 0.0
If you provide a sample of what you have, I may be able to create a template that extracts the numeric portion. For example, this will extract the numeric portion of 72 °F
Exactly. Those three values are defined the same way in the same history_graph card. I’m trying to figure out why one displays differently from the “stepped” graph I want. I click on the new one and get valid numeric values (now that the degree symbol is gone.) I even renamed the event and restarted HA in hopes that it wouldn’t retain any previous definition as a string. The new values are all now numeric, and still it displays as that odd bar graph.
I even created a new history_graph card in case the old one somehow remembered the configuration, but still got the bar.
Update: I deleted the HA database, as well as added unit_of_measurement: "°F"
to the scrape platform definition in the configuration.yaml file (which I renamed again to PWS_temp.)
That got me two separate line graphs on the card. We’re getting closer!
I then changed the unit_of_measurement on the other thermometers to “°F” instead of “degrees.”
Now all three lines show up on the same chart! The trick was to make sure they were all using the same unit of measurement. Of course, I’ve only got a few minutes’ worth of data so far, so the chart isn’t that helpful yet.
Hey, I’m trying to pull temperature from the WU station nearest me, but I don’t understand how to decode the format to properly reference the data. Could you actually post your config so maybe I can extrapolate from what you did? Sorry for being such an amateur
As I recall, I was able to just scrape the page for a while, but WU changed the way the page coded the temperature and it stopped working. Basically, you look at the page, find the temperature, then scan through all the web page source for that number. It wasn’t obvious and I think the change made it almost impossible to extract it reliably.
The problem is, to use the API you need a key, which you can only get if you have a PWS.
Thank you, kind of you to do all that. You’re right though, I don’t have an API key.
I actually (kind of) got this working, but the page seems to refresh after you go to it, and that updates the value. I guess HA doesn’t understand that, so it always pulls the wrong number that is populated to begin with (20.1). It’s too bad because the local PWS weather station is very accurate for me. Thanks anyways!
Oh, actually, I realized it’s just giving me a value in F instead of C because they do some silly after the fact refresh. Hopefully I can somehow put a formula into the sensor so it just reports C.
Right, it’s a pretty dynamic page. Hard to figure out what to scrape. It might be possible to locate the actual source of the data; maybe it’s in some file that you could pull down without grabbing the whole page.
I’d be curious to see how you’ve got it configured to grab the temperature. I recall struggling with temperature conversion too. It seems there are multiple places this can occur.
In the end it actually ended up being quite simple, this works perfectly delivering a measurement in C because that’s what HA shows me. (Keep in mind, I’m scraping a particular PWS that is close to me, so if you had a different page in mind it might not be the same)
Thanks, yes, that’s what I see, too. There are a bunch of values with a class named “wu-value-to.” It looks like the first one is the temperature. But on the page I’m looking at, there are 15 other values that use the same class. I guess the scraper just grabs the first one. Nice, elegant solution!