lukdwo / OpenWRT-collectd-MQTT-HA

OpenWRT Collectd to MQTT with Homeassistant Template
66 stars 11 forks source link

Add WAN Status and WAN IP Address #10

Open auanasgheps opened 1 month ago

auanasgheps commented 1 month ago

Hey there, this is not a real issue but I'm opening it to discuss this topic.

I wanted to get WAN Status and WAN IP address from the OpenWRT Router to Home Assistant. Whilst the IP Address can be achieved via a native integration in HA, the WAN Status needs some trickery.

I found out that is possible and someone has already done it here. I played with it, it works, but it's very rought.

I started to improve it and eventually I rewrote it entirely.

I think it would fit this "collection" (but I would call it lite-integration): it's still MQTT based, but uses a hotplug script.

If you fancy, I can create a PR so we can get these two sensors added as well!

auanasgheps commented 2 weeks ago

Hey @lukdwo any feedback on this? I've been working on it in my branch and I've almost completed it.

lukdwo commented 2 weeks ago

Hi, I'm sorry I was out of the loop for a while. It is a lot of opportunities to upgrade this collectd-MQQ-HA solution. For instance I wrote basic script which use speedtest.net CLI to check network speed: image

Use speedtest on exact SRV and save to file

speedtest -s 60535 --accept-gdpr -f json-pretty > speedtest.json

Download

mosquitto_pub -h 192.168.100.100 -p 1883 -u USERNAME -P PASSWORD -r -t speedtest/download/bandwidth -m "$(($(cat speedtest.json | jq ".download.bandwidth")/125000))" mosquitto_pub -h 192.168.100.100 -p 1883 -u USERNAME -P PASSWORD -r -t speedtest/download/bytes -m "$(($(cat speedtest.json | jq ".download.bytes")/1000000))" mosquitto_pub -h 192.168.100.100 -p 1883 -u USERNAME -P PASSWORD -r -t speedtest/download/elapsed -m "$(($(cat speedtest.json | jq ".download.elapsed")/1000))" mosquitto_pub -h 192.168.100.100 -p 1883 -u USERNAME -P PASSWORD -r -t speedtest/download/latency -m "$(cat speedtest.json | jq ".download.latency.iqm")"

PacketLoss

mosquitto_pub -h 192.168.100.100 -p 1883 -u USERNAME -P PASSWORD -r -t speedtest/packetloss -m "$(cat speedtest.json | jq ".packetLoss")" mosquitto_pub -h 192.168.100.100 -p 1883 -u USERNAME -P PASSWORD -r -t speedtest/resulturl -m "$(cat speedtest.json | jq ".result.url")"

Upload

mosquitto_pub -h 192.168.100.100 -p 1883 -u USERNAME -P PASSWORD -r -t speedtest/upload/bandwidth -m "$(($(cat speedtest.json | jq ".upload.bandwidth")/125000))" mosquitto_pub -h 192.168.100.100 -p 1883 -u USERNAME -P PASSWORD -r -t speedtest/upload/bytes -m "$(($(cat speedtest.json | jq ".upload.bytes")/1000000))" mosquitto_pub -h 192.168.100.100 -p 1883 -u USERNAME -P PASSWORD -r -t speedtest/upload/elapsed -m "$(($(cat speedtest.json | jq ".download.elapsed")/1000))" mosquitto_pub -h 192.168.100.100 -p 1883 -u USER -P PASSWORD -r -t speedtest/upload/latency -m "$(cat speedtest.json | jq ".download.latency.iqm")"

It is up to you what would you like to achieve and what you need. If you need any support please let me know.

BTW: The easiest way to get public IP is to sent result of curl ifconfig.me to mqtt.

auanasgheps commented 2 weeks ago

The speedtest feature is very interesting!

It is up to you what would you like to achieve and what you need. If you need any support please let me know.

My goal is to get all the useful information we can. I used to run a Asus router which has an excellent integration with HA, OpenWRT has basically nothing.

This collection is the best I've found on the web and I'm committed to make it better.

You can see the work I've done in this branch. In addition to the WAN sensors I've also done some documentation improvements.

I'm still not ready, I've just created sensors to get the current WAN speed in Mbits, which is very useful to monitor Internet usage.

I will do a PR when ready.

I also think we should change the name to make it a bit more user friendly.