Custom Component - ESXi Stats

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

Done with some additional support information.

Solved! I added step to uninstall and install again from HACS before removing/adding via integration UI and it properly started this time. Perhaps installation got somehow corrupted during recovery from SD crash that I have few days ago…

1 Like

0.5.0beta is available. If you can, please test and provide feedback.

Changes here are:

  • All objects (hosts, datastores, licenses, vms) have been broken out into their own sensors. So instead of 4 sensors you will now have many sensors.
  • You can control what is being show as a state of the sensors. For example, you can set your VM sensors to show their CPU Usage % as the state. And if you decide later to show uptime, you can change that at any time.
    • This is only available if you’re using Integrations UI to configure the platform. If you’re using yaml mode, you’re stuck with the defaults
    • This can be accessed by going to the ESXi Stats configurion UI page and clicking on the gears icon in the upper right corner
    • Initially default values are entered, but you can change them to be any attribute available in a sensor
  • Minimum version of HA required to run this release is 0.98 (because of 2nd bullet point)

Some of the things that still need work:

  • If the platform pulls data for a new object (ex. you add a new datastore), the sensor for that new object will now show up until hass is restarted.
  • Sensors are trying to show a graph, instead of a history bar, when there are no numerical values to show. I think this has to do with device class and unit_of_measurement but I am not 100% certain

Any help to point me in the right direction for these issues would be appreciated.

1 Like

Awesome work!! I’ll have to update my HA before I can test, but I’ll try to this week!

Some initial feedback.

Upgrading to the beta was painless through HACS but my pre-existing integration did not like the new version. All kinds of errors popped up in the home-assistant.log and the pre-existing functionality ceased. To fix the issue, I simply blew away the integration and re-added it. After that, all of the sensors were added as expected.

One initial observation is that the switches and network_adapters attributes for the VM Host have their own nested data (See example below). You might want to consider breaking these out into their own sensors as well, while you are at it. My example may not be very elaborate, but others may have more intricacies.

I’ll try to play around with this once I’m home later tonight and see what else I can accomplish with the new functionality. Still, this new functionality is very exciting!

switches: {
  "vSwitch0": [
    "VM Network",
    "ISCSI-B",
    "Management Network"
  ]
}
network_adapters: {
  "vmnic0": 1000,
  "vmnic32": 1000
}