Just flashed my old TP-Link Archer C9v1 with dd-wrt and it is working fine. I just want to have a glance of the router CPU Temperature, load and free ram. The end result looks like this:
FYI, my Hassio runs on Ubuntu server.
The rather simple ones are CPU load and free ram which has known SNMP OID values. The more complicated part is the CPU temperature which needs more steps to achieve.
CPU Load:
For the CPU load, I can find only the SNMP OID values for the 1-min, 5-min, and 15-min average load. So I use the 1-min average load to convert to percentage. Due to a dual-core CPU, the average load value 2 should represent 100% (both cores run at full load).
ps. Don’t forget to enable SNMP in your router, under Services tab, and set a more secured RO Community password.
SNMP OID values:
cpu avg load 1 min .1.3.6.1.4.1.2021.10.1.3.1
cpu avg load 5 min .1.3.6.1.4.1.2021.10.1.3.2
cpu avg load 15 min .1.3.6.1.4.1.2021.10.1.3.3
In configuration.yaml, under sensors section:
# Archer C9 CPU Load
- platform: snmp
name: AP C9 CPU Load
host: 192.168.2.254
community: !secret snmp_community_C9
baseoid: 1.3.6.1.4.1.2021.10.1.3.1
accept_errors: true
unit_of_measurement: '%'
# Dual CPU, so if value is 2, it means 100%, so multiply by 50
value_template: '{{ value | multiply(50) | round(1) }}'
Ram Free:
total ram free OID: .1.3.6.1.4.1.2021.4.11.0
it keeps ram free value in KB, I converted it to MB
In configuration.yaml, under sensors section:
# Archer C9 Ram free
- platform: snmp
name: AP C9 RAM Free
host: 192.168.2.254
community: !secret snmp_community_C9
baseoid: 1.3.6.1.4.1.2021.4.11.0
accept_errors: true
unit_of_measurement: 'MB'
value_template: '{{ value | multiply(0.001) | round(1) }}'
CPU Temperature:
The CPU temperature in my dd-wrt router is stored in file: /proc/dmu/temperature . The stored value must be divided by 10 to get the correct degree celcius.
I then have to create a script on my Hassio server and use cron job (at root level) to run it every minute (you can use a longer interval). The script is basically copying the raw temp value from my router to homeassistant config subfolder (mine is /usr/share/hassio/homeassistant/ddwrt).
However, we cannot simply copy it across server with a single steps. Here is my script:
#1/bin/sh
#copy temperature data from pseudo file on ddwrt to a temp file on ddwrt
ssh [email protected] 'cat /proc/dmu/temperature > /tmp/var/tmp/cpu_temp.txt'
#copy temperature data from a temp file on ddwrt to homeassistant config subdirectory
scp [email protected]:/tmp/var/tmp/cpu_temp.txt /usr/share/hassio/homeassistant/ddwrt/cpu_temp.txt
The cron job on my Hassio server (by using ‘sudo crontab -e’ command)
*/1 * * * * sh /home/yourusername/archerc9cputemp.sh
The reason to run cron job at root level because I need to copy the temperature file to the root folder (Homeassistant folders, for me, at ’ /usr/share/hassio/homeassistant/ddwrt’).
A preparation before running the above script is that both the ssh and scp commands in the script requires you to gen private and public keys on your Hassio server at root level (using command ‘ssh-keygen’ at root user). Then you have to copy the content inside the generated public key file to the DD-WRT router (open DD-WRT gui, Services tab)
Once you have both keys in the proper places, the above script can run as a background job without interactive inputs.