@tom_l (or anyone here). I’m still getting the log errors below continuously; although, I did fix a completely different issue.
2021-04-28 20:04:25 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: dict object has no element 0 when rendering '{{ value_json[0] }}'
2021-04-28 20:04:36 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: dict object has no element 0 when rendering '{{ value_json[0] }}'
I only have two other REST sensors that use '{{ value_json[0] }}'
& '{{ value_json[1] }}'
… they are below. What could be causing these continuous errors? All my sensors seem to display correctly in Lovelace cards, at least.
- name: diskio_0
value_template: '{{ value_json[0] }}'
json_attributes_path: "$.diskio.0"
json_attributes:
- time_since_update
- disk_name
- read_bytes
- write_bytes
- name: diskio_1
value_template: '{{ value_json[1] }}'
json_attributes_path: "$.diskio.1"
json_attributes:
- time_since_update
- disk_name
- read_bytes
- write_bytes
The respective returned data is:
"diskio": [
{
"time_since_update": 11.011141300201416,
"disk_name": "PhysicalDrive0",
"read_count": 37,
"write_count": 119,
"read_bytes": 227840,
"write_bytes": 36214784,
"key": "disk_name"
},
{
"time_since_update": 11.011141300201416,
"disk_name": "PhysicalDrive1",
"read_count": 238,
"write_count": 0,
"read_bytes": 28854272,
"write_bytes": 0,
"key": "disk_name"
}
],
PS: In case it’s relevant, below, are the respective templates for these two sensors:
sensor:
- platform: template
sensors:
horizon_c_drive_read_bytes:
value_template: >-
{% set read_byte = state_attr('sensor.diskio_0', 'read_bytes') %}
{% set time_since = state_attr('sensor.diskio_0', 'time_since_update') %}
{% if (read_byte != None ) and (time_since != None ) %}
{{ ((read_byte | int) / (time_since | int) / 1000000) | round (2) }}
{% endif %}
availability_template: >-
{{ states("sensor.diskio_0") not in ["unknown", "unavailable", "none"] }}
unit_of_measurement: 'MB/s'
- platform: template
sensors:
horizon_c_drive_write_bytes:
value_template: >-
{% set write_byte = state_attr('sensor.diskio_0', 'write_bytes') %}
{% set time_since = state_attr('sensor.diskio_0', 'time_since_update') %}
{% if (write_byte != None ) and (time_since != None ) %}
{{ ((write_byte | int) / (time_since | int) / 1000000) | round (2) }}
{% endif %}
availability_template: >-
{{ states("sensor.diskio_0") not in ["unknown", "unavailable", "none"] }}
unit_of_measurement: 'MB/s'
- platform: template
sensors:
horizon_e_drive_read_bytes:
value_template: >-
{% set read_byte = state_attr('sensor.diskio_1', 'read_bytes') %}
{% set time_since = state_attr('sensor.diskio_1', 'time_since_update') %}
{% if (read_byte != None ) and (time_since != None ) %}
{{ ((read_byte | int) / (time_since | int) / 1000000) | round (2) }}
{% endif %}
availability_template: >-
{{ states("sensor.diskio_1") not in ["unknown", "unavailable", "none"] }}
unit_of_measurement: 'MB/s'
- platform: template
sensors:
horizon_e_drive_write_bytes:
value_template: >-
{% set write_byte = state_attr('sensor.diskio_1', 'write_bytes') %}
{% set time_since = state_attr('sensor.diskio_1', 'time_since_update') %}
{% if (write_byte != None ) and (time_since != None ) %}
{{ ((write_byte | int) / (time_since | int) / 1000000) | round (2) }}
{% endif %}
availability_template: >-
{{ states("sensor.diskio_1") not in ["unknown", "unavailable", "none"] }}
unit_of_measurement: 'MB/s'