Custom Component - ESXi Stats

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.

Thx @wxt9861 for the component and tip

For the benefit of others here is a working version of the script to select vm/command based on attributes

vm_power_action:
  alias: VM Action
  sequence:
    - service: esxi_stats.vm_power
      data:
        host: 192.168.2.246
      data_template:
          vm: >
            {% if is_state  ('input_select.reboot_options', 'vm1') %} VM_1
            {% elif is_state('input_select.reboot_options', 'vm2') %} VM_2
            {% else %}
                 None
            {% endif %}
          command: >
            {% if is_state  ('input_select.action_options', 'Reboot') %} reboot
            {% elif is_state('input_select.action_options', 'Shutdown') %} shutdown
            {% elif is_state('input_select.action_options', 'On') %} on
            {% elif is_state('input_select.action_options', 'Off') %} off
            {% else %}
                 None
            {% endif %}

It appears that one of my previously reported errors is still present in the home-assistant.log file. There appears to be some sort of value mismatch as the sensor is expecting a number but is getting a string, in this case green.

This occurs on both of my Windows Server 2016 VMs but none of the other OS VMs, including Windows 7.

[homeassistant.helpers.condition] Value cannot be processed as a number: <state 
sensor.esxi_vm_dc01=green; name=dc01, status=green, state=running, 
uptime_hours=3858.9, cpu_count=1, cpu_use_pct=0.89, memory_allocated_mb=4096, 
memory_used_mb=4133, used_space_gb=43.71, tools_status=toolsOk, 
guest_os=Microsoft Windows Server 2016 (64-bit), guest_ip=<redacted>, snapshots=0, 
unit_of_measurement=Status, friendly_name=ESXi vm dc01 @ 2019-12-
22T17:05:48.460155-08:00> (Offending entity: green)

I need to take a deeper dive into this - at first glance it looks like HA doesnā€™t like the value of ā€˜greenā€™ for the sensor output and is expecting a number? Maybeā€¦ but if it did, Iā€™d expect that same behavior for all the sensors not just windows VMs. Also not sure if the error is introduced in 0.5.1 ESXi stats release or if some change in latest HA release. Iā€™ll try to replicate it and go from there.