Custom Component - ESXi Stats

Just wanted to say this is awesome and thanks for the hard work! Just installed yesterday (manually), but I’ll be working on breaking some info out into individual sensors sometime soon. Hoping to use this data to help with a server rack RGB project (LEDs on each side of the rack - using host data to change colors to help indicate resource usage and/or issues).

This will also help me get rid of Glances on each VM.

1 Like

0.4.0 is out. There is a breaking change if the component is configured via the Integrations UI.

Release contains these additions:

  1. Services to create and remove snapshots (only available if you run a vCenter or your stand-alone host is fully licensed)
  2. License monitoring - new sensor that will monitor licenses and let you know if one or more licenses are expiring within 30 days, or expired
  3. Persistent notification is created when a service command is complete
2 Likes

What is my problem? the sensor work but the Button template will be empty:

Card:

type: 'custom:button-card'
entity: sensor.esxi_stats_vms
name: ESXi
template: esxi_stats_vm
styles:
  icon:
    - color: |
        [[[
          if ( states['sensor.esxi_stats_vms'].attributes.plex.status == "green")
            return "green";
          if ( states['sensor.esxi_stats_vms'].attributes.plex.status == "warning" )
            return "yellow";
          return "red";
        ]]]
custom_fields:
  uptime: |
    [[[
      return `<ha-icon
        icon="mdi:arrow-up"
        style="width: 12px; height: 12px; color: deepskyblue;">
        </ha-icon><span><span style="color: var(--text-color-sensor);">
        ${states['sensor.esxi_stats_vms'].attributes.web01.uptime_hours}</span></span>`
    ]]]
  cpu: |
    [[[
      return `<ha-icon
        icon="mdi:server"
        style="width: 12px; height: 12px; color: deepskyblue;">
        </ha-icon><span>CPU: <span style="color: var(--text-color-sensor);">
        ${states['sensor.esxi_stats_vms'].attributes.web01.cpu_count}</span></span>`
    ]]]
  ram: |
    [[[
      return `<ha-icon
        icon="mdi:memory"
        style="width: 12px; height: 12px; color: deepskyblue;">
        </ha-icon><span>Mem: <span style="color: var(--text-color-sensor);">
        ${states['sensor.esxi_stats_vms'].attributes.web01.memory_allocated_mb} MB</span></span>`
    ]]]
  state: |
    [[[
      return `<ha-icon
        icon="mdi:harddisk"
        style="width: 12px; height: 12px; color: deepskyblue;">
        </ha-icon><span>State: <span style="color: var(--text-color-sensor);">
        ${states['sensor.esxi_stats_vms'].attributes.web01.state}</span></span>`
    ]]]

and the Sensor:

thanks for your help :slight_smile:

Is it possible to use the custom list card to display all VMs with their data? i can’t get it to work. Can anyone help out?

I think that is designer to work with a list of dicts, not with a dict like this.

Edit: confirmed

your problem might be the missing template? Did you copy the templates to your ui-lovelace yaml?

Yes it is! Example is available on the component github page. https://github.com/wxt9861/esxi_stats/blob/d827879dc8e275769eeb337012de3572c00f0843/examples/list-card-example.yaml

Here is how I have mine setup.

- type: custom:list-card
      entity: sensor.esxi_stats_vms
      title: VMs
      columns:
        - title: 'VM Name'
          field: name
          style:
            - text-align: center
        - title: 'Status'
          field: status
          style:
            - text-align: center
        - title: 'State'
          field: state
          style:
            - text-align: center
        - title: Uptime (H)
          field: uptime_hours
          style:
            - text-align: center          
        - title: CPU Usage %
          field: cpu_use_%
          style:
            - text-align: center
        - title: 'CPUs'
          field: cpu_count
          style:
            - text-align: center
        - title: Mem Use (MB)
          field: memory_used_mb
          style:
            - text-align: center
        - title: Mem Total (MB)
          field: memory_allocated_mb
          style:
            - text-align: center
        - title: Storage Used (GB)
          field: used_space_gb
          style:
            - text-align: center
        - title: VM Tools
          field: tools_status
          style:
            - text-align: center
        - title: Snapshots
          field: snapshots
          style:
            - text-align: center
1 Like

Thanks again for the excellent component. I now have a way to pull data from my NUC running ESXi and present it in HA.

This screenshot is still a work in progress but figured I’d share in the hopes that it inspires others to do the same. Still need to add VM counts and a few other things here and there.

Keep up the great work! Can’t wait to see what’s next (hopefully multiple ESXi servers :crossed_fingers:).

2 Likes

i had this:

background: var(--background-image)
resources:
  - type: module
    url: /local/custom_ui/dark-sky-weather-card.js
  - type: module
    url: /local/custom_ui/tracker-card.js?track=true
  - type: module
    url: /local/custom_ui/button-card.js?track=true
  - type: module
    url: /local/custom_ui/mini-media-player-bundle.js
  - type: module
    url: /local/custom_ui/mini-graph-card-bundle.js?track=true
  - type: js
    url: /local/custom_ui/bar-card.js?v=1.0.0
button_card_templates:
  esxi_stats_general:
    styles:
      card:
        - background-color: '#837e80'
        - border-radius: 10%
        - padding: 10%
        - color: ivory
        - text-shadow: 0px 0px 1px black
        - text-transform: capitalize
      grid:
        - grid-template-columns: 1fr 1fr
        - grid-template-rows: 1fr min-content min-content min-content min-content
      icon:
        - width: 70%
        - margin-top: '-10%'
      name:
        - font-weight: bold
        - font-size: 13px
        - color: white
        - align-self: middle
        - justify-self: start
        - padding-bottom: 4px
      img_cell:
        - justify-content: start
        - align-items: start
        - margin: none
  esxi_stats_hosts:
    show_icon: false
    template: esxi_stats_general
    styles:
      grid:
        - grid-template-areas: >-
            "i uptime" "n n" "version version" "cpu_total cpu_total" "mem_total
            mem_total"
        - grid-template-columns: 1fr 1fr
        - grid-template-rows: min-content min-content min-content min-content
      custom_fields:
        version:
          - font-size: 12px
          - padding-bottom: 2px
          - align-self: middle
          - justify-self: start
        cpu_total:
          - font-size: 12px
          - padding-bottom: 2px
          - align-self: middle
          - justify-self: start
        mem_total:
          - font-size: 12px
          - padding-bottom: 2px
          - align-self: middle
          - justify-self: start
  esxi_stats_vm:
    icon: 'mdi:server'
    aspect_ratio: 1/1
    template: esxi_stats_general
    styles:
      grid:
        - grid-template-areas: '"i uptime" "n n" "cpu cpu" "ram ram" "state state"'
      custom_fields:
        uptime:
          - icon: 'mdi:arrow-up'
        cpu:
          - font-size: 12px
          - padding-bottom: 2px
          - align-self: middle
          - justify-self: start
        ram:
          - font-size: 12px
          - padding-bottom: 2px
          - align-self: middle
          - justify-self: start
        state:
          - font-size: 12px
          - padding-bottom: 2px
          - align-self: middle
          - justify-self: start
  esxi_stats_datastores:
    icon: 'mdi:harddisk'
    aspect_ratio: 1/1
    template: esxi_stats_general
    styles:
      grid:
        - grid-template-areas: '"i free" "n n" "capacity capacity" "hosts hosts" "vms vms"'
      custom_fields:
        capacity:
          - font-size: 12px
          - padding-bottom: 2px
          - align-self: middle
          - justify-self: start
        hosts:
          - font-size: 12px
          - padding-bottom: 2px
          - align-self: middle
          - justify-self: start
        vms:
          - font-size: 12px
          - padding-bottom: 2px
          - align-self: middle
          - justify-self: start
title: Home
views:
..........ect

Wow, this looks great. Do you mind sharing what you did to create this view?

Next I want to present some host networking information to allow us to monitor status - for example, if you have multiple physical adapters attached to a vswitch it would be helpful to see this in HASS and alert if one goes down.

That looks good - if you copy the templates from the github repo, you should only need to replace the names of your VMs to get it working.

What version of button card are you running? I am not an expert on button card, but i think some of the features only supported in later versions (2.0+). Maybe check the button card thread, I think the creator is active and should be able to help further

Thank you for the great feedback. The view itself leverages several different cards. This includes,

  • Bar Card (for the graphs)
  • Picture Card (For the image)
  • Button-Card (For the Headers)
  • Vertical and Horizontal Stack (for organizing cards within a row or column)
  • Vertical Stack In Card (for eliminating the gap between stacks)
  • Decluttering Card (used to create a template for each card so they can be easily reused).
  • Layout Card (Optional - Used for controlling the overall size and layout of the view itself)

From there I just used slightly modified versions of the Value Templates to create dedicated sensors for each attribute that I wanted to display. For example, I leveraged the Total Disk Space and Free Disk Space attributes to calculate a Used Disk Space value. The Used Disk Space and Total Disk Space sensors were then piped into Bar Card to create the bar itself.

Here is the YAML code I used to generate the Used Disk Space value. This needs to go inside of your sensor.yaml file. Make sure to replace the placeholder text ( i.e. <PLACEHOLDER>) with your desired entity names and actual datastore names.

  - platform: template
    sensors:
      <DESIRED_ENTITY_NAME>:  #This will be the entity name of your sensor. You can call this whatever you want.
        entity_id: sensor.esxi_stats_hosts # This is the default entity created by the ESXi Custom Component from which the attributes are pulled.
        friendly_name: 'ESXI Used Disk Space - Datastore 1' #Again, this can be whatever you want
        value_template: "{{ states['sensor.esxi_stats_datastores'].attributes.<DATASTORE_NAME_HERE>.total_space_gb - states['sensor.esxi_stats_datastores'].attributes.<DATASTORE_NAME_HERE>.free_space_gb | round () }}"
        unit_of_measurement: 'GBs'

One thing to note about the value_template - I had to add | round () to the template because one of my datastores returned a value with 14 decimal places! That bit of code limits the value to two decimal places, however it may not be necessary for other use cases.

To be honest, the hardest part was having to convert the attributes into dedicated sensor entities in order to leverage the associated values. The value templates on the github page were a huge help but I could see where novice HA users would be completely lost. Heck, it took me a while to wrap my head around the whole thing.

@wxt9861 Considering the nested nature of all the information (basically everything is nested below sensor.esxi_stats_hosts, esxi_stats_vms, or sensor.esxi_stats_datastores), would it be possible for the component to generate unique datastore and vm sensor entities rather than presenting them as nested attributes? This would make it much easier to leverage the data generated by the component. Just a thought.

1 Like

Thank you for the write up. I’d like to try something like this.

I don’t see a problem with that. Initially I nested it this way to keep the number of additional sensors lower, but the downsides are exactly what you described.

Breaking out each object into its own entity would certainly make things a lot easier. It would be a breaking change, but the upsides are easier management.

I would definitely be in favor of breaking out the data. I already have so many sensors I have to search for what I’m looking for anyways.

1 Like

Something like this.
With the entity name being something like - sensor.esxi_vm_<vm_name>
Also, the status can be anything - either status, uptime, state… maybe make it configurable via yaml/Integration UI.

Looks good to me! That’d be awesome. Do you have a way to grab total HDD space allocated to the Guest OS?

Shouldn’t be an issue

1 Like

Yes! This would be AWESOME!

Component just stopped to work for me… On description page I can see some information about issue wqith v4 and above if installed via HACS:

  • Due to addition of licenses sensor, the platform will fail to load after the reboot.
  • To fix - 1. restart Home Assistant 2. remove and re-add the integration from the Integrations UI

I followed these steps, but no change… all of sensors are unavailable. Any idea how to fix this?

Enable debug and open an issue case with the debug information on the github page. https://github.com/wxt9861/esxi_stats/issues