!include_dir_merge_list not working

I have 2 files in the restful dir and want to include them with !include_dir_merge_list, but it’s not wokring. Only file2.yaml works and even some of the sensors from that file are broken (they report 0 when they definitely shouldn’t). The configured sensor from the other module reports entity unreachable.

Both of the files work without issues separately.
If I combine them manually into a single file there is no issue either. (Edit: I added some other sensors to file2.yaml and as it turns out combining them manually also breaks it, I just couldn’t notice before because of the string based sensor)
Tried all of the !include_dir_* methods but none of them are working.

I’m running HA in a docker container:

~/homeassistant $ ls -l restful/
total 12
-rw-r--r-- 1 root root  408 Apr  9 18:51 file1.yaml
-rw-r--r-- 1 root root 6329 Apr  9 19:28 file2.yaml

config.yaml:

rest: !include_dir_merge_list restful

file1.yaml:

- scan_interval: 60
  resource: https://REDACTED
  sensor:
    - name: "Status"
      value_template: "{{ value_json.status }}"

file2.yaml:

- scan_interval: 60
  resource: http://REDACTED
  sensor:
    - name: "CPU Temperature (average)"
      value_template: "{% for elem in value_json if elem.SensorName == 'CPU Die (average)' %}{{ '%0.2f' | format (elem.SensorValue | regex_replace(',', '.') | float)}}{% endfor %}"
      device_class: temperature
      unit_of_measurement: "°C"
    - name: "CPU Core 0 Clock"
      value_template: "{% for elem in value_json if elem.SensorName == 'Core 0 Clock' %}{{ '%0.2f' | format (elem.SensorValue | regex_replace(',', '.') | float)}}{% endfor %}"
      unit_of_measurement: "MHz"
    - name: "CPU PPT"
      value_template: "{% for elem in value_json if elem.SensorName == 'CPU PPT' %}{{ '%0.3f' | format (elem.SensorValue | regex_replace(',', '.') | float)}}{% endfor %}"
      device_class: power
      unit_of_measurement: "W"
    - name: "CPU Load"
      value_template: "{% for elem in value_json if elem.SensorName == 'CPU Total' %}{{ '%0.2f' | format (elem.SensorValue | regex_replace(',', '.') | float)}}{% endfor %}"
      unit_of_measurement: "%"
    - name: "Memory Load"
      value_template: "{% for elem in value_json if elem.SensorName == 'Generic Memory: Memory' %}{{ '%0.2f' | format (elem.SensorValue | regex_replace(',', '.') | float)}}{% endfor %}"
      unit_of_measurement: "%"
    - name: "GPU Temperature"
      value_template: "{% for elem in value_json if elem.SensorName == 'GPU Temperature' %}{{ '%0.2f' | format (elem.SensorValue | regex_replace(',', '.') | float)}}{% endfor %}"
      device_class: temperature
      unit_of_measurement: "°C"
    - name: "GPU Core Voltage"
      value_template: "{% for elem in value_json if elem.SensorName == 'GPU Core Voltage' %}{{ '%0.3f' | format (elem.SensorValue | regex_replace(',', '.') | float)}}{% endfor %}"
      device_class: voltage
      unit_of_measurement: "V"
    - name: "GPU Power"
      value_template: "{% for elem in value_json if elem.SensorName == 'GPU Power' %}{{ '%0.3f' | format (elem.SensorValue | regex_replace(',', '.') | float)}}{% endfor %}"
      device_class: power
      unit_of_measurement: "W"
    - name: "GPU Core Clock"
      value_template: "{% for elem in value_json if elem.SensorName == 'GPU Clock' %}{{ '%0.2f'| format (elem.SensorValue | regex_replace(',', '.') | float)}}{% endfor %}"
      unit_of_measurement: "MHz"
    - name: "GPU Memory Clock"
      value_template: "{% for elem in value_json if elem.SensorName == 'GPU Memory Clock' %}{{ '%0.2f' | format ((elem.SensorValue | regex_replace(',', '.') | float) * 4)}}{% endfor %}"
      unit_of_measurement: "MHz"
    - name: "GPU Core Load"
      value_template: "{% for elem in value_json if elem.SensorName == 'GPU Core Load' %}{{ elem.SensorValue | regex_replace(',', '.') | int}}{% endfor %}"
      unit_of_measurement: "%"
    - name: "GPU Memory Usage"
      value_template: "{% for elem in value_json if elem.SensorName == 'GPU Memory Usage' %}{{ elem.SensorValue | regex_replace(',', '.') | int}}{% endfor %}"
      unit_of_measurement: "%"
    - name: "GPU Memory Controller Load"
      value_template: "{% for elem in value_json if elem.SensorName == 'GPU Memory Controller Load' %}{{ elem.SensorValue | regex_replace(',', '.') | int}}{% endfor %}"
      unit_of_measurement: "%"
    - name: "GPU Fan"
      value_template: "{% for elem in value_json if ((elem.SensorName == 'GPU Fan1') and (elem.SensorUnit == '%')) %}{{ elem.SensorValue | regex_replace(',', '.') | int}}{% endfor %}"
      unit_of_measurement: "%"
    - name: "GPU Fan (rpm)"
      value_template: "{% for elem in value_json if ((elem.SensorName == 'GPU Fan1') and (elem.SensorUnit == 'RPM')) %}{{ elem.SensorValue | regex_replace(',', '.') | int}}{% endfor %}"
      unit_of_measurement: "rpm"

Read 2021.4: For our advanced users ❤️
“it works as soon as the automation has an id set”

Where should I be adding that? Simply adding it to the top, removing the list (-) and changing to !include_dir_list results in:
Invalid config for [rest]: [id] is an invalid option for [rest]. Check: rest->rest->0->id. (See ?, line ?). Please check the docs at https://www.home-assistant.io/integrations/rest

I’m not sure that the response from Vlad was meant for you…

but try putting a ‘/’ on the end of restful to denote it as a folder:

rest: !include_dir_merge_list restful/

I tried, but sadly it doesn’t solve it.

And you restarted HA after changing it?

if so I’m not sure why it’s not working.

It looks right to me.

Of course. One terminal has hundreds of lines restarting HA to test all the things I tried to solve it. :sweat_smile:

1 Like

I’ll do following:

  1. Remove or comment out
rest: !include_dir_merge_list restful
  1. Move files file1.yaml and file2.yaml to sensors folder.
  2. Add to configuration.yaml
sensor: !include_dir_merge_list sensor/

Restart HA.

That won’t work.
I’m using this method so I can make 1 rest call and create multiple sensors from it.
If I move them to sensors I need to change the whole setup, and do as many rest calls as sensors.

I’m using it, but it’s a sensor (located in sensor directory) in my case and only one file and I’m creating a lot of sensors:

  - platform: rest
    name: Tablet
    json_attributes:
      - batteryLevel
      - kioskMode
      - screenBrightness
      - motionDetectorStatus
      - maintenanceMode
      - appFreeMemory
      - appUsedMemory
      - totalFreeMemory
      - totalUsedMemory
      - ip4
      - Mac
      - locationLatitude
      - locationLongitude
      - locationAltitude
      - startUrl
      - currentPage
    resource: !secret foo_rest
    value_template: '{{ value_json.screenOn }}'
  - platform: template
    sensors:
      tablet_battery_level:
        friendly_name: Battery
        value_template: "{{ state_attr('sensor.tablet', 'batteryLevel') }}"
        icon_template: >-
          {% set battery_level = state_attr("sensor.tablet","batteryLevel")|int('unknown') %}
          {% set battery_round = (battery_level|int / 10)|int * 10 %}
          {% set charge_status = state_attr("sensor.tablet","batteryLevel") %}
          {% if battery_level == 'unknown' %}
            mdi:battery-unknown
          {% else %}
            {% if charge_status == True %}
              {% if battery_round > 0 %}
                mdi:battery-charging-{{ battery_round }}
              {% else %}
                mdi:battery-charging-outline
              {% endif %}
            {% else %}
              {% if battery_round >= 100 %}
                mdi:battery
              {% elif battery_round > 0 %}
                 mdi:battery-{{ battery_round}}
              {% else %}
                mdi:battery-alert
              {% endif %}
            {% endif %}
          {% endif %}"
      tablet_kiosk:
        friendly_name: Kiosk Mode
        value_template: "{{ state_attr('sensor.tablet', 'kioskMode') }}"
        icon_template: "mdi:globe-model"
      tablet_screen:
        friendly_name: Screen Brightness
        value_template: "{{ state_attr('sensor.tablet', 'screenBrightness') }}"
        icon_template: "mdi:brightness-percent"
      tablet_motion:
        friendly_name: Motion State
        value_template: "{{ state_attr('sensor.tablet', 'motionDetectorStatus') }}"
        icon_template: "mdi:motion-sensor"
      tablet_maintenance:
        friendly_name: Maintenance Mode
        value_template: "{{ state_attr('sensor.tablet', 'maintenanceMode') }}"
        icon_template: "mdi:brightness-percent"
      tablet_freememory:
        friendly_name: Free Memory
        value_template: "{{ state_attr('sensor.tablet', 'appFreeMemory') }}"
        unit_of_measurement: 'GB'
        icon_template: "mdi:memory"
      tablet_usedmemory:
        friendly_name: Used Memory
        value_template: "{{ state_attr('sensor.tablet', 'appUsedMemory') }}"
        unit_of_measurement: 'GB'
        icon_template: "mdi:memory"
      tablet_ip:
        friendly_name: IP
        value_template: "{{ state_attr('sensor.tablet', 'ip4') }}"
        icon_template: "mdi:server"
      tablet_mac:
        friendly_name: MAC
        value_template: "{{ state_attr('sensor.tablet', 'Mac') }}"
        icon_template: "mdi:map-marker"

I tried doing this, but the problem is that it doesn’t really support responses in an array like:

[
  {
    "some_attribute" : "some_value",
    "other_attribute" : "other_value"
  },
  {
    "some_attribute" : "some_value",
    "other_attribute" : "other_value"
  },
  ...
]

Can you show output from your resource?

It looks like this, only a lot more more entries. Truncated it a bit to copy here.

[
  {
    "SensorApp": "HWiNFO",
    "SensorClass": "System: MSI MS-7B85",
    "SensorName": "Virtual Memory Commited",
    "SensorValue": "22074",
    "SensorUnit": "MB",
    "SensorUpdateTime": 1618068445
  },
  {
    "SensorApp": "HWiNFO",
    "SensorClass": "System: MSI MS-7B85",
    "SensorName": "Virtual Memory Available",
    "SensorValue": "7573",
    "SensorUnit": "MB",
    "SensorUpdateTime": 1618068445
  },
  {
    "SensorApp": "HWiNFO",
    "SensorClass": "System: MSI MS-7B85",
    "SensorName": "Virtual Memory Load",
    "SensorValue": "74,4",
    "SensorUnit": "%",
    "SensorUpdateTime": 1618068445
  },
  {
    "SensorApp": "HWiNFO",
    "SensorClass": "System: MSI MS-7B85",
    "SensorName": "Physical Memory Used",
    "SensorValue": "7817",
    "SensorUnit": "MB",
    "SensorUpdateTime": 1618068445
  },
  {
    "SensorApp": "HWiNFO",
    "SensorClass": "System: MSI MS-7B85",
    "SensorName": "Physical Memory Available",
    "SensorValue": "8518",
    "SensorUnit": "MB",
    "SensorUpdateTime": 1618068445
  },
  {
    "SensorApp": "HWiNFO",
    "SensorClass": "System: MSI MS-7B85",
    "SensorName": "Physical Memory Load",
    "SensorValue": "47,8",
    "SensorUnit": "%",
    "SensorUpdateTime": 1618068445
  },
  {
    "SensorApp": "HWiNFO",
    "SensorClass": "System: MSI MS-7B85",
    "SensorName": "Page File Usage",
    "SensorValue": "9,57753108097957",
    "SensorUnit": "%",
    "SensorUpdateTime": 1618068445
  },
  {
    "SensorApp": "Open Hardware Monitor",
    "SensorClass": "Load",
    "SensorName": "Generic Memory: Memory",
    "SensorValue": "47,92204",
    "SensorUnit": "%",
    "SensorUpdateTime": 0
  },
  {
    "SensorApp": "Open Hardware Monitor",
    "SensorClass": "Data",
    "SensorName": "Generic Memory: Used Memory",
    "SensorValue": "7,645138",
    "SensorUnit": null,
    "SensorUpdateTime": 0
  },
  {
    "SensorApp": "Open Hardware Monitor",
    "SensorClass": "Data",
    "SensorName": "Generic Memory: Available Memory",
    "SensorValue": "8,308144",
    "SensorUnit": null,
    "SensorUpdateTime": 0
  },
  {
    "SensorApp": "Open Hardware Monitor",
    "SensorClass": "Load",
    "SensorName": "Generic Hard Disk: Used Space",
    "SensorValue": "75,1957",
    "SensorUnit": "%",
    "SensorUpdateTime": 0
  }
]

Use :
SensorName[0],
SensorValue[0],
SensorName[1],
SensorValue[1],
SensorName[2]
SensorValue[2]
and so on

For json_attributes? I don’t think that would work, JSONPath evaluator doesn’t like it.
I tried with [0].SensorValue but that didn’t work.
It worked with:

json_attributes_path: "$.[0]"
json_attributes:
   - SensorValue

but that only gives me one sensor.

Go to https://jsoneditoronline.org/#left=local.taluhe&right=local.fahinu

That look like a nice tool, but I don’t quite understand how that could help me here.

Using JSONPath evaluator I can get any value.

$.*, or
0:1.SensorValue
1:2.SensorValue
2:3.SensorValue

Tried these 3:

- platform: rest
  name: remote_test
  resource: REDACTED
  value_template: "OK"
  json_attributes_path: "$.*"
  json_attributes:
    - "[0]"
- platform: template
  sensors:
    remote_test_sensor:
      value_template: "{{ states.sensor.remote_test.attributes[0].SensorValue }}"
- platform: rest
  name: remote_test
  resource: REDACTED
  value_template: "OK"
  json_attributes_path: "$.*"
  json_attributes:
    - "0:1.SensorValue"
- platform: template
  sensors:
    remote_test_sensor:
      value_template: "{{ states.sensor.remote_test.attributes[0].SensorValue }}"
- platform: rest
  name: remote_test
  resource: REDACTED
  value_template: "OK"
  json_attributes:
    - "$.*"
- platform: template
  sensors:
    remote_test_sensor:
      value_template: "{{ states.sensor.remote_test.attributes[0].SensorValue }}"

But in either case the json attributes aren’t added to remote_test.
remote_test_sensor is unavailable because of that.