homeassistant-attributes icon indicating copy to clipboard operation
homeassistant-attributes copied to clipboard

Nested Attributes?

Open mikerenna opened this issue 4 years ago • 14 comments

Is there a syntax that would support what appear to be nested attributes? Thanks in advance. -Mike

mikerenna avatar Jun 29 '20 21:06 mikerenna

What do you mean by nested attibutes? in HA each entity has subset off attibutes in only one level. As far as i know there are no nested. Could you please post an example?

pilotak avatar Jun 30 '20 05:06 pilotak

it was only an assumption. The display in Home Assistant States view had some indentation and there are duplicate attribute names (not shown in subset below) that led me to suspect that may be the case. Here is a subset of the data from a zwift integration entity (it also may be, since this is a third-party integration entity and not official, that they sort of slapped in an API result set without formatting it well) where i'm trying to get at the data that constitutes the latest_activity, specifically attributes like totalElevation. Those that had that nested feel here don't show resolve the values but those that don't seem like they'd be a sub collection work fine.

latest_activity: id_str: '4567456745675675647' id: 4567456745674567 profileId: 4654565 profile: id: 4654565 publicId: 456745674567456745674567 firstName: Michael lastName: Renna male: true imageSrc: 'x' imageSrcLarge: 'x' playerType: NORMAL countryAlpha3: usa countryCode: 840 useMetric: false riding: false privacy: approvalRequired: false displayWeight: false minor: false privateMessaging: false defaultFitnessDataPrivacy: false suppressFollowerNotification: false displayAge: true defaultActivityPrivacy: PUBLIC socialFacts: profileId: 4654565 followersCount: 0 followeesCount: 0 followeesInCommonWithLoggedInPlayer: 0 followerStatusOfLoggedInPlayer: SELF followeeStatusOfLoggedInPlayer: SELF isFavoriteOfLoggedInPlayer: false worldId: null enrolledZwiftAcademy: false playerTypeId: 1 playerSubTypeId: null currentActivityId: null worldId: 1 name: Zwift - Watopia description: null privateActivity: false sport: CYCLING startDate: '2020-06-29T11:47:51.723+0000' endDate: '2020-06-29T12:16:20.678+0000' lastSaveDate: '2020-06-29T12:16:20.678+0000' autoClosed: false duration: '28' distanceInMeters: 9834.3 fitFileBucket: s3-fit-prd-uswest2-zwift fitFileKey: prod/1282501/aa052e05-583198288996566224 totalElevation: 39.213 avgWatts: 108.059 rideOnGiven: false activityRideOnCount: 1 activityCommentCount: 0 snapshotList: null calories: 161.113

mikerenna avatar Jun 30 '20 17:06 mikerenna

i can't see indentions from your log, could you please do a screenshot? i can only think of JSON being nested - if this is the case then this custom component will not work.

Have you tried it already?

pilotak avatar Jun 30 '20 19:06 pilotak

zwiftattributes See if that shows. it's a segment in the STATES page that shows some indenting. It's definitely not JSON but perhaps its just poorly formatted input to HA where I can't access some of these by name using your custom component. Had hoped you might have some ideas, but i'm sort of skeptical there is a simple fix here.

mikerenna avatar Jun 30 '20 20:06 mikerenna

thanks for screenshot, this is first time i see indented attributes. You could perhaps ask the author of the component how to extract these atributes with template sensor (native component in HA) and we can proceed from there

pilotak avatar Jul 01 '20 07:07 pilotak

Thanks. Will do.

From: Pavel S [email protected] Sent: Wednesday, July 1, 2020 2:35 AM To: pilotak/homeassistant-attributes [email protected] Cc: mikerenna [email protected]; Author [email protected] Subject: Re: [pilotak/homeassistant-attributes] Nested Attributes? (#19)

thanks for screenshot, this is first time i see indented attributes. You could perhaps ask the author of the component how to extract these atributes with template sensor (native component in HA) and we can proceed from there

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fpilotak%2Fhomeassistant-attributes%2Fissues%2F19%23issuecomment-652247314&data=02%7C01%7C%7C3261564993ec4dca92c308d81d915202%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637291857258795675&sdata=qfrdN4d7SBE1YO3z3LAdTvAKE5ti6RKrGlQfVg6QtFk%3D&reserved=0, or unsubscribehttps://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAKWHHRW5DINWGVWNRPOVFHTRZLRLZANCNFSM4OLTQ5WQ&data=02%7C01%7C%7C3261564993ec4dca92c308d81d915202%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637291857258805669&sdata=7PXJpxRjP3fShkljKE34RVhVYaS0ZfHIb37eD07Qq9g%3D&reserved=0.

mikerenna avatar Jul 02 '20 17:07 mikerenna

Did we ever get anywhere with this? i'm facing the same problem. different app.

generalk25 avatar Jun 23 '21 12:06 generalk25

@generalk25 same apply to you

You could perhaps ask the author of the component how to extract these atributes with template sensor (native component in HA) and we can proceed from there

i had no response from anyone so far

pilotak avatar Jun 23 '21 13:06 pilotak

"nested" attributes happen in many integrations. If "ask the developer of the integration to change that" is the only answer, this integration is pretty useless.

To do this manually:

template:
  - sensor:
    - name: solaredge_inverters_inverter1_name
      unique_id: 'solaredge_inverters_inverter1_name'
      state: "{{ state_attr('sensor.solaredge_inverters', 'inverters')[0]['name'] }}"

  - sensor:
    - name: solaredge_inverters_inverter1_manufacturer
      unique_id: 'solaredge_inverters_inverter1_manufacturer'
      state: "{{ state_attr('sensor.solaredge_inverters', 'inverters')[0]['manufacturer'] }}"

  - sensor:
    - name: solaredge_inverters_inverter1_model
      unique_id: 'solaredge_inverters_inverter1_model'
      state: "{{ state_attr('sensor.solaredge_inverters', 'inverters')[0]['model'] }}"

  - sensor:
    - name: solaredge_inverters_inverter1_communicationMethod
      unique_id: 'solaredge_inverters_inverter1_communicationMethod'
      state: "{{ state_attr('sensor.solaredge_inverters', 'inverters')[0]['communicationMethod'] }}"

  - sensor:
    - name: solaredge_inverters_inverter1_dsp1Version
      unique_id: 'solaredge_inverters_inverter1_dsp1Version'
      state: "{{ state_attr('sensor.solaredge_inverters', 'inverters')[0]['dsp1Version'] }}"

  - sensor:
    - name: solaredge_inverters_inverter1_dsp2Version
      unique_id: 'solaredge_inverters_inverter1_dsp2Version'
      state: "{{ state_attr('sensor.solaredge_inverters', 'inverters')[0]['dsp2Version'] }}"

this will break out all entities provided by the solaredge_inverters sensor in an array for "Inverter 1"

inverters:
 - name: Inverter 1
   manufacturer: SolarEdge
   model: SE12.5K-RW0T0BNN4
   communicationMethod: ETHERNET
   dsp1Version: 1.13.1938
   dsp2Version: 2.19.1511
   cpuVersion: 4.15.119
   SN: 7E0BDC4A-AF
   connectedOptimizers: 39
friendly_name: solaredge (Inverters)

ChristophCaina avatar Oct 14 '22 13:10 ChristophCaina

thanks for providing an example. It should be possible to adjust this integration to add additional field ie.: nested: "[0]['model']" which will result in

sensor:  
  - platform: attributes
    friendly_name: "Batteries"
    attribute: battery_level
    nested: "[0]['model']"
    entities:
      - sensor.myslipo_1_0
      - sensor.myslipo_2_0
      - sensor.myslipo_3_0
      - sensor.myslipo_4_0

is this what you need?

pilotak avatar Oct 14 '22 13:10 pilotak

Did this nested functionality ever get added? I don't see an updated build with it.

loryanstrant avatar Apr 02 '23 01:04 loryanstrant

no, nobody responded

pilotak avatar Apr 02 '23 11:04 pilotak

That's a shame, I only just discovered it and would love it. :-(

loryanstrant avatar Apr 06 '23 23:04 loryanstrant

@loryanstrant i will look into it if you can test as i don't have such an entity

pilotak avatar Apr 23 '23 12:04 pilotak