1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-08-03 14:48:22 +00:00

solarman: add new plugins

This commit is contained in:
Michael Grote 2023-03-02 16:22:34 +01:00
parent 418ae8e160
commit b2553475aa
2 changed files with 250 additions and 0 deletions

View file

@ -0,0 +1,143 @@
#!/bin/bash
#%# family=auto
#%# capabilities=autoconf
: << EOF
=head1 NAME
Outputs the total and daily production, DC current, DC voltage, DC power for the inverter and the connected panels from Solarman (Smart) API.
To get the API-Keys a E-Mail to customerservice@solarmanpv.com is needed.
=head1 CONFIGURATION
Tested with a "Deye SUN600G3-EU-230 600W" inverter.
Dependencies:
- curl
- jq
plugin config:
[solarman_api_inverter]
env.SLRM_APPID 2XXXXXXXX2
env.SLRM_DEVICE_SN=2XXXXXXXXX6-1
env.SLRM_MAIL "XXXX@YYY.de"
env.SLRM_PASSWORD 'aXXXXXXXXf'
env.SLRM_APPSECRET aXXXXXXXb
=head1 AUTHOR
Michael Grote
=head1 LICENSE
GPLv3 or later
SPDX-License-Identifier: GPL-3.0-or-later
=head1 MAGIC MARKERS
#%# family=auto
=cut
EOF
# check if jq is installed
if ! command -v "jq" &> /dev/null; then
echo "[ERROR] jq could not be found!"
exit 2
fi
# Combine Variables
## hash password; -n is used because "echo" normally outputs a newline
export SLRM_PASSWORD_SHA=$(echo -n $SLRM_PASSWORD | sha256sum | cut -f1 -d" ")
## set url
export SLRM_URL="https://api.solarmanpv.com/account/v1.0/token?appId=${SLRM_APPID}&language=en&="
## create request body for bearer token
export SLRM_BEARER_TOKEN_REQUEST_BODY=$(jq --null-input --arg appSecret "${SLRM_APPSECRET}" --arg email "${SLRM_MAIL}" --arg password "${SLRM_PASSWORD_SHA}" '{"appSecret": $appSecret, "email": $email, "password": $password}')
## get bearer token
export SLRM_BEARER_TOKEN=$(curl --silent --request POST --url "${SLRM_URL}" --header 'Content-Type: application/json' --data "$SLRM_BEARER_TOKEN_REQUEST_BODY" | jq .access_token | sed -r 's/"//g')
## create request body for panel data
export SLRM_DATA_REQUEST_BODY=$(jq --null-input --arg deviceSn "${SLRM_DEVICE_SN}" '{"deviceSn": $deviceSn}')
## get panel data
export SLRM_DATA=$(curl --silent --request POST --url "https://api.solarmanpv.com/device/v1.0/currentData?appId=${SLRM_APPID}&language=en&=" --header "Authorization: bearer ${SLRM_BEARER_TOKEN}" --header 'Content-Type: application/json' --data "${SLRM_DATA_REQUEST_BODY}")
# sometimes the api can not find the requested device, exit here
echo $SLRM_DATA | grep "device not found" && exit 1
# wenn parameter = ...
if [ "$1" = "autoconf" ]; then
echo yes
exit 0
fi
if [ "$1" = "config" ]; then
# setze optionen
echo "multigraph production_total"
echo "graph_title Production Total - SN: $SLRM_DEVICE_SN"
echo "graph_vlabel kWh"
echo "graph_category sensors"
echo "graph_args -l 0"
echo "graph_info The total Production in kWh of Inverter SN: $SLRM_DEVICE_SN"
echo "total_inverter.label Inverter"
echo "total_panel1.label Panel1"
echo "total_panel2.label Panel2"
echo "total_inverter.draw AREA"
echo "multigraph production_daily"
echo "graph_title Production Daily - SN: $SLRM_DEVICE_SN"
echo "graph_vlabel kWh"
echo "graph_category sensors"
echo "graph_args -l 0"
echo "graph_info The daily Production in kWh of Inverter SN: $SLRM_DEVICE_SN"
echo "daily_inverter.label Inverter daily kWh"
echo "daily_panel1.label Panel1 daily kWh"
echo "daily_panel2.label Panel2 daily kWh"
echo "multigraph temp"
echo "graph_title AC Radiator Temp - SN: $SLRM_DEVICE_SN"
echo "graph_vlabel °C"
echo "graph_category sensors"
echo "graph_args -l 0"
echo "graph_info The AC Radiator Temp in Celsius of Inverter SN: $SLRM_DEVICE_SN"
echo "temp.label AC Radiator Temp"
echo "multigraph voltage_current_input"
echo "graph_title DC Measurements - SN: $SLRM_DEVICE_SN"
echo "graph_vlabel V/A/W"
echo "graph_category sensors"
echo "graph_args -l 0"
echo "graph_info The current DC Voltage, Current and Power of Inverter SN: $SLRM_DEVICE_SN"
echo "voltage_panel1.label DC Voltage PV1"
echo "current_panel1.label DC Current PV1"
echo "power_panel1.label DC Power PV1"
echo "voltage_panel2.label DC Voltage PV2"
echo "current_panel2.label DC Current PV2"
echo "power_panel2.label DC Power PV2"
exit 0
fi
echo "multigraph production_total"
echo total_inverter.value "$(echo "$SLRM_DATA" | jq -r '.dataList[]|select(.key|IN("Et_ge0"))|.value')"
echo total_panel1.value "$(echo "$SLRM_DATA" | jq -r '.dataList[]|select(.key|IN("Et_ge1"))|.value')"
echo total_panel2.value "$(echo "$SLRM_DATA" | jq -r '.dataList[]|select(.key|IN("Et_ge2"))|.value')"
echo "multigraph temp"
echo temp.value "$(echo "$SLRM_DATA" | jq -r '.dataList[]|select(.key|IN("AC_RDT_T1"))|.value')"
echo "multigraph production_daily"
echo daily_inverter.value "$(echo "$SLRM_DATA" | jq -r '.dataList[]|select(.key|IN("Etdy_ge0"))|.value')"
echo daily_panel1.value "$(echo "$SLRM_DATA" | jq -r '.dataList[]|select(.key|IN("Etdy_ge1"))|.value')"
echo daily_panel2.value "$(echo "$SLRM_DATA" | jq -r '.dataList[]|select(.key|IN("Etdy_ge2"))|.value')"
echo "multigraph voltage_current_input"
echo voltage_panel1.value "$(echo "$SLRM_DATA" | jq -r '.dataList[]|select(.key|IN("DV1"))|.value')"
echo current_panel1.value "$(echo "$SLRM_DATA" | jq -r '.dataList[]|select(.key|IN("DC1"))|.value')"
echo power_panel1.value "$(echo "$SLRM_DATA" | jq -r '.dataList[]|select(.key|IN("DP1"))|.value')"
echo voltage_panel2.value "$(echo "$SLRM_DATA" | jq -r '.dataList[]|select(.key|IN("DV2"))|.value')"
echo current_panel2.value "$(echo "$SLRM_DATA" | jq -r '.dataList[]|select(.key|IN("DC2"))|.value')"
echo power_panel2.value "$(echo "$SLRM_DATA" | jq -r '.dataList[]|select(.key|IN("DP2"))|.value')"
exit 0

View file

@ -0,0 +1,107 @@
#!/bin/bash
#%# family=auto
#%# capabilities=autoconf
: << EOF
=head1 NAME
Outputs the total production, DC current, DC voltage, DC power from Solarman (Smart) API.
To get the API-Keys a E-Mail to customerservice@solarmanpv.com is needed.
=head1 CONFIGURATION
Tested with a "Deye SUN600G3-EU-230 600W" inverter.
Dependencies:
- curl
- jq
plugin config:
[solarman_api_panels_<name>]
env.SLRM_APPID 2XXXXXXXX2
env.SLRM_DEVICE_SN=2XXXXXXXXX6-1
env.SLRM_MAIL "XXXX@YYY.de"
env.SLRM_PASSWORD 'aXXXXXXXXf'
env.SLRM_APPSECRET aXXXXXXXb
=head1 AUTHOR
Michael Grote
=head1 LICENSE
GPLv3 or later
SPDX-License-Identifier: GPL-3.0-or-later
=head1 MAGIC MARKERS
#%# family=auto
=cut
EOF
# check if jq is installed
if ! command -v "jq" &> /dev/null; then
echo "[ERROR] jq could not be found!"
exit 2
fi
# Combine Variables
## hash password; -n is used because "echo" normally outputs a newline
export SLRM_PASSWORD_SHA=$(echo -n $SLRM_PASSWORD | sha256sum | cut -f1 -d" ")
## set url
export SLRM_URL="https://api.solarmanpv.com/account/v1.0/token?appId=${SLRM_APPID}&language=en&="
## create request body for bearer token
export SLRM_BEARER_TOKEN_REQUEST_BODY=$(jq --null-input --arg appSecret "${SLRM_APPSECRET}" --arg email "${SLRM_MAIL}" --arg password "${SLRM_PASSWORD_SHA}" '{"appSecret": $appSecret, "email": $email, "password": $password}')
## get bearer token
export SLRM_BEARER_TOKEN=$(curl --silent --request POST --url "${SLRM_URL}" --header 'Content-Type: application/json' --data "$SLRM_BEARER_TOKEN_REQUEST_BODY" | jq .access_token | sed -r 's/"//g')
## create request body for panel data
export SLRM_DATA_REQUEST_BODY=$(jq --null-input --arg deviceSn "${SLRM_DEVICE_SN}" '{"deviceSn": $deviceSn}')
## get panel data
export SLRM_DATA=$(curl --silent --request POST --url "https://api.solarmanpv.com/device/v1.0/currentData?appId=${SLRM_APPID}&language=en&=" --header "Authorization: bearer ${SLRM_BEARER_TOKEN}" --header 'Content-Type: application/json' --data "${SLRM_DATA_REQUEST_BODY}")
# sometimes the api can not find the requested device, exit here
echo $SLRM_DATA | grep "device not found" && exit 1
# wenn parameter = ...
if [ "$1" = "autoconf" ]; then
echo yes
exit 0
fi
if [ "$1" = "config" ]; then
# setze optionen
echo multigraph voltage_current_input
echo "graph_title Panel DC Voltage/Current/Power - SN: $SLRM_DEVICE_SN"
echo 'graph_vlabel V/A/W'
echo 'graph_category sensors'
echo 'graph_args -l 0'
echo "graph_info The Current DC Voltage, Current and Power of Panel SN: $SLRM_DEVICE_SN"
echo voltage.label Volt
echo current.label Ampere
echo power.label Watt
echo multigraph production
echo "graph_title Panel Total production - SN: $SLRM_DEVICE_SN"
echo 'graph_vlabel kWh'
echo 'graph_category sensors'
echo 'graph_args -l 0'
echo "graph_info The total Production in kWh of Panel SN: $SLRM_DEVICE_SN"
echo total.label kWh
echo total.draw AREA
exit 0
fi
echo multigraph voltage_current_input
echo voltage.value "$(echo "$SLRM_DATA" | jq -r '.dataList[]|select(.key|IN("DV1"))|.value')"
echo current.value "$(echo "$SLRM_DATA" | jq -r '.dataList[]|select(.key|IN("DC1"))|.value')"
echo power.value "$(echo "$SLRM_DATA" | jq -r '.dataList[]|select(.key|IN("DPi_t1"))|.value')"
echo multigraph production
echo total.value "$(echo "$SLRM_DATA" | jq -r '.dataList[]|select(.key|IN("Et_ge0"))|.value')"
exit 0