Hubitat HTML Attribute Display

This is a proof-of-concept for displaying HTML Attributes from Hubitat in a Custom Tile.

image

:man_technologist: This is one of several sample tiles that were built as part of the Custom Tiles release and is not intended to be a fully polished tile. Please feel free to learn from it, copy from it, or play with it.

image

What does it do?

Some community developed Hubitat device handlers use a ‘hack’ in which they stuff device attributes with HTML to enable them to display data as tables or embed images.

The Hero Attribute tile would normally display the HTML as text as a security precaution:
image

This tile can render the HTML and display embedded images/tables in a separate secure context:
image

Setup

Enable Hubitat Maker API

Follow the steps below to enable Maker API in Hubitat admin page.

  • Install the Maker API app and select the device(s) that you want to display
  • Enable Allow Access via Remote/Cloud
  • Add https://run.sharptools.app/ in the Allowed Hosts (for CORS) field
  • Scroll down and copy one of the example cloud endpoints
  • Make sure to press Done to save your changes!

Create Custom Tile

  • Tap the Import button above to import the tile, then scroll down and save the tile
    • Optionally, press Preview to try out the tile without saving (you’ll need the details from the Enable Hubitat Maker API section above)
  • Go to the desired dashboard, Edit, and Add Item. Tap “Custom Tile” in the Other section and add this custom tile.
  • Edit the tile, fill-in the settings, and save:
    • Sample Maker API Url - use one of the Hubitat Maker API Cloud endpoints
    • Device ID - enter the ID of a device with an attribute stuffed with HTML
      • Note that you can find the device ID in the URL of your browser when you are viewing a devices details within the Hubitat Admin UI page
    • Attribute - enter the name of the attribute that is stuffed with html

I like how the native sharptools tiles scale the font size as the overall dashboard is scaled. What HTML/CSS in a custom tile will achieve the same effect? I’ve tried defining font size in percent, em, etc. but no luck.

You could use a style which scales thing relative to the tile container (viewport):

.your-class {
   /* simplistic font autoscaling */
   font-size: min(15vh, 15vw); 
}

This scales the font based on the height (vh) and width (vw) of the tile container. You might also only want to scale based on one of the dimensions in which case you can just do something like:

.your-class {
   font-size: 15vh; /* scale relative to the tile height */
}
1 Like

Perfect. That did it. Thanks!

1 Like

I just tried this out and got it to work fine when I targeted a specific tile, the clock tile.

However when I apply it generically to my theme I can’t seem to get it working.

I have the following commands at the beginning of my theme to target all tiles:

.tile .title { top:70%; font-size: 15vh; }
.tile .icon svg {width: 55%; height: 55%; margin: 0; position: absolute; top: 30%; left: 50%; transform: translate(-50%, -50%);}
.tile .tile-footer { text-align: center; bottom: unset; top:85%; }
.tile .tile-footer .status span.right { float: inherit!important; }

When I insert the relative font size command it doesn’t seem to do anything with the size of the title. Usual caveat, I am teaching myself (or more accurately the community here is teaching me) css so apologies if I missed something obvious.

The style snippets posted above are for a developer to use within a Custom Tile.

The custom tiles render in their own context, so they don’t inherit all the aspects of a normal tile like font scaling. On the other hand, normal tiles dynamically get their font sized, so for Custom CSS in a Theme you’re generally better off using a font-size relative unit like em.

In theory, viewport relative units like those used above could be used in Custom CSS - you might want to read up on viewport units if you’re interested in what they are and how they work. :slight_smile:

@josh

As advised, I’ll post here instead of over at the hubitat forums (this thread, [RELEASE] Life360 Tracker - Works with the Paid and Free versions of Life360! - #426 by djh_wolf - Code Share - Hubitat)

That guy has made a pretty awesome set of apps. One of which links into his own life360 driver, which allows for all sorts of info to be pulled from life360 devices.

eg. this is my presence sensor (my mobile):

What I’m most interested for this discussion, is the ‘list of recent locations’ part, i.e.:

image

Here’s an example of how a tile can look with the standard hubitat dash.

However, if I try to pull the info from my device’s bpt-history, and display it on a tile in sharptools, I get the html code instead:

I can’t quite figure out how to use this thread to help me accomplish the task. Apologies =p

Thanks for posting! Can you share more details about what you’ve tried so far? There’s instructions in the first post explaining how to set up and use this custom tile – is there a particular step you got tripped up on?


Edit: I mentioned it over in the Hubitat thread, but I’ll mention it here as well in case anybody else finds this post. There’s also a community developed Life360 map for SharpTools for anyone who is looking for an interactive map on your dashboard.

1 Like

Sure.

Done this already:
image
Got could endpoint:


i.e.
hxxs://cloud.hubitat.com/api/50bf3f67xxxxxxxxxxxxxxxxxxxxxxxb82bd46/apps/1921/devices/[Device ID]?access_token=65f4d69f-ad17-xxxxxxxxxxxxxxxxxb86dcf6

and device id for life360 device
{“id”:“2051”,“name”:“Life360 - darren”,

Clicked preview, added the info as this screenschot:

…hah, and now it works. I was obviously doing something stupid.

-=edit=- doesn’t work. preview looks ok…

but when i try to add the custom tile to the dash…

1 Like

Thanks for the details. Sounds like you made progress!

So the preview in the developer console is mainly for developers as they are building a tile or for you to preview it before it’s actually used.

The settings in the preview window from the developer console are just temporary and are not saved with the custom tile.

Once you add a tile to the dashboard, you’ll want to edit that individual tile instance on your dashboard and copy the same settings that you used for your preview over.

1 Like

Cheers josh. Makes sense. Tested and managed to get to this…

There are no scroll bars, and I can’t figure out how to make the text a decent size which would flow better with my scalable dash.

Any ideas? Ta!

Awesome! Sounds like you got it working!

Custom tiles (and regular tiles) don’t have scroll bars, but if the content is scrollable you should still be able to scroll it either with a scroll wheel on a mouse, a touch pad, or a touch screen. That being said, this tile was originally designed around showing HTML content that would be vertically centered in a tile – like the weather example shown in the first post – so it wouldn’t surprise me if long scrolling content might not work well without some tweaks.

This tile was intended as a proof-of-concept – it’s not intended to be a fully polished tile and was really just something for the community developers to learn from and adapt to their needs.

Either the source html attribute from Hubitat would need to offer font scaling or someone would need to modify the custom tile to accommodate font scaling.

That being said, you could modify the custom tile to meet your needs if you want. Toward the bottom of the custom tile code, you could adjust the <style> block. Note that this will adjust the style of all your instances of this custom tile.

In this example, we’ve commented out the align-items: center, so it doesn’t try to vertically center things (you could also just delete this line). Then we added a font-size that scales with the size of the tile. You could just just use a static font size as shown in the next commented out line which is often more appropriate with content like this.

  html,body {height: 100%;margin:0;}
  .main-content {
    display: flex;
    height:100%;
    /* align-items: center; */ /* don't vertically center */
    justify-content: center;
    font-size: 20vh; /* viewport height relative sizing */
    /* font-size: 2em */ /* or use a bigger default font, but not one that scales with the size of the tile */
  }
  .main-content #content {
    text-align: center; /* OPTIONAL center align any text that gets injected */
  }
  .main-content #content img {
    max-width: 80%; /* OPTIONAL scale any inner images if they're too big */
  }
1 Like