I now actually have somewhat the same need, for my crypto currency tracker.
I tried my solution with the Brainy Table, but due to how Polymer is imported in that library, it can’t be used.
Right now, I’ve did it with a generic table in my instance, you can see a screenshot of a first version below:
As you can see, this is stil quite ugly, but it’s a start, I’ll be adding more columns and styling soon.
My code and data structure are not on my GitHub yet, but this is the gist off it:
<dom-module id="state-card-crypto_profit">
<template>
<table>
<thead>
<tr>
<th>Token</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
<template is="dom-repeat" items="{{stateObj.attributes.coins}}">
<tr>
<td>{{item.token}}</td>
<td>{{item.amount}}</td>
</tr>
</template>
</tbody>
</table>
</template>
</dom-module>
<script>
Polymer({
is: 'state-card-crypto_profit',
properties: {
hass: {
type: Object,
},
stateObj: {
type: Object,
},
}
});
As you can see, I use stateObj.attributes.coins
as items input, that’s because my attributes looks like this:
{
"friendly_name": "Crypto Profit",
"invested": 1331.8246080099339,
"coins": [
{
"price": 169.58,
"token": "ETH",
"initial": 97.00788288200002,
"amount": 0.5720479,
"current": 172.67650317100487
},
{
"price": 199.26,
"token": "ETH",
"initial": 386.7958026306,
"amount": 1.94116131,
"current": 585.9525873648814
},
{
"price": 36.1,
"token": "LTC",
"initial": 500.010928825,
"amount": 13.85071825,
"current": 709.1397096620267
},
{
"price": 0.49365,
"token": "IOT",
"initial": 48.009993680502,
"amount": 97.25512748,
"current": 66.559968834741
},
{
"price": 0.2629219997,
"token": "XEM",
"initial": 99.99999998673373,
"amount": 380.340938,
"current": 89.46357535877377
},
{
"price": 8.888229975,
"token": "PART",
"initial": 200.0000000050983,
"amount": 22.501668,
"current": 194.80125252248922
}
],
"total": 1818.593596913917,
"unit_of_measurement": "EUR",
"custom_ui_state_card": "crypto_profit"
}
For this to work I needed to add this sensor in a group, so keep that in mind as well
EDIT: Updated version:
Actually pretty quick and dirty, just playing with some CSS classes:
<style>
table {
width: 100%;
}
tr:nth-child(even) {
background-color: #dddddd;
}
td, th {
text-align: left;
}
</style>
<table>
<thead>
<tr>
<th>Token</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
<template is="dom-repeat" items="{{stateObj.attributes.coins}}">
<tr>
<td>{{item.token}}</td>
<td>{{item.amount}}</td>
</tr>
</template>
</tbody>
</table>