Last active
February 11, 2024 21:43
-
-
Save shmick/4862c9cb2beb814b7784723a6686c8d3 to your computer and use it in GitHub Desktop.
Send UXG Lite ppp0 stats to Home Assistant
This file contains 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
#!/bin/bash | |
# Using some hints from https://community.home-assistant.io/t/convert-webhook-into-multiple-temp-sensors/573335/2 | |
# Get Receive and Transmit bytes for ppp0 interface | |
if read data_received data_sent < <(awk '/ppp0:/{print $2, $10}' /proc/net/dev); then | |
# Validate that data_received and data_sent are numbers | |
if [[ ! "$data_received" =~ ^[0-9]+$ ]] || [[ ! "$data_sent" =~ ^[0-9]+$ ]]; then | |
echo "Error: Received invalid data. Expected numeric values for data_received and data_sent." >&2 | |
exit 1 | |
fi | |
# Build JSON payload | |
json_payload="{ \"data_received\": $data_received, \"data_sent\": $data_sent }" | |
webhook_url="your HA webhook url" | |
# Send the data to Home Assistant | |
curl "$webhook_url" \ | |
-H "Content-Type: application/json" \ | |
-d "@-" <<< "$json_payload" | |
else | |
echo "Error: Unable to retrieve data for ppp0 interface." >&2 | |
exit 1 | |
fi | |
# Crontab | |
#* * * * * ( /persistent/system/ppp0_stats.sh ) | |
#* * * * * ( sleep 10 ; /persistent/system/ppp0_stats.sh ) | |
#* * * * * ( sleep 20 ; /persistent/system/ppp0_stats.sh ) | |
#* * * * * ( sleep 30 ; /persistent/system/ppp0_stats.sh ) | |
#* * * * * ( sleep 40 ; /persistent/system/ppp0_stats.sh ) | |
#* * * * * ( sleep 50 ; /persistent/system/ppp0_stats.sh ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment