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

Enable attributes in an entity as a data source #501

Closed
wants to merge 7 commits into from

Conversation

mork2020
Copy link

Please ignore all other files then main.js
The changes in main.js allows attributes to be configured as a data source for the mini graph card.

The access to an entity value is encapulated in a new function getEntityValue. It checks wether an attribute is configured and returns the data from the attribute or from the state of the entity. Therefore all .state accesses are exchanged with the function call.

The getCache and setCache functions are adapted to save extended keys for attributes if necessary.

The fetchRecent function also needs a change, because the REST API must return all changes of the entity to access all attribute changes.

The updateEntity function is changed to filter the attributes of an entity and to access the value of an entity via getEntityValue function.

Well, using attributes from an entity could be improved using only one fetchRecent per entity, actually an entity is fetched via the REST API multiple times, for each configured attribute.
Perhaps the caching can also be optimized, because all attributes are stored in the cache history, although not every attributes changes in each returned fetch history.

@thekoma
Copy link

thekoma commented Nov 30, 2020

Nice!

Check added, if an attribute value changed compared to its predecessor.
If the value hasnt changed, ignore the value.
Split UpdateData in two parts, so a fetch of new data via the Rest API can be done once for a entity.
@saniho saniho mentioned this pull request Dec 11, 2020
@RomRider
Copy link
Collaborator

RomRider commented Jan 18, 2021

Thanks for the PR @mork2020.

It seems this can be achieved using standard HA features by creating a template sensor based on an attribute of an entity. Why introduce this complexity into mini-graph-card?

@kalkih
Copy link
Owner

kalkih commented Jan 20, 2021

Indeed, that has been my though as well, I've always pointed people towards template sensors when it comes to this particular feature request.
I understand it would be a nice addition, less hassle setting it up, but it adds quite some additional logic and complexity to the card.
Not sure if I feel like it's worth it when it already can be achieved in HA, will have to think about it.

@kalkih kalkih added the feature request New feature or request label Jan 20, 2021
@mork2020
Copy link
Author

mork2020 commented Jan 23, 2021

My climate sensors are connected to a Homee Gateway and i access those sensors from HA with a Node Red Script.
This scripts handles with a lot of values per sensor and creates for every Homee sensor a HA sensor,
where the values are stored in attributes. (Actually i can't guess of another implementation,
that keeps the Node Red part as simple as it can be.).

So, those climate sensors have a lot of attributes, e.g.
batterylevel, batterylowalarm, currentvalveposition, displayorientation, feedtemperature, firmwarerevision,
heatingmode, linkquality, malfunctionalarm, manualoperation, openwindowdetectionsensibility, softwarerevision,
targettemperature, temperature, temperatureoffset, wakeupinterval
.
Not every attribute is relevant to be used with the graph card, i use at least those attributes:
batterylevel, currentvalveposition, feedtemperature, targettemperature, temperature.

As of today i have 10 TRVs so i have to setup and maintain 50 template sensors. Those template sensors, please correct me if I am wrong, are additionally stored in the HA recorder/database. I dont know if that has a performance impact or not. (Any thoughts?)

While testing and configuring my mini-grahp-card (with attributes), i noticed, that while adding an existing attribute to the card, you see the already recorded history. Configuring that attribute via a template sensor means that there is "no history",
you have to wait, until there is enough data recorded. For me thats seems only to be relevant while fiddling around via the "correct" configuration of the card, but i want to mention it.

@thetic
Copy link

thetic commented Jan 27, 2021

I'd really like to see this functionality implemented. I agree that it can be accomplished without direct support in the card, but it is a repetitive, error prone, and inefficient strategy. Thanks for the awesome card.

@RomRider
Copy link
Collaborator

RomRider commented Jan 27, 2021

I've looked quickly at the content of this PR. I don't think the complexity introduced by this PR is required to enable this feature.
I'll have a go at it in the next days.

@kingy444
Copy link

Definitely like the look of this feature addition, hopefully it can get through - was not looking forward to templating a bunch of attributes.
Honestly cant believe this isn't standard in HA already. Why cant we access attributes directly.

Update to mini-graph-card-0.11.0-dev.2
@RomRider
Copy link
Collaborator

RomRider commented Feb 14, 2021

This feature is available in apexcharts-card.
I'll add this here too so you have a choice.

RomRider added a commit that referenced this pull request Feb 14, 2021
* feat(attribute): Retrieve an attribute instead of the state

* Fix lint

Fixes #411, Fixes #245, Fixes #501
github-actions bot pushed a commit that referenced this pull request Feb 14, 2021
# [0.11.0-dev.3](v0.11.0-dev.2...v0.11.0-dev.3) (2021-02-14)

### Features

* **attribute:** Retrieve an attribute instead of the state ([#564](#564)) ([3caafdb](3caafdb)), closes [#411](#411) [#245](#245) [#501](#501)
@RomRider
Copy link
Collaborator

I'm closing this, it has been released as beta through PR #564.

@RomRider RomRider closed this Feb 14, 2021
@github-actions
Copy link

🎉 This issue has been resolved in version 0.11.0-dev.3 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

jlsjonas pushed a commit that referenced this pull request Jan 22, 2022
* feat(attribute): Retrieve an attribute instead of the state

* Fix lint

Fixes #411, Fixes #245, Fixes #501
jlsjonas pushed a commit that referenced this pull request Jan 22, 2022
# [0.11.0-dev.3](v0.11.0-dev.2...v0.11.0-dev.3) (2021-02-14)

### Features

* **attribute:** Retrieve an attribute instead of the state ([#564](#564)) ([3caafdb](3caafdb)), closes [#411](#411) [#245](#245) [#501](#501)
github-actions bot pushed a commit that referenced this pull request Jan 22, 2022
# [0.11.0](v0.10.0...v0.11.0) (2022-01-22)

### Bug Fixes

* **config:** Remove entity config error [#592](#592) ([#593](#593)) ([53d923a](53d923a))
* display a warning if entity is not available ([#545](#545)) ([a334b84](a334b84)), closes [#487](#487)
* Fix undefined variable introduced by [#545](#545) ([9e923f5](9e923f5))
* Support for `fire-dom-event` ([c29f55f](c29f55f)), closes [#563](#563)
* **log:** color_thresholds render incorectly with logaritmic on ([#542](#542)) ([b704885](b704885)), closes [#531](#531)
* icon will properly follow entity's device_class [[#484](#484)] ([2f9e0a7](2f9e0a7))
* Time would sometime display 24:xx instead of 00:xx [[#536](#536)] ([7c7d921](7c7d921))

### Features

* Interpolate color threshold stops ([#596](#596)) ([3826c0d](3826c0d))
* **attribute:** Retrieve an attribute instead of the state ([#564](#564)) ([708bfde](708bfde)), closes [#411](#411) [#245](#245) [#501](#501)
* **graph:** Add median aggregate function ([#521](#521)) ([57219bd](57219bd))
* Format numbers according to selected language [[#495](#495) [#509](#509)] ([5785bd8](5785bd8))
@github-actions
Copy link

🎉 This issue has been resolved in version 0.11.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

github-actions bot pushed a commit to Malow/mini-graph-card that referenced this pull request Nov 18, 2023
# 1.0.0 (2023-11-18)

### Bug Fixes

* **config:** Remove entity config error [kalkih#592](https://github.com/malow/mini-graph-card/issues/592) ([kalkih#593](https://github.com/malow/mini-graph-card/issues/593)) ([53d923a](53d923a))
* **stalebot:** issues should also use exemptLabels ([4d74c1f](4d74c1f))
* display a warning if entity is not available ([kalkih#545](https://github.com/malow/mini-graph-card/issues/545)) ([a334b84](a334b84)), closes [kalkih#487](https://github.com/malow/mini-graph-card/issues/487)
* Fix undefined variable introduced by [kalkih#545](https://github.com/malow/mini-graph-card/issues/545) ([9e923f5](9e923f5))
* Support for `fire-dom-event` ([c29f55f](c29f55f)), closes [kalkih#563](https://github.com/malow/mini-graph-card/issues/563)
* **log:** color_thresholds render incorectly with logaritmic on ([kalkih#542](https://github.com/malow/mini-graph-card/issues/542)) ([b704885](b704885)), closes [kalkih#531](https://github.com/malow/mini-graph-card/issues/531)
* icon will properly follow entity's device_class [[kalkih#484](https://github.com/malow/mini-graph-card/issues/484)] ([2f9e0a7](2f9e0a7))
* Time would sometime display 24:xx instead of 00:xx [[kalkih#536](https://github.com/malow/mini-graph-card/issues/536)] ([7c7d921](7c7d921))

### Features

* Interpolate color threshold stops ([kalkih#596](https://github.com/malow/mini-graph-card/issues/596)) ([3826c0d](3826c0d))
* **attribute:** Retrieve an attribute instead of the state ([kalkih#564](https://github.com/malow/mini-graph-card/issues/564)) ([708bfde](708bfde)), closes [kalkih#411](https://github.com/malow/mini-graph-card/issues/411) [kalkih#245](https://github.com/malow/mini-graph-card/issues/245) [kalkih#501](https://github.com/malow/mini-graph-card/issues/501)
* **graph:** Add median aggregate function ([kalkih#521](https://github.com/malow/mini-graph-card/issues/521)) ([57219bd](57219bd))
* Format numbers according to selected language [[kalkih#495](https://github.com/malow/mini-graph-card/issues/495) [kalkih#509](https://github.com/malow/mini-graph-card/issues/509)] ([5785bd8](5785bd8))
github-actions bot pushed a commit to Malow/mini-graph-card that referenced this pull request Nov 18, 2023
# 1.0.0 (2023-11-18)

### Bug Fixes

* **config:** Remove entity config error [kalkih#592](https://github.com/malow/mini-graph-card/issues/592) ([kalkih#593](https://github.com/malow/mini-graph-card/issues/593)) ([53d923a](53d923a))
* **stalebot:** issues should also use exemptLabels ([4d74c1f](4d74c1f))
* display a warning if entity is not available ([kalkih#545](https://github.com/malow/mini-graph-card/issues/545)) ([a334b84](a334b84)), closes [kalkih#487](https://github.com/malow/mini-graph-card/issues/487)
* Fix undefined variable introduced by [kalkih#545](https://github.com/malow/mini-graph-card/issues/545) ([9e923f5](9e923f5))
* Support for `fire-dom-event` ([c29f55f](c29f55f)), closes [kalkih#563](https://github.com/malow/mini-graph-card/issues/563)
* **log:** color_thresholds render incorectly with logaritmic on ([kalkih#542](https://github.com/malow/mini-graph-card/issues/542)) ([b704885](b704885)), closes [kalkih#531](https://github.com/malow/mini-graph-card/issues/531)
* icon will properly follow entity's device_class [[kalkih#484](https://github.com/malow/mini-graph-card/issues/484)] ([2f9e0a7](2f9e0a7))
* Time would sometime display 24:xx instead of 00:xx [[kalkih#536](https://github.com/malow/mini-graph-card/issues/536)] ([7c7d921](7c7d921))

### Features

* Interpolate color threshold stops ([kalkih#596](https://github.com/malow/mini-graph-card/issues/596)) ([3826c0d](3826c0d))
* **attribute:** Retrieve an attribute instead of the state ([kalkih#564](https://github.com/malow/mini-graph-card/issues/564)) ([708bfde](708bfde)), closes [kalkih#411](https://github.com/malow/mini-graph-card/issues/411) [kalkih#245](https://github.com/malow/mini-graph-card/issues/245) [kalkih#501](https://github.com/malow/mini-graph-card/issues/501)
* **graph:** Add median aggregate function ([kalkih#521](https://github.com/malow/mini-graph-card/issues/521)) ([57219bd](57219bd))
* Format numbers according to selected language [[kalkih#495](https://github.com/malow/mini-graph-card/issues/495) [kalkih#509](https://github.com/malow/mini-graph-card/issues/509)] ([5785bd8](5785bd8))
github-actions bot pushed a commit to Malow/mini-graph-card that referenced this pull request Nov 18, 2023
# 1.0.0 (2023-11-18)

### Bug Fixes

* **config:** Remove entity config error [kalkih#592](https://github.com/malow/mini-graph-card/issues/592) ([kalkih#593](https://github.com/malow/mini-graph-card/issues/593)) ([53d923a](53d923a))
* **stalebot:** issues should also use exemptLabels ([4d74c1f](4d74c1f))
* display a warning if entity is not available ([kalkih#545](https://github.com/malow/mini-graph-card/issues/545)) ([a334b84](a334b84)), closes [kalkih#487](https://github.com/malow/mini-graph-card/issues/487)
* Fix undefined variable introduced by [kalkih#545](https://github.com/malow/mini-graph-card/issues/545) ([9e923f5](9e923f5))
* Support for `fire-dom-event` ([c29f55f](c29f55f)), closes [kalkih#563](https://github.com/malow/mini-graph-card/issues/563)
* **log:** color_thresholds render incorectly with logaritmic on ([kalkih#542](https://github.com/malow/mini-graph-card/issues/542)) ([b704885](b704885)), closes [kalkih#531](https://github.com/malow/mini-graph-card/issues/531)
* icon will properly follow entity's device_class [[kalkih#484](https://github.com/malow/mini-graph-card/issues/484)] ([2f9e0a7](2f9e0a7))
* Time would sometime display 24:xx instead of 00:xx [[kalkih#536](https://github.com/malow/mini-graph-card/issues/536)] ([7c7d921](7c7d921))

### Features

* Interpolate color threshold stops ([kalkih#596](https://github.com/malow/mini-graph-card/issues/596)) ([3826c0d](3826c0d))
* **attribute:** Retrieve an attribute instead of the state ([kalkih#564](https://github.com/malow/mini-graph-card/issues/564)) ([708bfde](708bfde)), closes [kalkih#411](https://github.com/malow/mini-graph-card/issues/411) [kalkih#245](https://github.com/malow/mini-graph-card/issues/245) [kalkih#501](https://github.com/malow/mini-graph-card/issues/501)
* **graph:** Add median aggregate function ([kalkih#521](https://github.com/malow/mini-graph-card/issues/521)) ([57219bd](57219bd))
* Format numbers according to selected language [[kalkih#495](https://github.com/malow/mini-graph-card/issues/495) [kalkih#509](https://github.com/malow/mini-graph-card/issues/509)] ([5785bd8](5785bd8))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants