1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-30 12:54:50 +00:00
Munin-Contrib/plugins/power/tasmota_
2023-10-16 13:46:14 +11:00

189 lines
5.1 KiB
Bash
Executable file

#!/bin/sh
: << =cut
=head1 NAME
tasmota_ - logs voltage, energy usage, power, power factor and current logged from tasmota power switches
To install the plugin, copy or move the plugin to /usr/share/munin/plugins/ set
the chmod to 755 and create a symbolic link:
ln -s /usr/share/munin/plugins/tasmota_ /etc/munin/plugins/tasmota_hostname_voltage
ln -s /usr/share/munin/plugins/tasmota_ /etc/munin/plugins/tasmota_hostname_energy
ln -s /usr/share/munin/plugins/tasmota_ /etc/munin/plugins/tasmota_hostname_power
ln -s /usr/share/munin/plugins/tasmota_ /etc/munin/plugins/tasmota_hostname_powerfactor
ln -s /usr/share/munin/plugins/tasmota_ /etc/munin/plugins/tasmota_hostname_current
Plugin also implements suggests, so if you have nodeattr installed and
/etc/genders populated with "tasmota" as well as "powermon" or
"DS18B20temp" flags for those tasmota devices that implement energy or
temperature monitoring, you can run an ansible play like this to set
up your links:
https://github.com/spacelama/ansible-initial-server-setup/tree/master/roles/monitoring/tasks
=head1 APPLICABLE SYSTEMS
Any host that can access tasmota systems and has "jq" installed. Can
auto suggest values if nodeattr genders (debian: apt install genders)
installed and configured with tasmota, powermon, DS18B20temp flags.
=head1 AUTHOR
Tim Connors <tconnors@rather.puzzling.org>
=head1 LICENSE
GPLv2 or later
=head1 MAGICK MARKERS
#%# family=auto
#%# capabilities=autoconf
=cut
DEVICE=$(basename "$0" | cut -d_ -f2)
FUNCTION=$(basename "$0" | cut -d_ -f3)
if [ "$1" = "autoconf" ]; then
echo yes && exit 0
fi
if [ "$1" = "suggest" ]; then
nodeattr -n 'tasmota&&powermon' | while read device ; do
for i in voltage power powerfactor current energy ; do
echo "${device}_${i}"
done
done
nodeattr -n 'tasmota&&DS18B20temp' | while read device ; do
for i in DS18B20temp ; do
echo "${device}_${i}"
done
done
exit
fi
voltage() {
if [ "$1" = "config" ]; then
echo "graph_title Tasmota Voltage: $DEVICE"
echo "graph_category sensors"
echo "graph_vlabel Volts"
echo "graph_args --base 1000 -l 0"
echo "Volts.label Volts"
exit 0
else
res=$( curl -fsS --data-urlencode "cmnd=Status 8" http://$DEVICE/cm )
volts=$( echo "$res" | jq -c '.StatusSNS.ENERGY.Voltage' )
echo Volts.value $volts
fi
}
current() {
if [ "$1" = "config" ]; then
echo "graph_title Tasmota Current: $DEVICE"
echo "graph_category sensors"
echo "graph_vlabel Amps"
echo "graph_args --base 1000 -l 0"
echo "Current.label Current"
exit 0
else
res=$( curl -fsS --data-urlencode "cmnd=Status 8" http://$DEVICE/cm )
current=$( echo "$res" | jq -c '.StatusSNS.ENERGY.Current' )
echo Current.value $current
fi
}
power() {
if [ "$1" = "config" ]; then
echo "graph_title Tasmota Power: $DEVICE"
echo "graph_category sensors"
echo "graph_vlabel Watts"
echo "graph_args --base 1000 -l 0"
for i in Power ApparentPower ReactivePower ; do
echo "${i}.label $i"
echo "${i}.type GAUGE"
echo "${i}.min 0"
done
else
res=$( curl -fsS --data-urlencode "cmnd=Status 8" http://$DEVICE/cm )
for i in Power ApparentPower ReactivePower ; do
power=$( echo "$res" | jq -c '.StatusSNS.ENERGY.'$i )
echo $i.value $power
done
fi
}
powerfactor() {
if [ "$1" = "config" ]; then
echo "graph_title Tasmota Power factor: $DEVICE"
echo "graph_category sensors"
echo "graph_vlabel Power Factor"
echo "graph_args --base 1000 -l 0"
echo "PowerFactor.min 0"
echo "PowerFactor.max 1"
echo "PowerFactor.label Power Factor"
exit 0
else
res=$( curl -fsS --data-urlencode "cmnd=Status 8" http://$DEVICE/cm )
powerfactor=$( echo "$res" | jq -c '.StatusSNS.ENERGY.Factor' )
echo PowerFactor.value $powerfactor
fi
}
energy() {
if [ "$1" = "config" ]; then
echo "graph_title Tasmota Energy: $DEVICE"
echo "graph_category sensors"
echo "graph_args --base 1000"
echo "graph_vlabel kWh"
echo "Energy.label Energy"
echo "Energy.draw AREA"
exit 0
else
res=$( curl -fsS --data-urlencode "cmnd=Status 8" http://$DEVICE/cm )
energy=$( echo "$res" | jq -c '.StatusSNS.ENERGY.Total' )
echo Energy.value $energy
fi
}
DS18B20temp() {
if [ "$1" = "config" ]; then
echo "graph_title Tasmota Temperature: $DEVICE"
echo "graph_category sensors"
echo "graph_args --base 1000"
echo "graph_vlabel °C"
echo "Temperature.label Temperature"
echo "Temperature.type GAUGE"
#echo "Temperature.min 0"
exit 0
else
res=$( curl -fsS --data-urlencode "cmnd=Status 10" http://$DEVICE/cm )
energy=$( echo "$res" | jq -c '.StatusSNS.DS18B20.Temperature' )
echo Temperature.value $energy
fi
}
[ "$1" = "config" ] && echo "graph_category sensors"
case "$FUNCTION" in
voltage|power|powerfactor|current|energy|DS18B20temp)
$FUNCTION "$1"
;;
*)
echo "Unknown Function"
;;
esac