Created
May 14, 2021 16:27
-
-
Save adamrb/03feba1c645fd81ce74edcf38db7c045 to your computer and use it in GitHub Desktop.
Home Assistant T-Mobile Internet Graphana
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sensor: | |
- platform: rest | |
name: tmobile | |
resource: "http://192.168.12.1/fastmile_radio_status_web_app.cgi" | |
json_attributes: | |
- cell_5G_stats_cfg | |
- cell_LTE_stats_cfg | |
scan_interval: 30 | |
value_template: "OK" | |
- platform: template | |
sensors: | |
fiveg_rsrp: | |
value_template: '{{ states.sensor.tmobile.attributes["cell_5G_stats_cfg"][0]["stat"]["RSRPCurrent"] if states.sensor.tmobile.attributes["cell_5G_stats_cfg"][0]["stat"]["RSRPCurrent"] != -32768 else "" }}' | |
device_class: signal_strength | |
unit_of_measurement: "dBm" | |
friendly_name: "RSRP" | |
fiveg_snr: | |
value_template: '{{ states.sensor.tmobile.attributes["cell_5G_stats_cfg"][0]["stat"]["SNRCurrent"] if states.sensor.tmobile.attributes["cell_5G_stats_cfg"][0]["stat"]["SNRCurrent"] != -32768 else "" }}' | |
device_class: signal_strength | |
unit_of_measurement: "dB" | |
friendly_name: "SNR" | |
fiveg_rsrq: | |
value_template: '{{ states.sensor.tmobile.attributes["cell_5G_stats_cfg"][0]["stat"]["RSRQCurrent"] if states.sensor.tmobile.attributes["cell_5G_stats_cfg"][0]["stat"]["RSRQCurrent"] != -32768 else "" }}' | |
device_class: signal_strength | |
unit_of_measurement: "dB" | |
friendly_name: "RSRQ" | |
fiveg_band: | |
value_template: '{{ states.sensor.tmobile.attributes["cell_5G_stats_cfg"][0]["stat"]["Band"] if states.sensor.tmobile.attributes["cell_5G_stats_cfg"][0]["stat"]["Band"] != "" else "Not Connected" }}' | |
friendly_name: "Band" | |
lte_rsrp: | |
value_template: '{{ states.sensor.tmobile.attributes["cell_LTE_stats_cfg"][0]["stat"]["RSRPCurrent"] if states.sensor.tmobile.attributes["cell_LTE_stats_cfg"][0]["stat"]["RSRPCurrent"] != -32768 else ""}}' | |
device_class: signal_strength | |
unit_of_measurement: "dBm" | |
friendly_name: "RSRP" | |
lte_snr: | |
value_template: '{{ states.sensor.tmobile.attributes["cell_LTE_stats_cfg"][0]["stat"]["SNRCurrent"] if states.sensor.tmobile.attributes["cell_LTE_stats_cfg"][0]["stat"]["SNRCurrent"] != -32768 else "" }}' | |
device_class: signal_strength | |
unit_of_measurement: "dB" | |
friendly_name: "SNR" | |
lte_rsrq: | |
value_template: '{{ states.sensor.tmobile.attributes["cell_LTE_stats_cfg"][0]["stat"]["RSRQCurrent"] if states.sensor.tmobile.attributes["cell_LTE_stats_cfg"][0]["stat"]["RSRQCurrent"] != -32768 else "" }}' | |
device_class: signal_strength | |
unit_of_measurement: "dB" | |
friendly_name: "RSRQ" | |
lte_band: | |
value_template: '{{ states.sensor.tmobile.attributes["cell_LTE_stats_cfg"][0]["stat"]["Band"] if states.sensor.tmobile.attributes["cell_LTE_stats_cfg"][0]["stat"]["Band"] != "" else "Not Connected" }}' | |
friendly_name: "Band" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"annotations": { | |
"list": [ | |
{ | |
"builtIn": 1, | |
"datasource": "-- Grafana --", | |
"enable": true, | |
"hide": true, | |
"iconColor": "rgba(0, 211, 255, 1)", | |
"name": "Annotations & Alerts", | |
"type": "dashboard" | |
} | |
] | |
}, | |
"editable": true, | |
"gnetId": null, | |
"graphTooltip": 0, | |
"id": 2, | |
"links": [], | |
"panels": [ | |
{ | |
"datasource": null, | |
"fieldConfig": { | |
"defaults": { | |
"color": { | |
"mode": "palette-classic" | |
}, | |
"custom": { | |
"axisLabel": "", | |
"axisPlacement": "auto", | |
"barAlignment": 0, | |
"drawStyle": "line", | |
"fillOpacity": 10, | |
"gradientMode": "opacity", | |
"hideFrom": { | |
"graph": false, | |
"legend": false, | |
"tooltip": false | |
}, | |
"lineInterpolation": "linear", | |
"lineWidth": 1, | |
"pointSize": 5, | |
"scaleDistribution": { | |
"type": "linear" | |
}, | |
"showPoints": "never", | |
"spanNulls": true | |
}, | |
"mappings": [], | |
"thresholds": { | |
"mode": "absolute", | |
"steps": [ | |
{ | |
"color": "green", | |
"value": null | |
}, | |
{ | |
"color": "red", | |
"value": 80 | |
} | |
] | |
}, | |
"unit": "short" | |
}, | |
"overrides": [] | |
}, | |
"gridPos": { | |
"h": 8, | |
"w": 12, | |
"x": 0, | |
"y": 0 | |
}, | |
"id": 9, | |
"options": { | |
"graph": {}, | |
"legend": { | |
"calcs": [], | |
"displayMode": "list", | |
"placement": "bottom" | |
}, | |
"tooltipOptions": { | |
"mode": "single" | |
} | |
}, | |
"pluginVersion": "7.5.3", | |
"targets": [ | |
{ | |
"groupBy": [ | |
{ | |
"params": [ | |
"entity_id" | |
], | |
"type": "tag" | |
} | |
], | |
"measurement": "dBm", | |
"orderByTime": "ASC", | |
"policy": "autogen", | |
"refId": "A", | |
"resultFormat": "time_series", | |
"select": [ | |
[ | |
{ | |
"params": [ | |
"value" | |
], | |
"type": "field" | |
} | |
] | |
], | |
"tags": [ | |
{ | |
"key": "entity_id", | |
"operator": "=", | |
"value": "fiveg_rsrp" | |
}, | |
{ | |
"condition": "OR", | |
"key": "entity_id", | |
"operator": "=", | |
"value": "lte_rsrp" | |
} | |
] | |
} | |
], | |
"title": "Cell Signal", | |
"transformations": [], | |
"type": "timeseries" | |
}, | |
{ | |
"datasource": null, | |
"description": "", | |
"fieldConfig": { | |
"defaults": { | |
"color": { | |
"mode": "thresholds" | |
}, | |
"mappings": [], | |
"thresholds": { | |
"mode": "absolute", | |
"steps": [ | |
{ | |
"color": "red", | |
"value": null | |
}, | |
{ | |
"color": "yellow", | |
"value": 20 | |
}, | |
{ | |
"color": "orange", | |
"value": 60 | |
}, | |
{ | |
"color": "blue", | |
"value": 80 | |
}, | |
{ | |
"color": "purple", | |
"value": 100 | |
}, | |
{ | |
"color": "green", | |
"value": 150 | |
} | |
] | |
}, | |
"unit": "Mbits" | |
}, | |
"overrides": [] | |
}, | |
"gridPos": { | |
"h": 4, | |
"w": 3, | |
"x": 0, | |
"y": 8 | |
}, | |
"id": 6, | |
"options": { | |
"reduceOptions": { | |
"calcs": [ | |
"last" | |
], | |
"fields": "/^Mbit/s$/", | |
"values": false | |
}, | |
"showThresholdLabels": false, | |
"showThresholdMarkers": true, | |
"text": {} | |
}, | |
"pluginVersion": "7.5.5", | |
"targets": [ | |
{ | |
"groupBy": [], | |
"measurement": "Mbit/s", | |
"orderByTime": "ASC", | |
"policy": "default", | |
"refId": "A", | |
"resultFormat": "time_series", | |
"select": [ | |
[ | |
{ | |
"params": [ | |
"value" | |
], | |
"type": "field" | |
} | |
] | |
], | |
"tags": [ | |
{ | |
"key": "entity_id", | |
"operator": "=", | |
"value": "speedtest_download" | |
} | |
] | |
} | |
], | |
"title": "Current Download Speed", | |
"type": "gauge" | |
}, | |
{ | |
"datasource": null, | |
"description": "", | |
"fieldConfig": { | |
"defaults": { | |
"color": { | |
"mode": "thresholds" | |
}, | |
"mappings": [], | |
"thresholds": { | |
"mode": "absolute", | |
"steps": [ | |
{ | |
"color": "red", | |
"value": null | |
}, | |
{ | |
"color": "yellow", | |
"value": 5 | |
}, | |
{ | |
"color": "orange", | |
"value": 10 | |
}, | |
{ | |
"color": "blue", | |
"value": 15 | |
}, | |
{ | |
"color": "purple", | |
"value": 20 | |
}, | |
{ | |
"color": "green", | |
"value": 35 | |
} | |
] | |
}, | |
"unit": "Mbits" | |
}, | |
"overrides": [] | |
}, | |
"gridPos": { | |
"h": 4, | |
"w": 3, | |
"x": 9, | |
"y": 8 | |
}, | |
"id": 7, | |
"options": { | |
"reduceOptions": { | |
"calcs": [ | |
"last" | |
], | |
"fields": "/^Mbit/s$/", | |
"values": false | |
}, | |
"showThresholdLabels": false, | |
"showThresholdMarkers": true, | |
"text": {} | |
}, | |
"pluginVersion": "7.5.5", | |
"targets": [ | |
{ | |
"groupBy": [], | |
"measurement": "Mbit/s", | |
"orderByTime": "DESC", | |
"policy": "default", | |
"refId": "A", | |
"resultFormat": "time_series", | |
"select": [ | |
[ | |
{ | |
"params": [ | |
"value" | |
], | |
"type": "field" | |
} | |
] | |
], | |
"tags": [ | |
{ | |
"key": "entity_id", | |
"operator": "=", | |
"value": "speedtest_upload" | |
} | |
] | |
} | |
], | |
"title": "Current Upload Speed", | |
"type": "gauge" | |
}, | |
{ | |
"datasource": null, | |
"description": "", | |
"fieldConfig": { | |
"defaults": { | |
"color": { | |
"mode": "palette-classic" | |
}, | |
"custom": { | |
"axisLabel": "", | |
"axisPlacement": "auto", | |
"barAlignment": 0, | |
"drawStyle": "line", | |
"fillOpacity": 33, | |
"gradientMode": "none", | |
"hideFrom": { | |
"graph": false, | |
"legend": false, | |
"tooltip": false | |
}, | |
"lineInterpolation": "stepAfter", | |
"lineWidth": 2, | |
"pointSize": 5, | |
"scaleDistribution": { | |
"type": "linear" | |
}, | |
"showPoints": "never", | |
"spanNulls": true | |
}, | |
"mappings": [ | |
{ | |
"from": "", | |
"id": 1, | |
"text": "", | |
"to": "", | |
"type": 1, | |
"value": "" | |
} | |
], | |
"thresholds": { | |
"mode": "absolute", | |
"steps": [ | |
{ | |
"color": "green", | |
"value": null | |
}, | |
{ | |
"color": "red", | |
"value": 80 | |
} | |
] | |
}, | |
"unit": "Mbits" | |
}, | |
"overrides": [] | |
}, | |
"gridPos": { | |
"h": 9, | |
"w": 12, | |
"x": 0, | |
"y": 12 | |
}, | |
"id": 2, | |
"options": { | |
"graph": {}, | |
"legend": { | |
"calcs": [], | |
"displayMode": "list", | |
"placement": "bottom" | |
}, | |
"tooltipOptions": { | |
"mode": "multi" | |
} | |
}, | |
"pluginVersion": "7.4.3", | |
"targets": [ | |
{ | |
"alias": "", | |
"groupBy": [ | |
{ | |
"params": [ | |
"entity_id" | |
], | |
"type": "tag" | |
} | |
], | |
"hide": false, | |
"measurement": "Mbit/s", | |
"orderByTime": "ASC", | |
"policy": "default", | |
"refId": "Speed", | |
"resultFormat": "time_series", | |
"select": [ | |
[ | |
{ | |
"params": [ | |
"value" | |
], | |
"type": "field" | |
} | |
] | |
], | |
"tags": [ | |
{ | |
"key": "entity_id", | |
"operator": "=", | |
"value": "speedtest_upload" | |
}, | |
{ | |
"condition": "OR", | |
"key": "entity_id", | |
"operator": "=", | |
"value": "speedtest_download" | |
} | |
] | |
} | |
], | |
"timeFrom": null, | |
"timeShift": null, | |
"title": "SpeedTest", | |
"transformations": [ | |
{ | |
"id": "renameByRegex", | |
"options": { | |
"regex": ".*speedtest_(.*)}.*", | |
"renamePattern": "$1 speed" | |
} | |
} | |
], | |
"type": "timeseries" | |
}, | |
{ | |
"datasource": null, | |
"description": "", | |
"fieldConfig": { | |
"defaults": { | |
"color": { | |
"mode": "palette-classic" | |
}, | |
"custom": { | |
"axisLabel": "", | |
"axisPlacement": "auto", | |
"barAlignment": 0, | |
"drawStyle": "line", | |
"fillOpacity": 10, | |
"gradientMode": "none", | |
"hideFrom": { | |
"graph": false, | |
"legend": false, | |
"tooltip": false | |
}, | |
"lineInterpolation": "stepAfter", | |
"lineWidth": 1, | |
"pointSize": 5, | |
"scaleDistribution": { | |
"type": "linear" | |
}, | |
"showPoints": "never", | |
"spanNulls": true | |
}, | |
"mappings": [], | |
"thresholds": { | |
"mode": "absolute", | |
"steps": [ | |
{ | |
"color": "green", | |
"value": null | |
}, | |
{ | |
"color": "red", | |
"value": 80 | |
} | |
] | |
}, | |
"unit": "ms" | |
}, | |
"overrides": [] | |
}, | |
"gridPos": { | |
"h": 8, | |
"w": 12, | |
"x": 0, | |
"y": 21 | |
}, | |
"id": 4, | |
"options": { | |
"graph": {}, | |
"legend": { | |
"calcs": [], | |
"displayMode": "hidden", | |
"placement": "bottom" | |
}, | |
"tooltipOptions": { | |
"mode": "multi" | |
} | |
}, | |
"pluginVersion": "7.4.3", | |
"targets": [ | |
{ | |
"groupBy": [], | |
"hide": false, | |
"measurement": "ms", | |
"orderByTime": "ASC", | |
"policy": "default", | |
"refId": "A", | |
"resultFormat": "time_series", | |
"select": [ | |
[ | |
{ | |
"params": [ | |
"value" | |
], | |
"type": "field" | |
} | |
] | |
], | |
"tags": [ | |
{ | |
"key": "entity_id", | |
"operator": "=", | |
"value": "speedtest_ping" | |
} | |
] | |
} | |
], | |
"timeFrom": null, | |
"timeShift": null, | |
"title": "Ping", | |
"transformations": [], | |
"type": "timeseries" | |
} | |
], | |
"schemaVersion": 27, | |
"style": "dark", | |
"tags": [], | |
"templating": { | |
"list": [] | |
}, | |
"time": { | |
"from": "now-2d", | |
"to": "now" | |
}, | |
"timepicker": {}, | |
"timezone": "", | |
"title": "Network Performance", | |
"uid": "MP5aCswMk", | |
"version": 10 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@service | |
def run_binary_speedtest(): | |
import requests | |
import subprocess | |
import json | |
import sys | |
################################## | |
# Instructions: | |
# HASERVER - URL (http:port or https:port of your Home Assistant). Leave quotes as is. | |
# SPEEDTEST_SERVERID - the speedtest server ID of your desired server, | |
# or leave as is and speedtest will find one. Leave quotes as is. | |
# Note if the id is incorrect or no longer in-service, this will throw error: | |
# "json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)" | |
# SPEEDTEST_PATH - The full filename/path to the speedtest.bin file. Leave quotes as is. | |
# | |
# Use your existing speedtest integration from HA, but set | |
# manual: true | |
# and use an automation to run this. | |
# Alternatively, this code will autocreate the same sensors | |
# but these sensrs will not live after a reboot. | |
# | |
# This will update the following sensors: | |
# sensor.speedtest_download | |
# sensor.speedtest_ping | |
# sensor.speedtest_upload | |
# | |
################################## | |
# Configuration | |
SPEEDTEST_SERVERID = '' | |
SPEEDTEST_PATH = '/config/pyscript/speedtest' | |
# Run Speedtest | |
log.debug('Running Speedtest') | |
if SPEEDTEST_SERVERID == '': | |
speed_test_server_id='' | |
else: | |
speed_test_server_id = '--server-id=' + SPEEDTEST_SERVERID | |
process = subprocess.Popen([SPEEDTEST_PATH, '--accept-license', '--format=json','--precision=4',speed_test_server_id], | |
stdout=subprocess.PIPE, | |
stderr=subprocess.PIPE, | |
universal_newlines=True) | |
stdout, stderr = process.communicate() | |
log.debug('Stdout: %s', stdout) | |
log.debug('Stderr: %s', stderr) | |
# Speed Test Results - (from returned JSON string) | |
st_results = json.loads(stdout) | |
download_speed = round(st_results["download"]["bandwidth"]*8/1000000, 2) | |
upload_speed = round(st_results["upload"]["bandwidth"]*8/1000000, 2) | |
ping_latency = round(st_results["ping"]["latency"], 2) | |
isp = st_results["isp"] | |
server_name = st_results["server"]["name"] | |
url_result = st_results["result"]["url"] | |
log.info('Downstream BW: %s',download_speed) | |
log.info('Upstram BW: %s',upload_speed) | |
log.info('Ping Latency: %s', ping_latency) | |
log.info('ISP: %s', isp) | |
log.info('Server name: %s',server_name) | |
log.info('URL results: %s',url_result) | |
log.info('---------------------------------') | |
sensor.speedtest_download = download_speed | |
sensor.speedtest_upload = upload_speed | |
sensor.speedtest_ping = ping_latency |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment