Get non-attribute data from Hubitat in custom tile?

I’m pretty sure this isn’t possible to do the way I’m trying, but maybe there’s a different way to do what I want, so I’ll ask anyway.

I am trying to create a custom tile using json data in Hubitat. It’s too clunky to throw the json into a device attribute, and I’m afraid I’ll hit the character limit for an attribute anyway. So I’m trying to retrieve the json data from Hubitat in a different way. I don’t see a way for me to retrieve it via Maker API, because it seems I can only retrieve device configuration info and attribute values, not device state or data returned from a command. So I tried a Hubitat cloud endpoint, but it seems as though there’s access control issues (that can’t be solved by using a proxy configuration parameter in the get call because that’s only available in first-party tiles). So that leaves me out of ideas… any other way you can think of to retrieve values from Hubitat outside of a device attribute from a custom tile?

The data I’m trying to retrieve is not sensitive. I wouldn’t really care if it was made public. But it can change, so I need to be able to dynamically fetch it.

Can you share more details about the data? Just trying to better understand why it needs to be in Hubitat? There’s a variety of different JSON ‘bins’ available online that might be a good fit for this.

I wonder if you could modify the response headers. I recall playing with this at one point when I wanted to modify the returned ‘Content-Type’ header with a proof of concept I was playing with years back. Let me search and see if I can find it…

Edit: Here’s the snippet for changing the content type. I’m away from my hub at the moment, but I wonder if a similar approach could be used for the Access-Control-Allow-Origin header:

Example Code
        name: "Test HTML Endpoints",
        namespace: "joshualyon",
        author: "Josh Lyon",
        description: "Test HTML Endpoints",
        category: "Amazing Apps",
        iconUrl: "",
        iconX2Url: "",
        oauth: [displayName: "HTML Endpoint", displayLink: ""]){

    page(name: "setupScreen")

def setupScreen(){
        //enable OAuth in the app settings or this call will fail
    def uri = getFullLocalApiServerUrl() + "/?access_token=${state.accessToken}"
    return dynamicPage(name: "setupScreen", uninstall: true, install: true){
            paragraph("Use the following URI to access the page: <a href='${uri}'>${uri}</a>")

mappings {
    //the root path - you can also map other paths or use parameters in paths and posted data
    path("/") { 			 action: [ GET: 	"renderWebsite" ] }

def renderWebsite(){ "Rendering page"
    html = "<html><head><title>Awesome Page</title></head><body><h1>hello world</h1></body></html>"
    render contentType: "text/html", data: html, status: 200
1 Like

Yup, good call, that worked! Thanks!!

For others, just make the last line from Josh’s code snippet:
render contentType: "application/json", data: jsonData?.toString(), status: 200, headers: ["Access-Control-Allow-Origin": ""]

1 Like