Closed fcassirer closed 3 years ago
Hey,
I didn't read through all the code nor try to do the maths on your behalf but it seems you have thought it through. 😊
If what you need is access the full state of the current timestamp (with all the attributes etc...) on top of just the state value for each history entry, I can make this happen. So you'd get x
as the state or attribute (but you can ignore it) and something like stateObj
with the whole content of the entity for the history entry currently being transformed
.
Would that work for you?
Yes, absolutely, that would provide some options for how to present the data. More broadly, maybe a general mechanism similar to the config-template-card might be a way to add more consistent scripting across the entire card, i.e, not reinventing what args get passed into template, data_generator, and no doubt future yet to be named features ;-) In my example, there is a function called tthold() that is global to the card from config-template-card, would it be useful to allow the transform/data_generator access to that context? Just thinking out loud ...
Thanks!
One thing at a time but thanks for the enthusiasm 😊
I'll add support for retrieving the full object in transform
asap!
:tada: This issue has been resolved in version 1.7.0-dev.2 :tada:
The release is available on GitHub release
Your semantic-release bot :package::rocket:
Thank you! This works well. Here is a graph that can now plot the % usage for each day:
All I had to do was change the data_timestamp reference from the current xfinity_usage object to the entity as it existed the day it was recorded:
transform: >-
...
console.log(entity.attributes.data_timestamp); const today = new
Date(entity.attributes.data_timestamp * 1000).getDate();
The red and yellow lines represent the 70% and 90% usage levels for that day of the cycle. Now that we have this field I think much more interesting graphs can be created.
Thanks again for the quick turnaround! -Fred
:tada: This issue has been resolved in version 1.7.0 :tada:
The release is available on GitHub release
Your semantic-release bot :package::rocket:
Good stuff @RomRider. Thanks for putting this together.
I have a use case where I am trying to chart daily usage of my xfinity internet service. I am trying to create a bar chart of daily usage for a given 'month so far' and an indication if I am on track to stay under my bandwidth cap (1229 GB/mo). I have sensors that have a daily history of usage as well as an array of 6 prior months total usage.
So, for any given day/datapoint, I need to:
The result should be a set of colorized bars that would show each day individually based on the day into the period. Note that day 1 could be over but day 2 could be under so the bars would be red then green if day 1 was a busy day and day 2 wasn't.
I have the config-template-card which allows me to use scripting over the entire apexcharts-card, however, this is only good for the current (today) instantiation of the entity.
I am looking at the transform option to provide this info, however, there is no access to the actual history item, instead, we get the historical 'x' value which is the state of the item and full access to the hass.states['sensor.xfinity_usage'] object, but this is again the current value, not the actual item that is being pulled from the history.
I think if there were an option to directly access the object structure item being transformed it would allow this capability.
So this line and this one
I think would just need to pass in the current working item to make it available as a named entity as 'x' or 'hass'.
Here is what a sample graph would look like, ideally the green bars would show based on that data points current usage not the usage as of the day it is being displayed. The following yaml was attempting to draw a line graph overlay that would show the 70% and 90% threshold lines, but it became clear that data isn't available. Note, this example is setting color based on the current state, not previous state.
using:
As a reference, here what the xfinity_usage sensor looks like, there is essentially some data in the outer block like data_timestamp, usage, and total and then there are 6 months of past usage summaries with usageMonths[6] being this month so far and also contains the start/end date of the current period.
Thanks in advance -Fred