Skip to content

Instantly share code, notes, and snippets.

@ronaldheft
Last active August 11, 2023 00:56
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ronaldheft/cb6fa83ea3873545c411da03b42cd2d9 to your computer and use it in GitHub Desktop.
Save ronaldheft/cb6fa83ea3873545c411da03b42cd2d9 to your computer and use it in GitHub Desktop.
Xfinity data monitor for Home Assistant
sensors:
- platform: influxdb
host: !secret influxdb_host
username: !secret influxdb_user
password: !secret influxdb_pass
queries:
- name: xfinity_data_used
database: xfinity
field: used
group_function: last
where: "time > now() - 7d"
measurement: '"comcast_data_usage"'
unit_of_measurement: "GB"
- name: xfinity_data_total
database: xfinity
field: total
group_function: last
where: "time > now() - 7d"
measurement: '"comcast_data_usage"'
unit_of_measurement: "GB"
- platform: rest
name: "xfinity_data_used_today"
resource_template: !secret influxdb_query_xfinity_downloaded_data_today
unit_of_measurement: GB
value_template: >-
{{ value_json["results"][0]["series"][0]["values"][0][1] }}
- platform: template
sensors:
month_days_in_current:
friendly_name: Days in Current Month
icon_template: mdi:calendar
value_template: >-
{% if now().month in [1,3,5,7,8,10,12] %}
31
{% elif now().month in [4,6,9,11] %}
30
{% elif now().month == 2 and ((now().year-2000) % 4 > 0) %}
28
{% elif now().month == 2 and ((now().year-2000) % 4 == 0) %}
29
{% endif %}
month_current_day:
friendly_name: Curreny Day in Month
icon_template: mdi:calendar
value_template: >-
{{ now().day }}
month_percent:
friendly_name: Percentage Through Month
icon_template: mdi:calendar
value_template: >-
{{ ((states('sensor.month_current_day')|float / states('sensor.month_days_in_current')|float) * 100) | round(0) }}
type: custom:stack-in-card
cards:
- type: custom:mini-graph-card
icon: mdi:download-network
entities:
- entity: sensor.xfinity_data_used
name: Xfinity Data
show_graph: false
aggregate_func: last
- entity: sensor.xfinity_data_used_today
name: Xfinity Data
show_graph: true
show_state: true
aggregate_func: last
hours_to_show: 672
group_by: date
font_size_header: 14
font_size: 100
line_width: 3
group: false
lower_bound: 0
animate: true
smoothing: false
color_thresholds:
- value: 0
color: "rgba(42, 187, 155, 0.9)"
- value: 30
color: "var(--label-badge-yellow)"
- value: 40
color: "#b93829"
show:
points: false
labels: false
labels_secondary: false
legend: false
graph: bar
tap_action: none
style: |
.name > span { font-weight: 400 !important; text-transform: uppercase; }
- type: entities
show_header_toggle: false
entities:
- type: custom:bar-card
name: Xfinity
icon: mdi:download-network
entity: sensor.xfinity_data_used
unit_of_measurement: "GB"
entity_row: true
max: 1229
severity:
- from: 950
to: 1100
color: "var(--label-badge-yellow)"
- from: 1100
to: 1229
color: "#b93829"
positions:
name: off
value: off
indicator: off
height: 30px
style: |-
bar-card-background { margin-right: 13px !important; margin-top: 5px !important; }
bar-card-value { margin-right: 0 !important; }
tap_action: none
- type: custom:bar-card
name: Month Percent
icon: mdi:calendar-arrow-right
entity: sensor.month_percent
unit_of_measurement: "%"
entity_row: true
max: 100
positions:
name: off
value: off
indicator: off
height: 30px
style: |-
bar-card-background { margin-right: 13px !important; margin-top: 5px !important; }
bar-card-value { margin-right: 0 !important; }
tap_action: none
style: |
.card-header { padding-top: 4px; padding-bottom: 12px; }
.card-header .name { font-size: 16.8px; font-weight: 400; text-transform: uppercase; opacity: 0.65; }
- type: markdown
style: |
ha-markdown.no-header { padding-top: 0 !important; text-align: center; }
ha-markdown { color: var(--secondary-text-color); }
content: >-
{% set data_used = states('sensor.xfinity_data_used') | int %}
{% set data_total = states('sensor.xfinity_data_total') | int %}
{% set data_remaining = data_total - data_used %}
{% set month_days_in_current = states('sensor.month_days_in_current') | int %}
{% set month_current_day = states('sensor.month_current_day') | int %}
{% set days_remaining = month_days_in_current - month_current_day %}
{% if data_remaining >= 0 -%}
{{ data_remaining }} GB remaining to use over the next {{ days_remaining }} {% if days_remaining != 1 %}days{% else %}day{% endif %}
{%- else -%}
**{{ -data_remaining }} GB over with {{ days_remaining }} {% if days_remaining != 1 %}days{% else %}day{% endif %} remaining**
_Xfinity charges $10 per 50 GB of data_
{%- endif %}
@ronaldheft
Copy link
Author

2F85EC2F-4A62-44F0-88E5-20830B11C0EB_1_201_a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment