>D 48 ; for external ScriptEditor ; Version see >W section IP=192.168.178.123 ; SB=6200 only if you have 1M flash ; and compile with #define EEP_SCRIPT_SIZE 6200 ; and #define USE_EEPROM SB=6200 ; ; https://ottelo.jimdofree.com/stromzähler-auslesen/ ; ; ; Wichtig: ;======= ; Damit der Tagesverbrauch und die Diagramme auch die korrekten Werte anzeigen muss nach dem Start ; (Auf eurer Tasmota Seite oben muss der korrekte Zählerstand dargestellt werden) ; folgendes hintereinander in der Console eingegeben werden: ; ; script>=#reset ; script>=#dreset ; script>=#dtreset ; script>=#mtreset ; ; Websensoren ;============ ; Websensor2 0 ; Websensor53 0 ; ;Damit die Zeitzone korrekt ist, folgendes eingeben: ;======================================= ; ; TimeSTD 0, 0, 10, 1, 3, 60 ; TimeDST 0, 0, 3, 1, 2, 120 ; timezone 99 ; time ; ; ;Script-Variablen Setzen in der Konsole ;=============================== ; ; mval (kWh Verbrauchswert am Anfang des aktuellen Monats, wichtig für "Monatsverbrauch") ; dval (kWh Verbrauchswert am Anfang des aktuellen Tages, wichtig für "Tagesverbrauch") ; ; Tagesanfang: abfragen script? dval ; Monatsanfang: abfragen script? mval ; ; Tagesanfang: setzen script>dval=13917.81 ; Monatsanfang: setzen script>mval=13902.04 ; ; sday[n] (24h Diagramm n=1-24 Stunden) ; dcon[n] (Monatsdiagramm n=1-31 Tag im Monat) ; mcon[n] (Jahresdiagramm n=1=Januar 12=Dezember) ; ; ; Verbrauch Monat / Tage: ; script>dcon[1]=9.350;dcon[2]=6.420;dcon[3]=9.930;dcon[4]=6.856;dcon[5]=7.823;dcon[6]=6.528; ; script>dcon[7]=5.201;dcon[8]=9.859;dcon[9]=11.376;dcon[10]=7.029;dcon[11]=7.323;dcon[12]=7.761; ; script>dcon[13]=2.968;dcon[14]=10.859;dcon[15]=11.376;dcon[16]=14.149;dcon[17]=4.080;dcon[18]=7.023; ; script>dcon[19]=9.013;dcon[20]=7.009;dcon[21]=6.000;dcon[22]=12.229;dcon[23]=8.535;dcon[24]=7.844 ; script>dcon[25]=10.107;dcon[26]=7.375;dcon[27]=7.552;dcon[28]=10.091;dcon[29]=9.523;dcon[30]=8.266; ; script>dcon[31]=9.809; ; ; Verbrauch 2022 Jahr / Monate: ; script>mcon[1]=0;mcon[2]=0;mcon[3]=0;mcon[4]=0; ; script>mcon[5]=0;mcon[6]=0;mcon[7]=0;mcon[8]=0; ; script>mcon[9]=0;mcon[10]=0;mcon[11]=0;mcon[12]=0;svars ; ; HowTo: ;======= ; Download the ScriptEditor from Tasmota Script page ; Change the IP and maybe the SB (look for EEP_SCRIPT_SIZE Tasmota Script page) ; change the -- SML -- script to your needs ; search for -300 und change it to your needs (I have only 300W PV) or remove it ; First start, go to console and type: script>=#dreset ; This will set the correct day consumption value ; 4h chart is not permament, after restart data is lost ; 24h, month and year chart is permament. Arrays are saved at midnight. ; to save immediately go to console and enter: script>=#save ; to change some values enter e.g.: script >dcon[day]=xxx ; ; ; console commands: ; script?var = get variable ; script >var=1 = set variable ; script>=svars = save permament var ; script>=#sub = run sub ; ; ;######################################################################## ; ; -- ARRAYS -- ;------------------------------------------------------------------- ; 24h power chart M:p:sday=0 96 ; daily energy consumption table day 1-31 M:p:dcon=0 31 ; ; monthly energy consumption table month 1-12 M:p:mcon=0 12 ; ; 4h power chart M:s4h=0 960 ; ; ;------------------------------------------------------------------- ; Variablen ;------------------------------------------------------------------- ;v1=SML#Total_In ;v2=SML#Total_out ;v3=SML#Power_curr ;v4=SML#Curr_summ ;v5=SML#Volt_avg ;v6=SML#Frequenz ;v7=SML#Meter_number ; v1=0 v2=0 v3=0 v4=0 v5=0 v6=0 v7=0 ; ; ; tmp=0 m15=0 cstr="" cstr2="" avgval=0 avgvalcnt=0 hour=0 mont=0 minutes=0 ; ; ;Permanente Variablen ;------------------------------------------------------------------- ; monthval and dayval p:mval=0 p:dval=0 ; ; ;------------------------------------------------------------------- ; -- BOOT -- ;------------------------------------------------------------------- >B ;disable mqtt at boot prevents sending 0 smlj=0 =>sensor53 r tper=10 is(0 "Jan|Feb|Mär|Apr|Mai|Jun|Jul|Aug|Sep|Okt|Nov|Dez|") ; ; -- SUBS -- ;------------------------------------------------------------------- ; 24h power chart #dreset for tmp 1 sday[-1] 1 sday[tmp]=0 next svars ; daily consumption month chart ; !execute this at the first time! #dtreset for tmp 1 dcon[-1] 1 dcon[tmp]=0 next dval=v1 svars ; monthly consumption year chart #mtreset for tmp 1 mcon[-1] 1 mcon[tmp]=0 next mval=v1 svars ; ; save #save print saving svars ; ; ; daily consumption month table #daysub wcs
wcs ; monthly consumption year table #monthsub wcs wcs ; ; random array #rnddcon for tmp 1 dcon[-1] 1 dcon[tmp]=rnd(10) next ; ; ;======================================== ; Gesamtverbrauch und Gesamteinspeisung erhalten ;---------------------------------------------------------------------- >T v1=SML#Total_in v2=SML#Total_out v3=SML#power v4=SML#Curr_summ v5=SML#Volt_avg v6=SML#Frequenz v7=SML#Meter_number ; ;======================================== ; Diese Werte werden mit MQTT übertragen. ;---------------------------------------------------------------------- >J ,"Z.Bezug":%3v1% ,"Z.Lieferung":%3v2% ; ; ;======================================== ;-- SML -- ;---------------------------------------------------------------------- >M 1 ;1=meter1 14=GPIO14 s=SML 0=filterOff 9600=baud MT175=Name +1,3,s,0,9600,SML 1,77070100010800ff@1000,Verbrauch,KWh,Total_in,3 1,77070100020800ff@1000,Netzeinspeisung,KWh,Total_out,3 1,77070100100700ff@1,Leistung,W,power,0 ; ; ;======================================== ; -- EVERY SECOND -- ;---------------------------------------------------------------------- >S ; Jahr kleiner 2021, dann nichts machen ; noch kein Datum und Uhrzeit if year<2021 then ; time not set break endif ; hour=hours mont=month ; ; get SML values, every teleperiod (10s)! if (upsecs%tper==0) then smlj=1 ; energy from grid [kWh] v1=sml[1] ; energy to grid [kWh] v2=sml[2] ; actual power [W] v3=sml[3] ; day consumption [kWh] dcon[day]=v1-dval ; month consumption [kWh] mcon[month]=v1-mval ; MQTT ;=>publish tele/%topic%/SENSOR {"Time":"%tstamp%","MT175":{"daily_con":%2dcon[day]%,"monthly_con":%2mcon[month]%}} endif ; ; ; 4h power chart - every 15s if (secs%15==0) then ; power to array, idx is set automatically s4h=v3 ; sum up power for "24h chart" avgval+=v3 avgvalcnt+=1; endif ; ; ; set x axis index to 4 hours a 15 sec therefore /240, no decimal point hour-=4 if (hour<0) then cstr2="cnth"+s(1.0((24-4+hours)*240)+(mins*4))+"/240" else cstr2="cnth"+s(1.0((hours-4)*240)+(mins*4))+"/240" endif ; ; hour=hours ; ; 24h power chart ; calc avg power [W] for last 15min and put into array[1-96] m15=int((((hours*60)+mins)/15)+1) if ((mins%15==0) and (chg[m15]>0)) then sday[m15]=int(avgval/avgvalcnt) avgval=0 avgvalcnt=0 ;svars save too often will damage flash endif ; ; set idx (pointer starts from 0!!) sday[0]=m15-1 ; set x axis idx to 24 hours a 15 min therefore /4, no decimal point ; calc minutes for x-axis tmp=hours if (mins<45) then minutes=mins+15 else minutes=mins-45 if (tmp<23) then tmp+=1 else tmp=0 endif endif ; cstr="cnt"+s(1.0(tmp+(int(minutes/15)/4))*4)+"/4" ; ; day consumption calculation at midnight if ((chg[hour]>0) and (hour==0)) then print Its midnight dval=v1 ; month change? if (chg[mont]>0) then mval=v1 endif ; save only 1 at midnight svars endif ; ; ;======================================== ; WEB INTERFACE ;---------------------------------------------------------------------- >W ; Auto reload ;$ ; ; Time/Date Datum:{m}%s(2.0day)%.%s(2.0month)%.%s(2.0year)% - %s(2.0hours)%:%s(2.0mins)%:%s(2.0secs)% Uptime:{m}%0uptime% min