Any suggestions how I can extract a price from a website?
Currently I’m trying to figure out how I could access the “Einspeisetarif” (feed-in tariff) for the aWattar Sunny tariff from this site: SUNNY - Ihr Solarstrom für Österreich!
It’s the “8,291 Cent/kWh”.
I thought I could just make a HTTP GET request and pass the result to Homey Script, where I could extract it with some string manipulation (regex preferable, but indexof/substring would also suffice). But it seems that no string functions are accessible in Homey Script. Am I mistaken?
Any other ideas or hints what I could try? Thanks in advance!
// https://www.awattar.at/services/api/v1/marketdata
// https://api.awattar.at/v1/marketdata
const res = await fetch("https://api.awattar.at/v1/marketdata");
if (!res.ok) {
throw new Error(res.statusText);
}
// Get the body JSON
const results = await res.json();
//console.log("RESULTS=", results,"\n ----------------" );
console.log("Data marketprice =", results.data[0].marketprice, results. Data[0].unit);
return (true );
This is what you are looking for?
1 Like
That gets the market data that is used for the Hourly tariff, but not the price for the Sunny feed-in tariff.
The first can be retrieved via the Power by the Hour app, but I don’t have a solution for the second. As far as I know, there is no API available for the feed-in tariff.
Sory, think I didn’t read very well…
String functions are available, its plane JavaScript.
Thanks, I got it working now.
1 Like
Great it’s working, did you extract it from the html page?
Yes, directly from the website. Just extract the first “xx,xxx Cent/kWh” I find in the body. I asked them if they could make they price available through their API, but haven’t got an answer yet.
1 Like