Custom Component - ESXi Stats

Thanks. Here’s a WIP of my individual server view. I’m about to install b2 so this is likely going to change a bit.

EDIT: The blank space is actually a card that won’t load. :smiley:

3 Likes

Finally had time to do some thorough troubleshooting and I think I found the culprit to my card loading problem. For whatever reason, if I configure a card to pull the value of a VM’s cpu_use_% attribute, the card either takes a very long time to load (flex-horseshoe-card), the card doesn’t load at all (>1% CPU usage on flex-horseshor-card) or pulls the default attribute of the VM instead (bar-card).

However, if cpu_use_% becomes the primary attribute of the entity_id, either as a unique sensor entity or via the Virtual Machine State Attribute Option, the values load correctly and the cards render immediately every time.

Another observation - Changing the Virtual Machine State Attribute requires a reboot of Home Assistant but does not prompt the user informing them of this requirement. Wasn’t sure whether or not this was intentional but figured it was worth mentioning. These test results were obtained against 0.5.0b2.

Now sure what to attribute this behavior to, but I changed cpu_usu_% to be 2 decimal places, so lets see how that works.

Changing the Virtual Machine State Attribute requires a reboot

Yes, I added this to documentation. Support for options via GUI was just released in HA recently, so I am not 100% if I’m just doing something wrong or that’s how it work. I’ll see if I can make it work without a reboot in later releases.

0.5.0 is out and includes the following changes.

  • Support to monitor multiple hosts/vCenters
  • All ESXi related objects (vm, datastore, etc) are now their own sensors. Using options UI, you can configure how their state is presented. See documentation for details
  • VM sensors now include guest IP address (as attribute)
  • License sensor now include host (as attribute) to which they are attached
  • VM sensor cpu_use_% value changed to display 2 decimal places
  • YAML is no longer supported, please use Integrations UI

This release is a breaking change, and hopefully the last one. In the future releases I’ll try to have the component handle breaking changes on its own.

If configured via Integrations UI

  1. Update the component
  2. Restart HASS - at this point, the component will fail to load. That’s ok
  3. Once HASS is back, go to Configuration > Integrations > ESXi Stats integrtion and remove it
  4. Add the Integrations back

if configured via YAML, use the Integrations UI

1 Like

thats cool :smiley: can you share the code of it?

I’ve posted the code over in the Flexible Horseshoe Card thread since it’s a more appropriate location. You can find my post here.

Example using flex-horseshoe-card added to esxi stats github.

Example

1 Like

two questions:

  1. How i can change the Status to a Icon?
    like this:
    Monitoring

  2. How i can set the Cardsize? :slight_smile:

I don’t see a way to set the card size within the configuration of this card, maybe some other custom card can be used here. I personally have all my VM stuff in its own tab with panel: true. In a horizontal stack I include 6 cards which scale to a size that is comfortable for me.

Icon configuration - for this to properly work with this card, you need to have the state of the sensor show information you want the icon to reflect.

For example, if you want the icon color based on VM running state, you need to have the Virtual Machine State Attribute set to ‘state’ (this is the default). Then you would change the decluttering template to the following. I added comments to show what I changed.

This will set the icon color to green if the VM is running, yellow if the VM is suspended, and grey if the VM is off.

vm_flex_template:
  card:
    type: 'custom:flex-horseshoe-card'
    entities:
      - entity: '[[entity]]'
        attribute: cpu_use_%
        decimals: 2
        unit: '%'
        area: CPU
        name: '[[name]]'
      - entity: '[[entity]]'
        name: 'Uptime'
        attribute: uptime_hours
        decimals: 0
        unit: 'H'
      - entity: '[[entity]]'
        name: Mem Use
        attribute: memory_used_mb
        unit: 'MB'
      - entity: '[[entity]]'
        name: 'Disk'
        attribute: used_space_gb
        decimals: 0
        unit: 'GB'
      - entity: '[[entity]]'
        name: 'Status'
        ## START - THIS IS ADDED TO SET THE ICON
        icon: mdi:server
        ## END
        unit: ' '
        attribute: status
    show:
      horseshoe_style: 'lineargradient'
      scale_tickmarks: true
    card_filter: card--dropshadow-none
    ## START - THIS IS ADDED TO SET ICON COLORS BASED ON STATE
    animations:
      entity.4:
        - state: 'running'
          icons:
            - animation_id: 0
              styles:
                - fill: green
        - state: 'suspended'
          icons:
            - animation_id: 0
              styles:
                - fill: yellow
        - state: 'off'
          icons:
            - animation_id: 0
              styles:
                - fill: grey
    ## END
    layout:
      hlines:
        - id: 0
          xpos: 50
          ypos: 38
          length: 70
          styles:
            - opacity: 0.2;
            - stroke-width: 4;
            - stroke-linecap: round;
      vlines:
        - id: 0
          xpos: 50
          ypos: 58
          length: 38
          styles:
            - opacity: 0.2;
            - stroke-width: 5;
            - stroke-linecap: round;
      states:
        - id: 0
          entity_index: 0
          xpos: 50
          ypos: 30
          styles:
            - font-size: 2.6em;
            - opacity: 0.9;
        - id: 1
          entity_index: 1
          xpos: 46
          ypos: 54
          styles:
            - font-size: 1.6em;
            - text-anchor: end;
        - id: 2
          entity_index: 2
          xpos: 54
          ypos: 54
          styles:
            - font-size: 1.6em;
            - text-anchor: start;
        - id: 3
          entity_index: 3
          xpos: 54
          ypos: 74
          styles:
            - font-size: 1.6em;
            - text-anchor: start;
       ## THIS IS REPLACED BY THE ICON     
       # - id: 4
       #   entity_index: 4
       #   xpos: 46
       #   ypos: 74
       #   styles:
       #     - font-size: 1.6em;
       #     - text-anchor: end;

      ## START - THIS IS ADDED TO REPLACE STATE WITH ICON 
      icons:
        - id: 0
          animation_id: 0
          xpos: 36
          ypos: 72
          entity_index: 4
          icon_size: 2.4
          styles:
            - color: var(--primary-text-color);
      ## END
      names:
        - id: 0
          xpos: 50
          ypos: 100
          entity_index: 0
          styles:
            - font-size: 1.3em;
            - opacity: 0.7;
            - opacity: 0.7;
        - id: 1
          xpos: 46
          ypos: 60
          entity_index: 1
          styles:
            - font-size: 0.8em;
            - text-anchor: end;
            - opacity: 0.6;
        - id: 2
          entity_index: 2
          xpos: 54
          ypos: 60
          styles:
            - font-size: 0.8em;
            - text-anchor: start;
            - opacity: 0.6;
        - id: 3
          xpos: 54
          ypos: 80
          entity_index: 3
          styles:
            - font-size: 0.8em;
            - text-anchor: start;
            - opacity: 0.6;
        - id: 4
          xpos: 46
          ypos: 80
          entity_index: 4
          styles:
            - font-size: 0.8em;
            - text-anchor: end;
            - opacity: 0.6;
      areas:
        - id: 0
          entity_index: 0
          xpos: 50
          ypos: 15
          styles:
            - font-size: 0.8em;
    horseshoe_state:
      color:  '#FFF6E3'
    horseshoe_scale:
      min: 0
      max: 100
      width: 3
    color_stops:
      05: '#FFF6E3'
      15: '#FFE9B9'
      25: '#FFDA8A'
      35: '#FFCB5B'
      45: '#FFBF37'
      55: '#ffb414'
      65: '#FFAD12'
      75: '#FFA40E'
      85: '#FF9C0B' 
      95: '#FF8C06' 

If you want to display icon color based on VM status (green/yellow/red/grey) you would need to change the Virtual Machine State Attribute to ‘status’ and then modify the automation section of the card to match possible states, like this:

    animations:
      entity.4:
        - state: 'green'
          icons:
            - animation_id: 0
              styles:
                - fill: green
        - state: 'yellow'
          icons:
            - animation_id: 0
              styles:
                - fill: yellow
        - state: 'red'
          icons:
            - animation_id: 0
              styles:
                - fill: red
        - state: 'grey'
          icons:
            - animation_id: 0
              styles:
                - fill: grey

I hope this helps.

OK :slight_smile:
this is my conifg - with it, i can’t see a icon :roll_eyes:

decluttering_templates:
  vm_flex_template:
    card:
      type: 'custom:flex-horseshoe-card'
      entities:
        - entity: '[[entity]]'
          attribute: cpu_use_%
          decimals: 2
          unit: '%'
          area: CPU
          name: '[[name]]'
        - entity: '[[entity]]'
          name: Uptime
          attribute: uptime_hours
          decimals: 0
          unit: H
        - entity: '[[entity]]'
          name: Mem Use
          attribute: memory_used_mb
          unit: MB
          icon: 'mdi:memory'
        - entity: '[[entity]]'
          name: Disk
          attribute: used_space_gb
          decimals: 0
          unit: GB
        - entity: '[[entity]]'
          name: Status
          icon: 'mdi:server'
          unit: ' '
          attribute: state
      show:
        horseshoe_style: lineargradient
        scale_tickmarks: true
      card_filter: card--dropshadow-none
      animations:
        entity.4:
          - state: running
            icons:
              - animation_id: 0
                styles:
                  - fill: green
          - state: suspended
            icons:
              - animation_id: 0
                styles:
                  - fill: yellow
          - state: 'off'
            icons:
              - animation_id: 0
                styles:
                  - fill: grey
      layout:
        hlines:
          - id: 0
            xpos: 50
            ypos: 38
            length: 70
            styles:
              - opacity: 0.2;
              - stroke-width: 4;
              - stroke-linecap: round;
        vlines:
          - id: 0
            xpos: 50
            ypos: 58
            length: 35
            styles:
              - opacity: 0.2;
              - stroke-width: 5;
              - stroke-linecap: round;
        states:
          - id: 0
            entity_index: 0
            xpos: 50
            ypos: 30
            styles:
              - font-size: 2.6em;
              - opacity: 0.9;
          - id: 1
            entity_index: 1
            xpos: 46
            ypos: 54
            styles:
              - font-size: 1.6em;
              - text-anchor: end;
          - id: 2
            entity_index: 2
            xpos: 54
            ypos: 54
            styles:
              - font-size: 1.6em;
              - text-anchor: start;
          - id: 3
            entity_index: 3
            xpos: 54
            ypos: 74
            styles:
              - font-size: 1.6em;
              - text-anchor: start;
        names:
          - id: 0
            xpos: 50
            ypos: 100
            entity_index: 0
            styles:
              - font-size: 1.3em;
              - opacity: 0.7;
              - opacity: 0.7;
          - id: 1
            xpos: 46
            ypos: 60
            entity_index: 1
            styles:
              - font-size: 0.8em;
              - text-anchor: end;
              - opacity: 0.6;
          - id: 2
            entity_index: 2
            xpos: 54
            ypos: 60
            styles:
              - font-size: 0.8em;
              - text-anchor: start;
              - opacity: 0.6;
          - id: 3
            xpos: 54
            ypos: 80
            entity_index: 3
            styles:
              - font-size: 0.8em;
              - text-anchor: start;
              - opacity: 0.6;
          - id: 4
            xpos: 46
            ypos: 80
            entity_index: 4
            styles:
              - font-size: 0.8em;
              - text-anchor: end;
              - opacity: 0.6;
        areas:
          - id: 0
            entity_index: 0
            xpos: 50
            ypos: 15
            styles:
              - font-size: 0.8em;
      horseshoe_state:
        color: '#FF0B0B'
      horseshoe_scale:
        min: 0
        max: 100
        width: 3
      color_stops:
        '5': '#E4FBFF'
        '15': '#FFE9B9'
        '25': '#FFDA8A'
        '35': '#FFCB5B'
        '45': '#FFBF37'
        '55': '#ffb414'
        '65': '#FFAD12'
        '75': '#FFA40E'
        '85': '#FF9C0B'
        '95': '#FF8C06'

i change the attribute to “state” and add the code

i change the attribute to “state” and add the code

Where did you change this? In the decluttering template or in the Integrations UI options? It needs to be set to state in Integrations UI options, like so:

also, if you changed it there, you’ll need to restart home assistant for change to reflect.

Looks like you forgot the “icons:” section between states: and names:. I did the same thing just now.

i look in the integration UI and have “state”

image

i mean i change it in the decluttering

        - entity: '[[entity]]'
          name: Status
          icon: 'mdi:server'
          unit: ' '
          attribute: state

you have in your attribute “status” but this does’t have the state “running” or i don’t understand this? :smile:

@ kryt1kal This was it! :smiley: thanks

and @wxt9861 your awesome!

Anyone else seeing these errors since updating to the latest version?

2019-12-12 17:59:19 ERROR (MainThread) [custom_components.esxi_stats.sensor] State is set to incorrect key. Check Options in Integration UI

This one is VM specific but is occurring against both of my Windows Server 2016 Domain Controllers.

2019-12-12 17:58:52 WARNING (MainThread) [homeassistant.helpers.condition] Value cannot be processed as a number: <state sensor.esxi_vm_dc01=Error; name=dc01, status=green, state=running, uptime_hours=3619.8, cpu_count=1, cpu_use_pct=131.52, memory_allocated_mb=4096, memory_used_mb=4132, used_space_gb=43.66, tools_status=toolsOk, guest_os=Microsoft Windows Server 2016 (64-bit), guest_ip=<redacted>, snapshots=0, unit_of_measurement=, friendly_name=ESXi vm dc01 @ 2019-12-12T13:00:53.426207-08:00> (Offending entity: Error)

Do you happen to have cpu_use_% as a VM State attribute set in options? Can you check your Integration Options (Configuration > Integrations > ESXi Stats) and share what you have set there?

I can’t say for certain since those fields were blank when I went back to review the settings. I suspect the blank field is what triggered all of the repetitive warnings. That said, configuring the missing setting and restarting HA resolved the issue.

Interesting that it was blank. I told it to set defaults if nothing is configured… Glad to hear it is fixed, though.

I am trying to use this component’s service call to reboot/shutdown VM.

I defined an input_select dropdown with options containing the VM name like this:

reboot_options:
  name: Reboot Computer
  options:
    - Plex01
    - Webserv01
    - Win10vm01
    - None
  initial: None
  icon: mdi:restart

script / automaton

service: esxi_stats.vm_power
data:
     host: 192.168.2.246
     vm: '{{ states.input_select.reboot_options.state }}'   (This normally looks like vm: Plex01)
     command: 'reboot'

I want the “vm” to be based on the input_select.reboot_options.

Any ideas of a script or automation to make this work. I have about 12 VMs, so individual scripts / automations makes maintenance difficult.

I think “use-templates-to-determine-the-attributes” section should help you out.