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.
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.
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.
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.
{'data_timestamp': 1612890369,
'friendly_name': 'Xfinity Usage',
'raw': {'courtesyAllowed': 1,
'courtesyRemaining': 1,
'courtesyUsed': 0,
'displayUsage': True,
'inPaidOverage': False,
'usageMonths': [{'additionalBlocksUsed': 0.0,
'additionalCostPerBlock': 10.0,
'additionalIncluded': 0.0,
'additionalPercentUsed': 0.0,
'additionalRemaining': 0.0,
'additionalUnitsPerBlock': 50.0,
'additionalUsed': 0.0,
'allowableUsage': 1229.0,
'billableOverage': 0.0,
'currentCreditAmount': 0,
'devices': [{'id': 'B0:39:56:99:E4:E1',
'usage': 931.0}],
'displayUsage': True,
'endDate': '08/31/2020',
'homeUsage': 931.0,
'maxCreditAmount': 0,
'overageCharges': 0.0,
'overageUsed': 0.0,
'policy': 'limited',
'policyName': '1.2 Terabyte Data Plan',
'startDate': '08/01/2020',
'totalUsage': 931.0,
'unitOfMeasure': 'GB',
'wifiUsage': 0.0},
{'additionalBlocksUsed': 0.0,
'additionalCostPerBlock': 10.0,
'additionalIncluded': 0.0,
'additionalPercentUsed': 0.0,
'additionalRemaining': 0.0,
'additionalUnitsPerBlock': 50.0,
'additionalUsed': 0.0,
'allowableUsage': 1229.0,
'billableOverage': 0.0,
'currentCreditAmount': 0,
'devices': [{'id': 'B0:39:56:99:E4:E1',
'usage': 987.0}],
'displayUsage': True,
'endDate': '09/30/2020',
'homeUsage': 987.0,
'maxCreditAmount': 0,
'overageCharges': 0.0,
'overageUsed': 0.0,
'policy': 'limited',
'policyName': '1.2 Terabyte Data Plan',
'startDate': '09/01/2020',
'totalUsage': 987.0,
'unitOfMeasure': 'GB',
'wifiUsage': 0.0},
{'additionalBlocksUsed': 0.0,
'additionalCostPerBlock': 10.0,
'additionalIncluded': 0.0,
'additionalPercentUsed': 0.0,
'additionalRemaining': 0.0,
'additionalUnitsPerBlock': 50.0,
'additionalUsed': 0.0,
'allowableUsage': 1229.0,
'billableOverage': 0.0,
'currentCreditAmount': 0,
'devices': [{'id': 'B0:39:56:99:E4:E1',
'usage': 730.0}],
'displayUsage': True,
'endDate': '10/31/2020',
'homeUsage': 730.0,
'maxCreditAmount': 0,
'overageCharges': 0.0,
'overageUsed': 0.0,
'policy': 'limited',
'policyName': '1.2 Terabyte Data Plan',
'startDate': '10/01/2020',
'totalUsage': 730.0,
'unitOfMeasure': 'GB',
'wifiUsage': 0.0},
{'additionalBlocksUsed': 0.0,
'additionalCostPerBlock': 10.0,
'additionalIncluded': 0.0,
'additionalPercentUsed': 0.0,
'additionalRemaining': 0.0,
'additionalUnitsPerBlock': 50.0,
'additionalUsed': 0.0,
'allowableUsage': 1229.0,
'billableOverage': 0.0,
'currentCreditAmount': 0,
'devices': [{'id': 'B0:39:56:99:E4:E1',
'usage': 850.0}],
'displayUsage': True,
'endDate': '11/30/2020',
'homeUsage': 850.0,
'maxCreditAmount': 0,
'overageCharges': 0.0,
'overageUsed': 0.0,
'policy': 'limited',
'policyName': '1.2 Terabyte Data Plan',
'startDate': '11/01/2020',
'totalUsage': 850.0,
'unitOfMeasure': 'GB',
'wifiUsage': 0.0},
{'additionalBlocksUsed': 0.0,
'additionalCostPerBlock': 10.0,
'additionalIncluded': 0.0,
'additionalPercentUsed': 0.0,
'additionalRemaining': 0.0,
'additionalUnitsPerBlock': 50.0,
'additionalUsed': 0.0,
'allowableUsage': 1229.0,
'billableOverage': 0.0,
'currentCreditAmount': 0,
'devices': [{'id': 'B0:39:56:99:E4:E1',
'usage': 882.0}],
'displayUsage': True,
'endDate': '12/31/2020',
'homeUsage': 882.0,
'maxCreditAmount': 0,
'overageCharges': 0.0,
'overageUsed': 0.0,
'policy': 'limited',
'policyName': '1.2 Terabyte Data Plan',
'startDate': '12/01/2020',
'totalUsage': 882.0,
'unitOfMeasure': 'GB',
'wifiUsage': 0.0},
{'additionalBlocksUsed': 0.0,
'additionalCostPerBlock': 10.0,
'additionalIncluded': 0.0,
'additionalPercentUsed': 0.0,
'additionalRemaining': 0.0,
'additionalUnitsPerBlock': 50.0,
'additionalUsed': 0.0,
'allowableUsage': 1229.0,
'billableOverage': 0.0,
'currentCreditAmount': 0,
'devices': [{'id': 'B0:39:56:99:E4:E1',
'usage': 1099.0}],
'displayUsage': True,
'endDate': '01/31/2021',
'homeUsage': 1099.0,
'maxCreditAmount': 0,
'overageCharges': 0.0,
'overageUsed': 0.0,
'policy': 'limited',
'policyName': '1.2 Terabyte Data Plan',
'startDate': '01/01/2021',
'totalUsage': 1099.0,
'unitOfMeasure': 'GB',
'wifiUsage': 0.0},
{'additionalBlocksUsed': 0.0,
'additionalCostPerBlock': 10.0,
'additionalIncluded': 0.0,
'additionalPercentUsed': 0.0,
'additionalRemaining': 0.0,
'additionalUnitsPerBlock': 50.0,
'additionalUsed': 0.0,
'allowableUsage': 1229.0,
'billableOverage': 0.0,
'currentCreditAmount': 0,
'devices': [{'id': 'B0:39:56:99:E4:E1',
'usage': 205.0}],
'displayUsage': True,
'endDate': '02/28/2021',
'homeUsage': 205.0,
'maxCreditAmount': 0,
'overageCharges': 0.0,
'overageUsed': 0.0,
'policy': 'limited',
'policyName': '1.2 Terabyte Data Plan',
'startDate': '02/01/2021',
'totalUsage': 205.0,
'unitOfMeasure': 'GB',
'wifiUsage': 0.0}]},
'total': 1229.0,
'unit_of_measurement': 'GB',
'units': 'GB',
'used': 205.0
}
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