kalkih / mini-graph-card

Minimalistic graph card for Home Assistant Lovelace UI
MIT License
3.06k stars 238 forks source link

Graph from values in yaml? #556

Closed fcassirer closed 2 years ago

fcassirer commented 3 years ago

I was wondering if there was any way to use an alternate data source for the history values for a mini-graph-card. The use case is that I have a json data blob for xfinity usage. The blob has a usage value which I bring in via an mqtt sensor declaration, but it also has attributes that contain an array of 5 or 6 of the past months total usage.

I am trying to determine how I could create a (bar) graph of the 6 past months values and the usage so far this month. I could imagine a graph declaration that looked like:

type: 'custom:mini-graph-card'
entities:
  - entity: sensor.xfinity_usage
custom_data:
  - value: {{ sensor.xfinity_monthly_usage.attributes.raw.usageData[0].totalUsage }}
    created: {{ as_timestamp(sensor.xfinity_monthly_usage.attributes.raw.usageData[0].endDate) }}
  - value: {{ sensor.xfinity_monthly_usage.attributes.raw.usageData[1].totalUsage }}
    created: {{ as_timestamp(sensor.xfinity_monthly_usage.attributes.raw.usageData[1].endDate) }}
  - value: {{ sensor.xfinity_monthly_usage.attributes.raw.usageData[2].totalUsage }}
    created: {{ as_timestamp(sensor.xfinity_monthly_usage.attributes.raw.usageData[2].endDate) }}
  - value: {{ sensor.xfinity_monthly_usage.attributes.raw.usageData[3].totalUsage }}
    created: {{ as_timestamp(sensor.xfinity_monthly_usage.attributes.raw.usageData[3].endDate) }}
  - value: {{ sensor.xfinity_monthly_usage.attributes.raw.usageData[4].totalUsage }}
    created: {{ as_timestamp(sensor.xfinity_monthly_usage.attributes.raw.usageData[4].endDate) }}

Obviously the value/created hash could be generated by jinja, but I hardcoded it here for illustration.

The result of this would be to graph the current value of the sensor 'xfinity_usage' which is the running total and then use the data values as previous bars based on the date provided. Likely the custom_data might need to be tied to a given entity so maybe it needs to indent custom_data under entity, but hopefully this gets the idea across.

Thoughts? Are there other ways to accomplish this?

Thanks in advance for any insight.

RomRider commented 3 years ago

You can do that using data_generator from the alternative apexcharts-card. https://github.com/RomRider/apexcharts-card

fcassirer commented 3 years ago

@RomRider thank you! That is exactly what I was looking for. I was able to cobble something together using the bar-card and a bunch of sensor templates, but this is a much better option.

Fred

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. If this is still an active issue, please let us know!