#/bin/bash # SMAspot with Volkszaehler # WF 2014-05-29 # $Header: /home/wf/smaspot/RCS/sma2vz,v 1.8 2014/06/01 10:49:38 wf Exp wf $ # # get a configuration # param 1: bluetooth address # param 2: name of configuration/plant # param 3: "USER" password for SMA device # param 4: latitude of plant # param 5: longitude of plant # param 6: path to output files of SMAspot # smaspot_config() { local l_btaddr=$1 local l_name=$2 local l_password=$3 local l_lon=$4 local l_lat=$5 local l_path=$6 cat << EOF ################################################################################ # ____ __ __ _ _ # / ___|| \/ | / \ ___ _ __ ___ | |_ # \___ \| |\/| | / _ \ / __| '_ \ / _ \| __| # ___) | | | |/ ___ \\__ \ |_) | (_) | |_ # |____/|_| |_/_/ \_\___/ .__/ \___/ \__| # |_| # # SMAspot.cfg - Configuration file for SMAspot.exe # SMAspot - Yet another tool to read power production of SMA solar inverters # (c)2012-2014, SBF # # DISCLAIMER: # A user of SMAspot software acknowledges that he or she is receiving this # software on an "as is" basis and the user is not relying on the accuracy # or functionality of the software for any purpose. The user further # acknowledges that any use of this software will be at his own risk # and the copyright owner accepts no responsibility whatsoever arising from # the use or application of the software. # ################################################################################ # SMA Inverter's Bluetooth address # Windows: smaspot -scan # Linux : hcitool scan # IMPORTANT FOR SPEEDWIRE USERS: COMMENT OUT BTADDRESS (PUT # IN FRONT) BTAddress=$l_btaddr # SMA Inverter's Speedwire IP address # If IP_Address is not set or is 0.0.0.0 SMAspot will try to detect the speedwire inverter by broadcast # If IP_Address is set to a valid IP, SMAspot will try to connect directly to that IP without broadcast detection #IP_Address=0.0.0.0 # User password (default 0000) Password=$l_password # MIS_Enabled (Multi Inverter Support: Default=0 Disabled) # +------------+-------+-------------+ # | #Inverters | NetID | MIS_Enabled | # +------------+-------+-------------+ # | 1 | 1 | Don't Care | # +------------+-------+-------------+ # | 1 | >1 | 0 | # +------------+-------+-------------+ # | >1 | >1 | 1 | # +------------+-------+-------------+ MIS_Enabled=0 # Plantname Plantname=$l_name # OutputPath (Place to store CSV files) # # Windows: C:\TEMP\SMA\%Y # Linux : /home/sbf/Documents/sma/%Y # %Y %m and %d will be expanded to Year Month and Day OutputPath=$l_path/%Y # OutputPathEvents (Place to store CSV files for events) # If omitted, OutputPath is used OutputPathEvents=$l_path/Events # Position of pv-plant http://itouchmap.com/latlong.html # Example for Ukkel, Belgium Latitude=$l_lat Longitude=$l_lon # Calculate Missing SpotValues # If set to 1, values not provided by inverter will be calculated # eg: Pdc1 = Idc1 * Udc1 CalculateMissingSpotValues=1 # DateTimeFormat (default %d/%m/%Y %H:%M:%S) # For details see strftime() function # http://www.cplusplus.com/reference/clibrary/ctime/strftime/ DateTimeFormat=%Y-%m-%d %H:%M:%S # DateFormat (default %d/%m/%Y) DateFormat=%-%m-%d # DecimalPoint (comma/point default comma) DecimalPoint=point # TimeFormat (default %H:%M:%S) TimeFormat=%H:%M:%S # SynchTime (default 1 = On) # If set to 1 the Inverter time is synchronised with pc time # Some inverters don't have a real-time clock SynchTime=1 # SunRSOffset # Offset to start before sunrise and end after sunset (0-3600 - default 900 seconds) SunRSOffset=900 # Locale # Translate Entries in CSV files # Surpported locales: de-DE;en-US;fr-FR;nl-NL;es-ES;it-IT # Default en-US Locale=de-DE # Timezone # Select the right timezone in date_time_zonespec.csv # e.g. Timezone=Europe/Brussels Timezone=Europe/Berlin ########################### ### CSV Export Settings ### ########################### # With CSV_* settings you can define the CSV file format # CSV_Export (default 1 = Enabled) # Enables or disables the CSV Export functionality CSV_Export=1 # CSV_ExtendedHeader (default 1 = On) # Enables or disables the SMA extended header info (8 lines) # isep=; # Version CSV1|Tool SMAspot|Linebreaks CR/LF|Delimiter semicolon|Decimalpoint comma|Precision 3 # etc... # This is usefull for manual data upload to pvoutput.org CSV_ExtendedHeader=1 # CSV_Header (default 1 = On) # Enables or disables the CSV data header info (1 line) # dd/MM/yyyy HH:mm:ss;kWh;kW # This is usefull for manual data upload to pvoutput.org # If CSV_ExtendedHeader is enabled, CSV_Header is also enabled CSV_Header=1 # CSV_SaveZeroPower (default 1 = On) # When enabled, daily csv files contain all data from 00:00 to 23:55 # This is usefull for manual data upload to pvoutput.org CSV_SaveZeroPower=1 # CSV_Delimiter (comma/semicolon default semicolon) CSV_Delimiter=semicolon # CSV_Spot_TimeSource (Inverter|Computer default Inverter) CSV_Spot_TimeSource=Inverter # CSV_Spot_WebboxHeader (Default 0 = Off) # When enabled, use Webbox style header (DcMs.Watt[A];DcMs.Watt[B]...) CSV_Spot_WebboxHeader=0 ################################# ### Online Monitoring Systems ### ################################# # # In the future, multiple online monitoring systems can be defined # Here we can activate the ones we like # ################################ ### PVoutput Upload Settings ### ################################ # PVoutput (default 0 = Disabled) # Enables or disables the upload functionality to pvoutput.org # When enabled, be sure to use -u switch on the command line PVoutput=0 #PVoutput_SID #Sets PVoutput System ID PVoutput_SID= #PVoutput_Key #Sets PVoutput API Key PVoutput_Key= # VoltageLogging sets AC or DC logging. # Possible values are: # NONE (disabled) # MAX(AC) (default) # AC(PH1) or AC(PH2) or AC(PH3) # MAX(DC) or DC(ST1) or DC(ST2) VoltLogging=MAX(AC) # InverterTemp (default 0 = disabled) # Enables or disables the upload of the inverter's temperature InverterTemp=0 # InverterTempMapTo (default v5 = Use standard PVoutput Temperature Graph) # In Donation Mode only, map inverter's temperature to extended data field (v7..v12) # For more info, see http://pvoutput.org/help.html#donations InverterTempMapTo=v5 # CumulativeEnergy (default 0 = Today's Energy) # Set the cumulative flag = 1 when you wish to pass lifetime energy or 0 for today's energy # WARNING!!! DO NOT CHANGE THIS FLAG DURING DAYLIGHT AS THIS WILL MESS UP YOUR PVOUTPUT GRAPHS CumulativeEnergy=0 EOF } # #inverters # inverters() { # insert your data from # hcitool scan | grep SMA # # first column is bluetooth address # second column is the name of the device (here just the wattage is used) # third column is the password for "USER" that the SMA Device expects # fourth column is the latitude # fifth column is the longitude cat << EOF 00:80:25:24:xx:xy 1300Watt password /home/wf/smaspot 00:80:25:29:xx:xy 4000Watt password /home/wf/smaspot EOF } # # create configuration files # configure() { checklonlat "configure" inverters | while read btaddr name password path; do echo "creating ${name}.cfg for bluetooth addr $btaddr" 1>&2 smaspot_config $btaddr $name $password $lon $lat $path > ${name}.cfg done } # # get the sma meter reading # getsmameter() { # temp filename base for SMAspor result tmp=/tmp/smaspot$$ # read data from all inverters inverters | while read btaddr name password path; do # single shot run of SMAspot with no CVS export # uncomment to debug #echo "running smaspot with ${name}.cfg for bluetooth addr $btaddr" ./SMAspot -v -nocsv -cfg${name}.cfg > ${tmp}_${name} # the lines we need look like: # EToday: 3.358kWh # ETotal: 5151.294kWh # Total Pac : 0.442kW # let's filter the result with awk cat ${tmp}_${name} | awk ' # set the field separator fitting the x: y format BEGIN { FS=":";doublequote="\x22" } # check the input lines for the three patterns and remove # the unit at the end - assign to the three variables # etoday, etotal and totalpac /EToday:/ { etoday =$2;gsub("kWh","",etoday) } /ETotal:/ { etotal =$2;gsub("kWh","",etotal) } /Total Pac/ { totalpac=$2;gsub("kW" ,"",totalpac) } # at the end of all lines print out a single json formatted result line END { printf("{%s,%s,%s}\n", json("etoday",etoday), json("etotal",etotal), json("totalpac",totalpac)) } # helper function to create json name values function json(name,value,result) { # trim value gsub(" ","",value); result=quote(name)":"quote(value); return result } # helper function to quote a string function quote(s,result) { result=doublequote s doublequote; return result }' rm ${tmp}_${name} done } # # show usage # usage() { cat << EOF usage: $0 --vzurl=vzurl --cuuid_pwr=x --cuuid_kwh=y [ --daytimeonly --lat=lattitude --lon=longitude] [--loop --delay=delay] | [--help] | [--configure] --vzurl= volkszaehler middleware url --cuuid_pwr= channel uuid for power (watt) PV output --cuuid_kwh= channel uuid for energy (kwH) PV total --daytimeonly do not post data at night (e.g. if your device does not supply data) --lon= plant longitude geo coordinate --lat= plant lattitude geo coordinate --loop poll SMA inverters in a loop --delay= how many secs to wait between each reading (default: 15 secs) --configure create SMAsport configuration file(s) modify $0 inverters shell function here document to fit your plant's data EOF exit 1 } # # show error and exit # error() { local l_msg=$1 local l_hint=$2 echo "error $0: $l_msg" 1>&2 echo " you might want to $l_hint !" 1>&2 exit 1 } # # check that longitude and lattitude are supplied # checklonlat() { local l_title="$1" if [ "$lon" == "" ] then error "option --lon" "supply lon longitude setting for $l_title to work" fi if [ "$lat" == "" ] then error "option --lat" "supply lat lattitude setting for $l_title to work" fi } # defaults delay=15 maxloops=1 daytimeonly=0 # check command line arguments while [ $# -gt 0 ] do arg="$1" #echo "$arg" case "$arg" in --help) usage ;; --vzurl) vzurl="$2" shift ;; --cuuid_pwr) cuuid_pwr="$2" shift ;; --cuuid_kwh) cuuid_kwh="$2" #echo $cuuid_kwh shift ;; --daytimeonly) daytimeonly=1; ;; --lat) lat="$2" shift ;; --lon) lon="$2" shift ;; --delay) delay=$2 shift ;; --loop) maxloops=10000000; ;; --configure) echo "creating configuration files" configure exit ;; *) echo >&2 "Invalid argument: $1" exit 1 ;; esac shift done # check that options are set if [ "$vzurl" == "" ] then error "option --vzurl is missing" "check and use volkszaehler middleware url" fi if [ "${cuuid_pwr}" == "" ] then error "option --cuuid_pwr is missing" "check the uuid for the PV power (Watt) channel" fi if [ "$cuuid_kwh" == "" ] then error "option --cuuid_kwh" "check the uuid for the PV energy (kwH) channel" fi if [ "$daytimeonly" -eq 1 ] then checklonlat "daytimeonly" fi loop=0 while [ $loop -lt $maxloops ] do # get the SMA meter readings getsmameter | php sma2vz.php --vzurl=$vzurl --cuuid_pwr=$cuuid_pwr --cuuid_kwh=$cuuid_kwh --daytimeonly=$daytimeonly --lat=$lat --lon=$lon # sleep a while if [ $maxloops -gt 1 ] then sleep $delay fi loop=`expr $loop + 1 ` done