How to use entity attribute in history graph

Hello,

I’m wondering if it’s possible to use entity’s attribute in history graph. For example I have sun.sun which has elevation. I would like to use it as input for my graph. Is it possible? If yes, could you please give me a hint how to do it? :slight_smile:

Thanks
Bartek

2 Likes

if you define a sensor (see below) to provide the attribute value, you should then be able to graph the value over time.

- platform: template
    sensors:
      sunrise:
      sun_elevation:
        value_template: '{% if states.sun.sun %}{{ ((states.sun.sun.attributes.elevation)) | float }}{% endif %}'
      sun_azimuth:
        value_template: '{% if states.sun.sun %}{{ ((states.sun.sun.attributes.azimuth)) | float }}{% endif %}'

Will not state_attr(‘sun.sun’, ‘elevation’)
do the same as the if but without it?

1 Like

possibly, lots of ways of skinning a cat. :grinning:

1 Like

Thanks for the answer. Small adaptations to your code were needed but works like a charm.
Thx!

is there a way to do this without actually creating another sensor? maybe this is a feature request, but i have sensors with tons of attributes that i need only for plotting and nothing else. Creating a “new” sensor for every single item just pollutes a lot. Entering the attribute in the lovelace card directly will be ideal

12 Likes

Agree! I’m in the same boat. If these are logged anyway as I can plot attributes in InfluxDB they should be available to display in graphs.

1 Like

I had also the requirement to visualize the attribute of an entity. So i forked the mini-graph-card an added the possibility to configure attributes from an enitity as a data source.
You can download the js file from here: https://github.com/mork2020/mini-graph-card/releases/tag/v0.0.1
https://github.com/mork2020/mini-graph-card/releases/tag/v0.0.2

I try to make a pull request for the original mini-graph-card - repro.

Actually this implementation makes a data fetch for every entity and attribute configured.
An optimization would be only one data fetch per entity and extract the data for the different attributes with a single fetch. Hence, you must be carefull while using this implementation.

2 Likes

I added a new release, where the fetch of new data from the server is only done once for every entity configured:

Hi all,
really interesting and useful.

Is it released also as HACS add-on or it must be manually installed, replacing the origing mini-graph-card?

thanks again

Stefano

Actually you must install this add on manually. I placed I pull request in Github, so hopefully the mini-graph-card maintainers incooperate the changes to the “main line”.

Add unit_of_measurement to show graph instead of color line

sun_elevation:
        value_template: '{% if states.sun.sun %}{{ ((states.sun.sun.attributes.elevation)) | float }}{% endif %}'
        unit_of_measurement: "°"
1 Like

Actually the feature to access attributes from the mini-graph-card is not implemented in the original repository. So I updated my repository with the changes from the original repository.

1 Like

HI @Perun thanks for your work !

EDIT : I found the “master” branch and it works well now.

It worked for quite some time and since the last update of HA it broke.

I uninstalled the frontend integration and reinstalled it (with beta versions checked) and I only get v0.0.4 on the list.
Since then I got this message : "Custom element doesn’t exist: mini-graph-card. "

Am I missing something ?

Thanks for this, helps me a lot in determining when I need to trigger my hallway lights and motion sensor based on the elevation of the sun, maybe compared with some lux values.

1 Like

I used this method before , but is needed restart HA , now i use appex-chart repo , install it with HACS.

My code of lovelace card that show external temperature is:

type: custom:apexcharts-card
graph_span: 5d
header:
  show: true
  title: External Temperature
series:
  - entity: weather.casa
    attribute: temperature
    type: line
    name: temperature

2 Likes

There’s also a custom integration on HACS to create sensors from attributes, which works like a charm for me.

Not sure which approach is better. :slight_smile:

2 Likes

This card is really awesome, it is the best card to plot series made for HA hands down