1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-21 18:41:03 +00:00

Merge pull request #1406 from spacelama/master

Add switch and dimmer state capability for tasmota plugin
This commit is contained in:
Kenyon Ralph 2023-12-23 13:12:11 -08:00 committed by GitHub
commit b963a960d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,4 +1,4 @@
#!/bin/sh #!/bin/bash
: << =cut : << =cut
@ -54,7 +54,7 @@ get_status() {
cached_curl='{}' cached_curl='{}'
fi fi
fi fi
res=$( echo "$cached_curl" | jq -c "$2" ) res=$( echo "$cached_curl" | jq -c -r "$2" )
if [ "$res" = null ] ; then if [ "$res" = null ] ; then
res=U res=U
fi fi
@ -79,31 +79,41 @@ if [ "$1" = "autoconf" ]; then
fi fi
if [ "$1" = "suggest" ]; then if [ "$1" = "suggest" ]; then
nodeattr -n 'tasmota&&powermon' | while read -r device ; do nodeattr -n '(tasmota || beken) && powermon' | while read -r device ; do
for i in voltage power powerfactor current energy ; do for i in voltage power powerfactor current energy ; do
echo "${device}_${i}" echo "${device}_${i}"
done done
done done
nodeattr -n 'tasmota&&DS18B20' | while read -r device ; do nodeattr -n '(tasmota || beken) && DS18B20' | while read -r device ; do
for i in DS18B20 ; do for i in DS18B20 ; do
echo "${device}_${i}" echo "${device}_${i}"
done done
done done
nodeattr -n 'tasmota&&SCD40' | while read -r device ; do nodeattr -n '(tasmota || beken) && SCD40' | while read -r device ; do
for i in SCD40 ; do for i in SCD40 ; do
echo "${device}_${i}" echo "${device}_${i}"
done done
done done
nodeattr -n 'tasmota&&PMS5003' | while read -r device ; do nodeattr -n '(tasmota || beken) && PMS5003' | while read -r device ; do
for i in PMS5003 ; do for i in PMS5003 ; do
echo "${device}_${i}" echo "${device}_${i}"
done done
done done
nodeattr -n 'tasmota&&millivolts' | while read -r device ; do nodeattr -n '(tasmota || beken) && millivolts' | while read -r device ; do
for i in millivolts ; do for i in millivolts ; do
echo "${device}_${i}" echo "${device}_${i}"
done done
done done
nodeattr -n '(tasmota || beken) && switch' | while read -r device ; do
for i in switch ; do
echo "${device}_${i}"
done
done
nodeattr -n '(tasmota || beken) && dimmer' | while read -r device ; do
for i in dimmer ; do
echo "${device}_${i}"
done
done
exit exit
fi fi
@ -269,8 +279,82 @@ millivolts() {
fi fi
} }
switch() {
if [ "$1" = "config" ]; then
echo "graph_title Tasmota Switch: $DEVICE"
echo "graph_args --base 1000 -l 0"
fi
for v in POWER POWER{1,2,3,4,5,6,7,8,9} ; do
axis=$( echo "$v" | cut -d= -f 1 )
lab=$( echo "$v" | cut -d= -f 2 )
get_status 11 ".StatusSTS.$v"
if [ "$res" != U ] || [ -e $MUNIN_PLUGSTATE/tasmota/$DEVICE.$FUNCTION.$v.seen ] ; then
# if we've ever seen an axis, then we want to keep
# telling munin we are capable of reading that axis,
# even if the device is currently unpowered
mkdir -p $MUNIN_PLUGSTATE/tasmota
touch $MUNIN_PLUGSTATE/tasmota/$DEVICE.$FUNCTION.$v.seen
if [ "$1" = "config" ]; then
echo "$axis.label $lab"
echo "$axis.type GAUGE"
echo "$axis.min 0"
else
case "$res" in
ON)
res=1
;;
OFF)
res=0
;;
U) # assume off, since if it doesn't have power to get wifi, then it's not going to have power output
res=0
;;
esac
echo "$axis.value $res"
fi
fi
done
}
dimmer() {
if [ "$1" = "config" ]; then
echo "graph_title Tasmota Dimmer: $DEVICE"
echo "graph_args --base 1000 -l 0"
fi
for v in Channel{1,2,3,4} ; do
axis=$( echo "$v" | cut -d= -f 1 )
lab=$( echo "$v" | cut -d= -f 2 )
get_status 11 ".StatusSTS.$v"
if [ "$res" != U ] || [ -e $MUNIN_PLUGSTATE/tasmota/$DEVICE.$FUNCTION.$v.seen ] ; then
# if we've ever seen an axis, then we want to keep
# telling munin we are capable of reading that axis,
# even if the device is currently unpowered
mkdir -p $MUNIN_PLUGSTATE/tasmota
touch $MUNIN_PLUGSTATE/tasmota/$DEVICE.$FUNCTION.$v.seen
if [ "$1" = "config" ]; then
echo "$axis.label $lab"
echo "$axis.type GAUGE"
echo "$axis.min 0"
else
if [ "$res" = U ] ; then
res=0 # assume 0 power, since if it doesn't have power to get wifi, then it's not going to have power output
fi
echo "$axis.value $res"
fi
fi
done
}
case "$FUNCTION" in case "$FUNCTION" in
voltage|power|powerfactor|current|energy|DS18B20|SCD40|PMS5003|millivolts) voltage|power|powerfactor|current|energy|DS18B20|SCD40|PMS5003|millivolts|switch|dimmer)
$FUNCTION "$1" $FUNCTION "$1"
;; ;;
*) *)