custom-cards / flex-table-card

Highly Flexible Lovelace Card - arbitrary contents/columns/rows, regex matched, perfect to show appdaemon created content and anything breaking out of the entity_id + attributes concept
GNU General Public License v3.0
198 stars 23 forks source link

Multiple attributes with same name aren't shown #57

Closed DreadN closed 10 months ago

DreadN commented 2 years ago

Trying to visualize the "faultType" or also "Since" attribute in this entity. But nothing is visualized, even if i put comma between same value two times.

If i put this in data:

columns:
  - name: Alerts
    data: faultType,since

Result is: "null, null"

If i put this in fata:

columns:
  - name: Alerts
    data: faultType

Result is: "undefined"


Entity data:

hvac_modes:
  - 'off'
  - heat
min_temp: 5
max_temp: 35
preset_modes:
  - none
  - temporary
  - permanent
current_temperature: 23
temperature: 30
preset_mode: permanent
status:
  setpoints:
    this_sp_from: '2021-08-04T18:00:00+02:00'
    this_sp_temp: 19.5
    next_sp_from: '2021-08-04T22:30:00+02:00'
    next_sp_temp: 17
  zone_id: '5526090'
  active_faults:
    - faultType: TempZoneSensorLowBattery
      since: '2021-08-03T14:27:54'
    - faultType: TempZoneActuatorLowBattery
      since: '2021-08-03T15:26:48'
  setpoint_status:
    target_heat_temperature: 30
    setpoint_mode: PermanentOverride
  temperature_status:
    temperature: 23.5
    is_available: true
friendly_name: Bagno
icon: mdi:radiator
supported_features: 17
daringer commented 2 years ago

yes, this is clearly a limitation currently. But you might use modify to descent into the lists and select the next unique identifier, roughly like this:

columns:
  - name: "1st Alert"
    data: active_faults
    modify: x[0].faultType
  - name: "2nd Alert"
    data: active_faults
    modify: x[1].faultType
DreadN commented 2 years ago

Unfortunately it doesn't work as intended, because when there's no fault, the array under "active_faults" is empty, and the "modify:" statements throws error.

But I appreciate the suggestion.

Main problem is from EvoHome integration that is not well structured and has too many nested information instead of having plain attributes or sensors.

Thanks.

daringer commented 2 years ago

well modify: is in fact java-script code, which means could do arbitrary complex stuff and reformat your data as you wish... something simple would be e.g.,:

modify: (x.isArray() && x.length > 0)  ?  x.map( (item) => `${item['faultType']} ${item['since']}` ).join("<br />") : "no failures"

(untested, be careful) but this would write all faults separated by a linebreak into one cell, but if the array is empty, simple report this... You could also check the project's (closed) ticket history, there have been ppl with multi-line js-code... in theory that's clearly possible, but I fully understand that this is by far not comfortable, nor something for everyone...

Yes, this clearly (again) increases the need for a json-per-column-selector within flex-table-card