MuMoKpoKoDuJI
ок, если хочешь можем подебажить. пришлешь вывод? сохрани скрипт куда-нибудь, запусти как в автоматизации с параметром device1,temperature,day
#!/bin/sh
mqtt_sub(){
mosquitto_sub $auth -W 5 -t "homed/recorder" | jq -r 'select(.id == "chart-telegram") | (.value // .avg) as $val | .timestamp | to_entries[] | [(.value/1000 | round), $val[.key]] | @tsv' >$1
}
host=""
username=""
password=""
auth=""
gplot_conf='set encoding utf8
set title "<TITLE>" font ",30" textcolor "#cccccc"
set datafile separator "\\t"
set xdata time
set timefmt "%s"
set format x "%Y-%m-%d %H:%M:%S"
set key top left autotitle columnheader
set grid
set autoscale
set terminal png enhanced size 1280,480 background rgb "#111111"
set xtics textcolor rgb "#797979"
set ytics textcolor rgb "#797979"
set key textcolor rgb "#797979"
set style line 5 lt rgb "#36a2eb" lw 2
set output "/tmp/homed_automation_<NAME>_<PROPERTY>.png"
plot "/tmp/homed_automation_<NAME>_<PROPERTY>.dat" using 1:2 title "<PROPERTY>" w l ls 5'
device=$(echo "$*" | cut -d ',' -f1)
property=$(echo "$*" | cut -d ',' -f2)
interval=$(echo "$*" | cut -d ',' -f3)
title=$(echo "$device" | sed s/_/\\\ /g)
time_format="%Y-%m-%d"
if [ -n "$host" ]; then
port=$(echo "$host" | cut -d ':' -f 2)
host=$(echo "$host" | cut -d ':' -f 1)
auth="-h $host"
[ -n "$port" ] && auth="$auth -p $port"
fi
[ -n "$username" ] && [ -n "$password" ] && auth="$auth -u $username -P $password"
endpointid=$(mosquitto_sub $auth -W 5 -t "#" | jq -r '.devices | select(. != null) | .[] | select(.name == "'"$device"'") | [.name, .ieeeAddress] | @tsv' | cut -d $'\t' -f2)
end="$(date +"%s")000"
case "$interval" in
"day")
start=$((end-86400000))
time_format="%H:%M:%S"
;;
"week")
start=$((end-7*86400000));;
"month")
start=$((end-30*86400000));;
*)
start=$((end-86400000));;
esac
req='{"action":"getData","end":"'$end'","endpoint":"zigbee/'$endpointid'","id":"chart-telegram","property":"temperature","start":"'$start'"}'
rm -f /tmp/homed_automation_*
echo "$req"
device=$(echo "$device" | sed s/[[:space:]]/_/g)
mqtt_sub "/tmp/homed_automation_""$device""_$property.dat" &
sleep 1
mosquitto_pub $auth -t "homed/command/recorder" -m "$req"
sleep 1
echo -e "$gplot_conf" | sed s/\<TITLE\>/"$title"/g | sed s/\<NAME\>/"$device"/g | sed s/\<TIME_FORMAT\>/"$time_format"/g | sed s/\<PROPERTY\>/"$property"/g
GDFONTPATH=/opt/usr/share/fonts/ gnuplot <(echo -e "$gplot_conf" | sed s/\<TITLE\>/"$title"/g | sed s/\<NAME\>/"$device"/g | sed s/\<TIME_FORMAT\>/"$time_format"/g | sed s/\<PROPERTY\>/"$property"/g) 2>/dev/null && \
echo "/tmp/homed_automation_""$device""_$property.png"