custom-cards / entity-attributes-card

Entity Attributes
Apache License 2.0
68 stars 12 forks source link

What to do if a sensor has an attribute in the form of an array? #17

Open ericvb opened 4 years ago

ericvb commented 4 years ago

What to do if a sensor has an attribute in the form of an array like the attribute next_passages?

sensor.kerk

attribution: Data provided by data.delijn.be
stopname: Kerk
line_number_public: 2
line_transport_type: BUS
final_destination: Antwerpen
due_at_schedule: 2020-05-28T17:42:00+00:00
due_at_realtime: 2020-05-28T17:42:00+00:00
next_passages: 
- passage: 0
  line_number: 800
  direction: HEEN
  final_destination: Antwerpen
  due_at_schedule: '2020-05-28T17:42:00+00:00'
  due_at_realtime: '2020-05-28T17:42:00+00:00'
  due_in_min: 16
  is_realtime: false
  line_number_public: '2'
  line_desc: Diplomatenwijk
  line_transport_type: BUS
  line_number_colourFront: WI
  line_number_colourFrontHex: FFFFFF
  line_number_colourBack: GR
  line_number_colourBackHex: '229922'
  line_number_colourFrontBorder: ZW
  line_number_colourFrontBorderHex: '000000'
  line_number_colourBackBorder: GR
  line_number_colourBackBorderHex: '229922'
  stopname: 'Kerk'
- passage: 1
  line_number: 800
  direction: HEEN
  final_destination: Antwerpen
  due_at_schedule: '2020-05-28T17:42:00+00:00'
  due_at_realtime: '2020-05-28T17:42:00+00:00'
  due_in_min: 16
  is_realtime: false
  line_number_public: '2'
  line_desc: Diplomatenwijk
  line_transport_type: BUS
  line_number_colourFront: WI
  line_number_colourFrontHex: FFFFFF
  line_number_colourBack: GR
  line_number_colourBackHex: '229922'
  line_number_colourFrontBorder: ZW
  line_number_colourFrontBorderHex: '000000'
  line_number_colourBackBorder: GR
  line_number_colourBackBorderHex: '229922'
  stopname: 'Kerk'

friendly_name: Kerk
icon: mdi:bus
device_class: timestamp

The attribute next_passages can have multiple passages. In the example above there are two passages, but we can have 3 or 4 or … passages

bcutter commented 3 years ago

I´m curious to see this too. Currently my attribute has only one line (I use it mainly for showing available updates and currently all sensors attributes unfortunately only have one available update...). Will test how entity-attributes-card behaves as soon as one attribute contains more elements (lines) and probably come back here...

bcutter commented 3 years ago

...aaaand I hit it too:

image

image

How to handle (show) that? Currently the card only shows an "object" text which is not useful at all... I want ALL of that attributes content to show up instead.

Any suggestions / workarounds?

ChristophCaina commented 1 year ago

OK, I am also running into this issue... The Attributes of one Sensore are an array...

engine:
  engine_type: iV
  power_in_kw: 132
  battery_capacity_kwh: 62

So, I can only select "engine" in the attributes card, which will show the [object Object] pattern: grafik

bcutter commented 1 year ago

Have a look at the flex-table-card. I replaced most of my entity-attributes-card already with it.

ghost commented 1 year ago

Have a look at the flex-table-card. I replaced most of my entity-attributes-card already with it.

The card looks awesome, but for the life of me, I do not understand the docs.

I am trying to use it with an array. Any chance you can give me a pointer? The array in question is from Watchman (HACS) sensor.watchman_missing_entities which has an array under entities. Pic below Screenshot 2023-03-15 at 09 47 07

I've tries all sorts of variations on:

  - type: custom:flex-table-card
    title: Missing entities
    entities:
      include: sensor.watchman_missing_entities
    columns:
      - name: Entity
        data: entities.id
      - name: State
        data: entities.state

...with and without entities, with and without the utterly confusing receivedTS and sendTS from the docs.

Any pointer would be appreciated. I know I can raise a ticker there, but thought you might be able to help with a dumb question like mine.


edit: typically, after posting for help, one finds the right thread to answer it! this thread (using weather.openweathermap) helped me crack it.

The answer, for me, is:

  - type: custom:flex-table-card
    title: Missing entities
    entities:
      include: sensor.watchman_missing_entities
    columns:
      - name: Entity
        data: entities
        modify: x.id
      - name: State
        data: entities
        modify: x.state
      - name: Occurances
        data: entities
        modify: x.occurrences