diff --git a/plugins/power/tasmota_ b/plugins/power/tasmota_ index 2dc058be..8fe53c3c 100755 --- a/plugins/power/tasmota_ +++ b/plugins/power/tasmota_ @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash : << =cut @@ -54,7 +54,7 @@ get_status() { cached_curl='{}' fi fi - res=$( echo "$cached_curl" | jq -c "$2" ) + res=$( echo "$cached_curl" | jq -c -r "$2" ) if [ "$res" = null ] ; then res=U fi @@ -79,31 +79,41 @@ if [ "$1" = "autoconf" ]; then fi 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 echo "${device}_${i}" 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 echo "${device}_${i}" 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 echo "${device}_${i}" 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 echo "${device}_${i}" 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 echo "${device}_${i}" 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 fi @@ -269,8 +279,82 @@ millivolts() { 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 - voltage|power|powerfactor|current|energy|DS18B20|SCD40|PMS5003|millivolts) + voltage|power|powerfactor|current|energy|DS18B20|SCD40|PMS5003|millivolts|switch|dimmer) $FUNCTION "$1" ;; *)