#Post your yaml in a thread and lemme see

1 messages · Page 1 of 1 (latest)

wet ridge
#

Original code

card:
  show_header_toggle: false
  title: TrueNAS Datasets
  type: entities
filter:
  include:
    - entity_id: /sensor.truenas_datasets/
      options:
        name:
          - []
        secondary_info: >-
          <b style='color:orange'>Pool:</b> <span style='color:white'>[[
          {entity}.attributes.Pool ]]</span> <br> <b
          style='color:orange'>Mountpoint:</b> [[ {entity}.attributes.Mountpoint
          ]] <br> <b style='color:orange'>Used:</b> [[ {entity}.attributes.Used
          ]] bytes<br> <b style='color:orange'>Free:</b> [[
          {entity}.attributes.Available ]] bytes<br>
        type: custom:secondaryinfo-entity-row
show_empty: true
sort:
  method: state
  numeric: true
  reverse: true
type: custom:auto-entities

I'll post the jinja test version shortly

#

Okay, it seems to work if I put in dumb text (although it kills the js templates)

card:
  show_header_toggle: false
  title: TrueNAS Datasets
  type: entities
filter:
  include:
    - entity_id: /sensor.truenas_datasets/
      options:
        name:
          - []
        secondary_info: >- 
          {% set used_space = "123" %}
          <b style='color:orange'>Pool:</b> <span style='color:white'>[[
          {entity}.attributes.Pool ]]</span> <br> <b
          style='color:orange'>Mountpoint:</b> [[ {entity}.attributes.Mountpoint
          ]] <br> <b style='color:orange'>Used:</b>
          {{ used_space }} bytes<br> <b style='color:orange'>Free:</b> [[
          {entity}.attributes.Available ]] bytes<br>
        type: custom:secondaryinfo-entity-row
show_empty: true
sort:
  method: state
  numeric: true
  reverse: true
type: custom:auto-entities

How do translate [[ {entity}.attributes.Used ]] js template to jinja?

inner escarp
#

I don't think you need to. I think you have everything set up properly. Let's try am experiment. I want to know what happens if you change the original code to [[ {entity}.attributes.Used + 123456 ]]

wet ridge
inner escarp
#

I'm curious if you get <really big number>123456 or <a slightly bigger number than before>

#

well that didn't go as planned

wet ridge
# wet ridge

Which is the same as what I get if I add any other javascript, such as [[ {entity}.attributes.Used; ]]

inner escarp
#

but the original code is what is used in the first screenshot, right?

inner escarp
#

and if you remove the + 123456, it shows the really big number?

wet ridge
#

correct

inner escarp
#

what happens with yaml [[ parseInt({entity}.attributes.Used) ]]

wet ridge
#

same... undefined

inner escarp
#

weird. I was hoping that would work.

wet ridge
#

yea, I don't understand why it's not accepting javascript

#

the jinja templates work though, I just don't know how to get the current entity attributes

inner escarp
#

what about this.entity_id?

#

# Note the magic value this.entity_id here

wet ridge
#

nope

name:
  - []
secondary_info: >-
  {% set test = this.entity_id %}
  {{ test }}
type: custom:secondaryinfo-entity-row
inner escarp
#

I wonder if you're hitting a limitation to the entities card itself. I don't think it allows templating by itself...

#

But that doesn't make sense because you were able to apply the colors to it.

wet ridge
#

I can do some templating at least.

name:
  - []
secondary_info: >-
  {% set test = 1234 / 1000 %}
  {{ test }}
type: custom:secondaryinfo-entity-row
inner escarp
#

So I was looking at this {% set battery_level = states['this.entity_id'].state |int(0) %}
What if you adapted your test variable to something like that?

wet ridge
#

Yes! It Works!

name:
  - []
secondary_info: >-
  {% set test = states['this.entity_id'].attributes.Used / 1000 / 1000 / 1000  %}
  {{ test }} GB
type: custom:secondaryinfo-entity-row
inner escarp
#

some progress. try using // 1000000000 instead of all the divide by 1000.

#

actually, it might be closer to use 1024000000

wet ridge
#

Yea, I was going to say, it seems to be off a little bit.

name:
  - []
secondary_info: >-
  {% set factor = 1024 * 1024 * 1024 %}
  {% set used_space = states['this.entity_id'].attributes.Used / factor | round(1) %}
  {% set available_space = states['this.entity_id'].attributes.Available / factor | round(1) %}
  {{ used_space }} GB
type: custom:secondaryinfo-entity-row

Rounding doesn't seem to be working though.

inner escarp
#

okay. so math is checking out. now just have to round the number.

wet ridge
#

roudning works if I put in the last template, but not where I'm setting the value

inner escarp
#

wrap the state and factor in parentheses so it happens first and then that is piped into round (states['this.entity_id'].attributes.Available / factor)

#

(states['this.entity_id'].attributes.Available / factor).toFixed(1) should also work

wet ridge
#

Nice, it works!

name:
  - []
secondary_info: >-
  {% set factor = 1024 * 1024 * 1024 %}
  {% set used_space = (states['this.entity_id'].attributes.Used / factor) | round(1) %}
  {% set available_space = (states['this.entity_id'].attributes.Available / factor) | round(1) %}
  {% set pool = states['this.entity_id'].attributes.Pool %}
  {% set mountpoint = states['this.entity_id'].attributes.Mountpoint %}
  <b style='color:orange'>Pool:</b> <span style='color:white'>{{ pool }}</span> <br> <b
  style='color:orange'>Mountpoint:</b> {{ mountpoint }}<br> <b style='color:orange'>Used:</b> {{ used_space }} GB
  <br> <b style='color:orange'>Free:</b> {{ available_space }} GB<br>
type: custom:secondaryinfo-entity-row

I really appreciate the help!

#

I wish HA didn't reformat my yaml when saving though, lol.

inner escarp
#

Yeah. That bugs me too some times. Even when trying to tell it not to format... nope. formats anyways.

#

That turned out pretty good. Are you still using the entities card (from the 4th line of the original code posted)?

#

Or is everything being "processed" through the custom:secondaryinfo-entity-row?

wet ridge
#

This is the full yaml.

card:
  show_header_toggle: false
  title: TrueNAS Datasets
  type: entities
filter:
  include:
    - entity_id: /sensor.truenas_datasets/
      options:
        name:
          - []
        secondary_info: >-
          {% set factor = 1024 * 1024 * 1024 %} {% set used_space =
          (states['this.entity_id'].attributes.Used / factor) | round(1) %} {%
          set available_space = (states['this.entity_id'].attributes.Available /
          factor) | round(1) %} {% set pool =
          states['this.entity_id'].attributes.Pool %} {% set mountpoint =
          states['this.entity_id'].attributes.Mountpoint %} <b
          style='color:orange'>Pool:</b> <span style='color:white'>{{ pool
          }}</span> <br> <b style='color:orange'>Mountpoint:</b> {{ mountpoint
          }}<br> <b style='color:orange'>Used:</b> {{ used_space }} GB<br> <b
          style='color:orange'>Free:</b> {{ available_space }} GB<br>
        type: custom:secondaryinfo-entity-row
show_empty: true
sort:
  method: state
  numeric: true
  reverse: true
type: custom:auto-entities
inner escarp
#

you might consider{% set used_space = (states['this.entity_id'].attributes.Used / factor).toLocaleString('en-US', {minimumFractionDigits:1, maximumFractionDigits:1}); %} which will add commas and ensure one decimal place even if zero.

#

There's definitely a lot going on in these cards: custom:auto-entities, entities, and custom:secondaryinfo-entity-row. Nicely put together!