Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested Attributes? #19

Open
mikerenna opened this issue Jun 29, 2020 · 14 comments
Open

Nested Attributes? #19

mikerenna opened this issue Jun 29, 2020 · 14 comments
Labels
question Further information is requested

Comments

@mikerenna
Copy link

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

@pilotak
Copy link
Owner

pilotak commented Jun 30, 2020

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?

@mikerenna
Copy link
Author

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

@pilotak
Copy link
Owner

pilotak commented Jun 30, 2020

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?

@mikerenna
Copy link
Author

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.

@pilotak
Copy link
Owner

pilotak commented Jul 1, 2020

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 pilotak added the question Further information is requested label Jul 1, 2020
@mikerenna
Copy link
Author

mikerenna commented Jul 2, 2020 via email

@generalk25
Copy link

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

@pilotak
Copy link
Owner

pilotak commented Jun 23, 2021

@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

@ChristophCaina
Copy link

"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)

@pilotak
Copy link
Owner

pilotak commented Oct 14, 2022

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?

@loryanstrant
Copy link

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

@pilotak
Copy link
Owner

pilotak commented Apr 2, 2023

no, nobody responded

@loryanstrant
Copy link

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

@pilotak
Copy link
Owner

pilotak commented Apr 23, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants