What would be the syntax to pull json from an external url in a script stored in the Html property of a Web Browser?
You could read the HTML in as a string & search through it just as though it was any standard string. Once you find the external URL, send an HTTP GET to read the file.
Iâm getting js errors running the actual âgetâ. Could you post an example?
Much appreciated.
The only reason I can of is that it might be trying to parse the response as JSON. Try including the responseType
option & set it to âtextâ.
And make for sure itâs the complete URL. If you are copying it from the HTML it could be relative.
http.get(" your url ", {responseType : "text"});
I tried
<script>
var http = new HttpClient();
var url='https://jsonplaceholder.typicode.com/posts';
http.get(url, {responseType : "text"});
</script>
and get
'HttpClient' is undefined
Not sure how to define http in this context.
Itâs HTTPClient, not HttpClient. Itâs case sensitive.
I get a similar error.
The HTTPClient class is only available to Plugins. You canât use it in HTML like that.
What exactly is it that you are ultimately trying to do? It seems odd that you are trying to programmatically manipulate/generate HTML like this. Does the service you are talking to not provide a standard JSON or XML API?
If you look at all of the devices the Home Remote supports, itâs never reading & parsing HTML. Itâs almost always either JSON or XML.
Maybe thereâs a feature that could be added so you can more easily achieve whatever it is youâre trying to achieve. What you are trying to do in that screenshot is not something I can add support for. Maybe thereâs something else though that can help.
This right here, which was brought up the other day, is something that I can fairly easily add.
I have several projects in mind, but the common thread is to pull data from a url (mainly json), manipulate it, and send it to the screen.
Using a plugin, all the current methods have limitations: devices (and their attributes) have a fixed quantity, text for labels can have variable length but limited formatting, arrays can only be shown in limited ways, with basic formatting.
Both possible solutions you have mentioned (binding plugin html output to a web browser, binding plugin array output to formatting tiles) would be useful in different cases and will be welcome additions.
Both methods would allow me to take the list of energy consumption per circuit, remove the ones currently inactive, sort them descendant by wattage, and show a table with the circuit name, current watts, kwh today and % of total daily spent. The only difference is that in one case the formatting is done with elements of your designer, and in the other case the plugin can generate the html table and all its formatting.
Does the URL youâre referring to actually serve the json to the page? Or are you talking about going into the html elements of the page to find the data youâre looking for? If itâs the former, HR does this already. If itâs the latter, Iâm currently pulling data from web elements with selenium. I have a raspberry pi web server that does the parsing in python, then I use the server to provide the data I need to HR via get requests. I believe selenium has a javscript API.
I have projects for both cases, json and html. But in the case of json that HR can parse, Iâm having difficulty handling and displaying data of variable length. When you donât know how many rows of data youâll get, itâs difficult to squeeze it into devices and attributes.
Splitting part of the processing into another machine would be an alternative. My first option would be to have all self-contained within HR.
Speaking from an ignorant perspective, it sounds like your project might be better suited in html/css/js. Then you could use a browser in HR
Yes, there are many ways to do these projects. And there is no hurry. If Bill can make the html property bindable in the near future it would be a big help.
One advantage of making it purely in HR would be the ability to share the plugin, in case someone else has a Brultech GEM energy monitoring system.
Yes, I can think of some other uses for this as well. Great idea.
The HTML property will be bindable in the next release.
Fantastic news! Thanks!