Auto-entities + card-templater

I’m monitoring my network with nmap. I’m trying to make entity card with devices connected to network and devices not connected (different color). I also want to see IP address instead ‘home’ , ‘not_home’. I almost did it but instead of entities I see cards inside card. Doas anybody know how can I fix it?

type: 'custom:auto-entities'
card:
  type: entities
  title: Network
filter:
  include:
    - attributes:
        scanner: NmapDeviceScanner
      entity_id: device_tracker.*
      options:
        type: 'custom:card-templater'
        card:
          type: entities
          style: |
            :host {
              font-variant: small-caps;
              }
              #states > * {
                      margin: -20px 0px !important;
                }
          entities:
            - entity: this.entity_id
              style: |
                :host { 
                  {% if is_state('this.entity_id', 'not_home') %} 
                    color: red
                  {% else %}
                   
                  {% endif %} 
                }
        entities:
          - entity: this.entity_id
            state_template: '{{ state_attr("this.entity_id","ip") }}'
      sort:
        attribute: ip
        method: attribute

because you’re using an entities card inside an entities card.

You can either style the card to have no background or shadow. Or use the custom:hui-sensory-entity-row

This is what I wanted to do.
Thank you.

type: 'custom:auto-entities'
card:
  type: entities
  style: |
    :host {
      font-variant: small-caps;
    }
    #states > * {
            margin: -12px 0px !important;
    }
  title: Network
filter:
  include:
    - attributes:
        scanner: NmapDeviceScanner
      entity_id: device_tracker.*
      options:
        type: 'custom:template-entity-row'
        state: '{{state_attr(config.entity, ''ip'')}}'
        style: |
          :host { 
            {% if is_state('this.entity_id', 'not_home') %} 
              color: red
            {% else %}
             
            {% endif %} 
          }
      sort:
        attribute: ip
        method: attribute

Now it’s working perfectly.

3 Likes

Hi there @ligeza, I’ve wanted to do a similar thing where I list all my packages with the following required changes:

  1. Omit the seventeen track prefix from the entity name.
  2. Bold / Mark in other colour packages that are in “ready for pickup” state.

Would appreciate your help with this, here’s what I currently got:

      - type: custom:auto-entities
        show_empty: false
        card:
          type: entities
          title: Packages
          show_header_toggle: false
        filter:
          include:
            - entity_id: "sensor.seventeentrack_*"
              options:
                secondary_info: last-changed
          exclude:
            - state: Delivered

Thanks in advance.

I’m using this code:

card:
  style: |
    :host {
      font-variant: small-caps;
    }
  title: Network ostatnie 6 godzin
  type: entities
filter:
  include:
    - attributes:
        scanner: NmapDeviceScanner
      entity_id: device_tracker.*
      last_changed: < 360
      options:
        secondary: >-
          {{ as_timestamp(states[config.entity].last_changed)|
          timestamp_custom('%X - %D') }}
        state: '{{state_attr(config.entity, ''ip'')}}'
        style: |
          :host { 
            {% if is_state('this.entity_id', 'not_home') %} 
              color: red
            {% else %}
              color: yellow
            {% endif %} 
          }
        type: 'custom:template-entity-row'
      sort:
        method: last_changed
type: 'custom:auto-entities'

2

Yellow are online devices, red are offline. It is last 6 hours time. I think you want to do similar thing.

For styling you need:

1 Like

Hello,
I’m quite new to HA and started with integrating my Homematic devices and building some smart Lovelace cards.
Currently I’m working on an auto-entity-card, which shows all open windows with their window_state.
I’d like to get the window_state in red color in case the window is open. Is the window not opened it should stay white.
After researching a bit I found this threat which I adopted to my needs, but unfortunately the styling doesn’t work in my card. The needed card-mod template is installed.
I would very much appreciate, if someone could point me to the error in the code and subsequently to a solution.
E.g. one question in my mind: when to use config.entity vs. ‘this.entity_id’
Thanks in advance.

      - card:
          show_empty: true
          title: Offene Fenster und Türen
          type: entities
        entities:
          - entity: binary_sensor.hmip_fenster_und_turkontakt_oben
            name: Terrassentür
        filter:
          include:
            - entity_id: '*fenstergriff*'
              state: 'on'
              options:
                secondary: >-
                  vor {{ relative_time(states[config.entity].last_changed)|
                  timestamp_custom('%d-%m-%y %H:%M:%S') }}
                state: '{{state_attr(config.entity, "window_state")}}'
                icon: 'mdi:window-open-variant'
                style: |
                  :host {
                    {% if is_state_attr('this.entity_id', 'window_state', 'OPEN') %}
                      color: red
                    {% else %}
                      color: white
                    {% endif %}
                  }
                type: 'custom:template-entity-row'
          exclude:
            - state: 'off'
        type: 'custom:auto-entities'

I can’t explain why, but I checked the Lovelace card again today and the above stated code works in the way it should.

I would assume it still doesn’t work the way you think it should. I believe this line needs to have the quotes removed around 'this.entity_id'.

{% if is_state_attr(this.entity_id, 'window_state', 'OPEN') %}

It works exactly as expected with ‘this.entity_id’ - but strangely only inside the Firefox browser.
Inside the HA App the font color doesn’t change.
I also tested the code without quotes - as you suggested - but then the code is not working in the browser and in the app neither.

Any ideas why its not working in the app?

if it works in one browser and not another, the other browser is most likely using old cached info. Clear the cache and refresh the page.

No, I wrote it works in the Firefox browser but not in the HA app.
Any idea, why the code doesn‘t work in the HA app?

Which HA app?

Hi petro,
I use the IOS Home Assistant App for iPhone and iPad - both ver. 2020.6.2.
But I can’t explain how, because I didn’t change anything.
Today both Apps show the correct font format of the window state.
So, this problem is solved.

great! thanks for sharing your final results. was exactly what I was looking for… you saved me quite some research time!

1 Like