Parsing multiple JSON values from a current HA sensor NOT a URL

Playing around with this new component: https://github.com/wxt9861/esxi_stats.
I am trying to parse a long json but this doesn’t seem like it can be done by a rest sensor since the information is coming from an internal sensor.

Examples:
The sensor: sensor.esxi_stats_hosts
with a numeric state: 28
and json state attributes:

{
  "hassio": {
    "name": "hassio",
    "status": "green",
    "state": "running",
    "uptime_hours": 15.1,
    "cpu_count": 1,
    "cpu_use_%": 44,
    "memory_allocated_mb": 1024,
    "memory_used_mb": 1092,
    "used_space_gb": 8.29,
    "tools_status": "toolsOk",
    "guest_os": "Ubuntu Linux (64-bit)"
  },
  "callforce01": {
    "name": "callforce01",
    "status": "green",
    "state": "running",
    "uptime_hours": 35.5,
    "cpu_count": 1,
    "cpu_use_%": 23,
    "memory_allocated_mb": 4096,
    "memory_used_mb": 3907,
    "used_space_gb": 44.99,
    "tools_status": "toolsOk",
    "guest_os": "Microsoft Windows 7 (64-bit)"
  },
  "dsu-vdi2": {
    "name": "dsu-vdi2",
    "status": "green",
    "state": "off",
    "uptime_hours": "n/a",
    "cpu_count": 1,
    "cpu_use_%": "n/a",
    "memory_allocated_mb": 2048,
    "memory_used_mb": "n/a",
    "used_space_gb": 29.06,
    "tools_status": "toolsNotRunning",
    "guest_os": "Microsoft Windows 7 (64-bit)"
  },

I am trying to create an automation where when any of the devices change from “status”: “green”. It sends a notification of the device’s name (e.g. “name”: “callforce01”).

Similarly there is another sensor sensor.esxi_stats_datastores
with a numeric state: 8
and json state attributes:

{
  "sso14-local": {
    "name": "sso14-local",
    "type": "vmfs",
    "free_space_gb": 127.55,
    "total_space_gb": 128.5,
    "connected_hosts": 1,
    "virtual_machines": 0
  },
  "sso15-local": {
    "name": "sso15-local",
    "type": "vmfs",
    "free_space_gb": 59.8,
    "total_space_gb": 60.75,
    "connected_hosts": 1,
    "virtual_machines": 0
  },
  "sso16-local": {
    "name": "sso16-local",
    "type": "vmfs",
    "free_space_gb": 59.8,
    "total_space_gb": 60.75,
    "connected_hosts": 1,
    "virtual_machines": 0
  },

Here I am trying to create an automation for free space percentage ((“free_space_gb”: 59.8 / “total_space_gb”: 60.75) * 100). When this value for any of the devices falls below 30%. It sends a notification of the device’s name (e.g. “name”: “sso14-local”).

Any help is appreciated!

Have you considered creating a Template Sensor to monitor the status attribute? When this Template Sensor changes state (from green to something else) it can be used as a trigger within an automation.

How would a do that with multiple states under 1 sensor?

I can help you achieve your goal but first you have to help me understand the esxi_stats component. What are the names of the attributes for sensor.esxi_stats_hosts?

Does it have three attributes called:

  1. hassio
  2. callforce01
  3. dsu-vdi2

Or is it one attribute containing the complex dictionary structure you posted above? If it is, what is this attribute’s name?

It’s one attribute with a complex dictionary structure:

{
  "sso14-local": {
    "name": "sso14-local",
    "type": "vmfs",
    "free_space_gb": 127.55,
    "total_space_gb": 128.5,
    "connected_hosts": 1,
    "virtual_machines": 0
  },
  "sso15-local": {
    "name": "sso15-local",
    "type": "vmfs",
    "free_space_gb": 59.8,
    "total_space_gb": 60.75,
    "connected_hosts": 1,
    "virtual_machines": 0
  },
  "sso16-local": {
    "name": "sso16-local",
    "type": "vmfs",
    "free_space_gb": 59.8,
    "total_space_gb": 60.75,
    "connected_hosts": 1,
    "virtual_machines": 0
  },
  "veeambackup_sso06-wap-v.smilesltd.com": {
    "name": "veeambackup_sso06-wap-v.smilesltd.com",
    "type": "nfs",
    "free_space_gb": 66.27,
    "total_space_gb": 139.9,
    "connected_hosts": 1,
    "virtual_machines": 0
  },
  "nfs-datastore01": {
    "name": "nfs-datastore01",
    "type": "nfs",
    "free_space_gb": 5871.05,
    "total_space_gb": 10998.25,
    "connected_hosts": 3,
    "virtual_machines": 5
  },
  "nfs-datastore02": {
    "name": "nfs-datastore02",
    "type": "nfs",
    "free_space_gb": 3611.85,
    "total_space_gb": 5356.65,
    "connected_hosts": 3,
    "virtual_machines": 17
  },
  "nfs-datastore03": {
    "name": "nfs-datastore03",
    "type": "nfs",
    "free_space_gb": 1227.25,
    "total_space_gb": 1829.36,
    "connected_hosts": 3,
    "virtual_machines": 13
  },
  "sspdnas-datastore": {
    "name": "sspdnas-datastore",
    "type": "nfs",
    "free_space_gb": 5871.04,
    "total_space_gb": 10998.25,
    "connected_hosts": 3,
    "virtual_machines": 2
  },
  "unit_of_measurement": "datastore(s)",
  "friendly_name": "ESXi Stats datastores"
}

OK. Whatever is the name of that attribute is what you will use to replace `attribute_name’ in the following Template Sensor:

  - platform: template
    sensors:
      hassio_status:
        friendly_name: 'HASS.IO Status'
        value_template: "{{ (state_attr('sensor.esxi_stats_hosts', 'attribute_name')).hassio.status }}"

Here’s what the value_template does:

  • It uses the state_attr function to acquire the value of attribute_name from sensor.esxi_stats_hosts.
  • The resulting value is a dictionary structure and .hassio.status references the desired value.

The resulting Template Sensor will be sensor.hassio_status and its state will be ‘green’ (or whatever color represents its current status).

This led me into the right direction.

the value_template would be:
{{ state_attr(‘sensor.esxi_stats_vms’, ‘hassio’).status }}

Got this to work.

Thanks!!