Moving the bar charts from a Tasmota Scripter script to the TinyC programsDie Balkendiagramme von einem Tasmota-Scripter-Script in die TinyC-Programme umziehen
The tool is a single HTML file. Open script_charts_to_tinyc_pvs.html from the tinyc/utils folder in any browser — no server, no install, and nothing is uploaded anywhere. The conversion happens entirely in your browser.
Already on TinyC and only want to look at your charts? That is the chart editor.
Das Werkzeug ist eine einzelne HTML-Datei. script_charts_to_tinyc_pvs.html aus dem Ordner tinyc/utils im Browser öffnen — kein Server, keine Installation, und es wird nichts hochgeladen. Die Umrechnung passiert vollständig im Browser.
Schon auf TinyC und willst nur deine Diagramme ansehen? Dafür gibt es den Diagramm-Editor.
Download data.csv from the old device's file manager (http://<device>/ufsd) and pick it here. Easier: enter the old device's IP at the top of step 1, then a ready-made link to the file appears there.
The layout is detected from the line and column counts, so you do not have to say which script wrote it.
No data.csv on the old device? An ESP8266 with 1 MB flash has no file system, so its Scripter never wrote one. Then take path a) in the tool: the bars live in the running script's memory, and one clicked link reads them out as JSON — paste the answer and press Balken übernehmen (take over bars):
http://<ip>/cm?cmnd=script%3Fdcon%3Bdprod%3Bmcon
Whether the script has feed-in is recognised from the answer: dprod present and mcon with 24 values, or dprod as "???" and mcon with 12. Two limits: do not restart the old device first — without a file system the bars are gone after a restart — and the 24 h curve does not come through this way (1441 values overflow the answer, the device replies "???"), so it stays empty.
Die data.csv im Dateimanager des alten Geräts (http://<geraet>/ufsd) herunterladen und hier auswählen. Bequemer: oben in Schritt 1 die IP des alten Geräts eintragen, dann steht dort ein fertiger Link auf die Datei.
Das Layout wird an den Zeilen- und Spaltenzahlen erkannt, du musst also nicht angeben, welches Script sie geschrieben hat.
Keine data.csv auf dem alten Gerät? Ein ESP8266 mit 1 MB Flash hat kein Dateisystem, sein Scripter hat also nie eine geschrieben. Dann im Werkzeug Weg a) nehmen: die Balken liegen im Arbeitsspeicher des laufenden Scripts, und ein angeklickter Link liest sie als JSON aus — Antwort einfügen, Balken übernehmen drücken:
http://<ip>/cm?cmnd=script%3Fdcon%3Bdprod%3Bmcon
Ob das Script Einspeisung hat, wird an der Antwort erkannt: dprod vorhanden und mcon mit 24 Werten, oder dprod als "???" und mcon mit 12. Zwei Grenzen: das alte Gerät vorher nicht neu starten — ohne Dateisystem sind die Balken danach weg — und der 24-h-Verlauf kommt so nicht mit (1441 Werte sprengen die Antwort, das Gerät meldet "???"), er bleibt leer.
dval, mval, yval and the feed-in twins are the counter zero points. In the Scripter they are p: variables in the Tasmota settings and therefore not in the data.csv. Without them the program computes every running bar as
sml_dcon[today] = meter reading − sml_dval
and with sml_dval at 0 that puts the whole meter reading into today's bar — it shoots up to something like 45,000 kWh and squashes the entire imported history onto the zero line.
Click the generated link (the IP is entered in step 1), copy the answer back into the field. A link you click is a normal navigation, so the same-origin rule that blocks a fetch from a local file does not apply — no USE_CORS needed.
http://<ip>/cm?cmnd=script%3Fdval%3Bmval%3Byval%3Bda
http://<ip>/cm?cmnd=script%3Fdval2%3Bmval2%3Byval2
Typing these by hand: keep %3F and %3B encoded. With a plain ; the device answers with the first variable only — {"script":{"dval":26714.37}} — and the baselines stay incomplete.
Leave the fields empty and no baselines are written. Then press Reset day/month/year consumption once on the device: the history survives, only the running day and month start at 0.
dval, mval, yval und die Einspeise-Zwillinge sind die Zähler-Nullpunkte. Im Scripter sind das p:-Variablen in den Tasmota-Einstellungen und stehen deshalb nicht in der data.csv. Ohne sie rechnet das Programm jeden laufenden Balken als
sml_dcon[heute] = Zählerstand − sml_dval
und bei sml_dval = 0 landet der komplette Zählerstand im heutigen Balken — der schießt auf z. B. 45.000 kWh hoch und drückt die ganze importierte Historie auf die Nulllinie.
Auf den erzeugten Link klicken (die IP steht in Schritt 1), die Antwort ins Feld zurückkopieren. Ein angeklickter Link ist eine normale Navigation — die Same-Origin-Sperre, die ein fetch aus einer lokalen Datei blockiert, greift dort nicht. Es braucht also kein USE_CORS.
http://<ip>/cm?cmnd=script%3Fdval%3Bmval%3Byval%3Bda
http://<ip>/cm?cmnd=script%3Fdval2%3Bmval2%3Byval2
Wer die Links von Hand eintippt: %3F und %3B kodiert lassen. Mit einem einfachen ; antwortet das Gerät nur mit der ersten Variable — {"script":{"dval":26714.37}} — und die Basiswerte bleiben unvollständig.
Bleiben die Felder leer, werden keine Basiswerte geschrieben. Dann auf dem Gerät einmal Tages/Monats/Jahres-Verbrauchswerte zurücksetzen drücken: die Historie bleibt, nur der laufende Tag und Monat fangen bei 0 an.
Only now — that way the baselines from step 2 are inside.
| File | Contents | without | with baselines |
|---|---|---|---|
sml_chart.bin | sml_s4h · sml_s24h · sml_dcon · sml_mcon | 1965 | 1969 |
sml_chart_pv.bin | sml_dprod · sml_mprod | 43 | 46 |
Raw 4-byte little-endian float32, no header — including the two int16 rings, which sml_chart_imp16() converts while reading. A script without feed-in produces only sml_chart.bin: 43 zeros would wipe a feed-in history that is already on the device.
And the tc_options.cfg — always. The TinyC programs share this file, and on their first tick it wins over the imported values:
sml_dval = tcOptGetF(0, sml_dval); // sml_chart.tc, first tick
main() has imported the .bin by then, so a baseline that only travels in the .bin is replaced one second later by the old value from the cfg — the log still says .bin carried baselines, yet day, month and year start near 0 and the next 60 s tick writes today's and this month's bar from the wrong zero point. So the tool writes the baselines into imp_day, imp_month, imp_year, exp_day, exp_month, exp_year and sml_da as well.
Load the new device's own tc_options.cfg into the tool first (enter its IP, the download link appears). The file also holds the settings of every other TinyC program, and only these seven keys are replaced. On a device that has none yet (File Not Found) just carry on without.
Erst hier — so sind die Basiswerte aus Schritt 2 mit drin.
| Datei | Inhalt | ohne | mit Basiswerten |
|---|---|---|---|
sml_chart.bin | sml_s4h · sml_s24h · sml_dcon · sml_mcon | 1965 | 1969 |
sml_chart_pv.bin | sml_dprod · sml_mprod | 43 | 46 |
Rohe 4-Byte-Little-Endian-float32, kein Kopf — auch für die beiden int16-Ringe, die sml_chart_imp16() beim Lesen umwandelt. Ein Script ohne Einspeisung erzeugt nur sml_chart.bin: 43 Nullen würden eine schon vorhandene Einspeise-Historie löschen.
Dazu die tc_options.cfg — immer. Die TinyC-Programme teilen sich diese Datei, und beim ersten Tick gewinnt sie gegen die importierten Werte:
sml_dval = tcOptGetF(0, sml_dval); // sml_chart.tc, erster Tick
main() hat die .bin da schon importiert. Ein Nullpunkt, der nur in der .bin steht, wird also eine Sekunde später durch den alten Wert aus der cfg ersetzt — im Log steht trotzdem .bin carried baselines, aber Tag, Monat und Jahr fangen fast bei 0 an, und der nächste 60-s-Tick schreibt den heutigen Balken und den des laufenden Monats mit dem falschen Nullpunkt. Deshalb schreibt das Werkzeug die Basiswerte auch nach imp_day, imp_month, imp_year, exp_day, exp_month, exp_year und sml_da.
Vorher die tc_options.cfg des neuen Geräts ins Werkzeug laden (IP eintragen, der Download-Link erscheint). Die Datei enthält auch die Einstellungen aller anderen TinyC-Programme, und es werden nur diese sieben Schlüssel ersetzt. Hat das Gerät noch keine (File Not Found), einfach ohne weitermachen.
Optional. Only to check that the values landed where they should.Optional. Nur zum Nachsehen, ob die Werte richtig gelandet sind.
| Script | LinesZeilen | ColumnsSpalten | |
|---|---|---|---|
| For all of them the 4 h curve is zeroed — see What carries over.Bei allen wird die 4-h-Kurve genullt — siehe Was übernommen wird. | |||
1_SML_Chart.tas | 4 | 481 / 1441 / 31 / 12 | no feed-inohne Einspeisung |
2_SML_Chart_PV.tas, _PV_Modbus, 3_…_Bezugszaehler | 5 | 481 / 1441 / 31 / 31 / 24 | |
2_SML_Chart_PV2.tas | 5 | 721 / 1441 / 31 / 31 / 24 | 1 h curve at 5 s, zeroed like the 4 h one1-h-Verlauf à 5 s, wird genullt wie der 4-h-Verlauf |
2_SML_Chart_PV3.tas | 7 | … + 53 / 53 | weekly bars dropped — TinyC has noneWochenbalken entfallen — TinyC hat keine |
4_SML_Chart_PV_no_4h24h.tas | 3 | 31 / 31 / 24 | 4 h/24 h zeroed4 h/24 h werden genullt |
5_SteckdoseLeistungsmesser_1 / _2, 6_SML_Wasseruhr | 4 | 481 (or(bzw. 721) / 1441 / 31 / 12 | same shape, but no TinyC counterpartgleiche Form, aber kein TinyC-Gegenstück |
Not covered: 0_SML_Simple.tas has no charts.Nicht dabei: 0_SML_Simple.tas hat keine Diagramme.
The Scripter's mcon[24] is split: [1..12] consumption → sml_mcon, [13..24] feed-in → sml_mprod. That is why two files come out of one.Das mcon[24] des Scripters wird aufgeteilt: [1..12] Verbrauch → sml_mcon, [13..24] Einspeisung → sml_mprod. Deshalb entstehen aus einer Datei zwei.
tc_options.cfg always, plus the .bin file(s) if there are any. The existing tc_options.cfg is overwritten.If the slot is still running while you upload, saveVars() rewrites the .pvs before the .bin is read. The program imports the .bin once, writes it into the .pvs and then deletes it — the file being gone is the "already imported" marker. The log then says:
sml_chart: .bin carried baselines
sml_chart: imported .bin into .pvs, /sml_chart.bin deleted
tc_options.cfg immer, dazu die .bin-Datei(en), falls es welche gibt. Die vorhandene tc_options.cfg wird überschrieben.Läuft der Slot beim Hochladen noch, schreibt saveVars() die .pvs neu, bevor die .bin gelesen wird. Das Programm importiert die .bin einmal, schreibt sie in die .pvs und löscht sie danach — dass die Datei weg ist, ist die Markierung „schon importiert". Im Log steht dann:
sml_chart: .bin carried baselines
sml_chart: imported .bin into .pvs, /sml_chart.bin deleted
The bars for day and month, consumption and feed-in alike. They are indexed by day and month, so every row is a 1:1 copy (Scripter arrays are 1-based, TinyC puts day 1 at index 0 — that cancels out).
The 24 h curve, also exactly. The Scripter indexes it by minute of the day (s24h[0]=hours*60+mins) and so does TinyC (sml_s24h[hour*60+minute]), and the program recomputes the ring position from the clock on every tick.
The 4 h curve is not carried over — it is written as zeros. In the TinyC programs this is a short-term chart with a selectable range (15 min to 4 h, 180 or 240 slots of 5 to 60 s) and a free-running cursor. The Scripter's 480 values of 30 s cannot be placed in it at the right time; they would show up as a plausible-looking wrong chart. It fills up again within its range.
The baselines, provided the tc_options.cfg goes up as well — see step 3. Check afterwards: Import day on the main page has to match the old device.
wval / wval2 (weekly values from 2_SML_Chart_PV3) have no counterpart in sml_chart_common.tc and are dropped.
Die Balken für Tag und Monat, Verbrauch wie Einspeisung. Sie sind nach Tag bzw. Monat indiziert, deshalb ist jede Zeile eine 1:1-Kopie (Scripter-Arrays sind 1-basiert, TinyC legt Tag 1 auf Index 0 — das hebt sich auf).
Die 24-h-Kurve, ebenfalls exakt. Der Scripter indiziert sie nach Minute des Tages (s24h[0]=hours*60+mins), TinyC genauso (sml_s24h[hour*60+minute]), und das Programm setzt die Ringposition bei jedem Tick neu aus der Uhrzeit.
Die 4-h-Kurve wird nicht übernommen — sie wird genullt. In den TinyC-Programmen ist das ein Kurzzeit-Diagramm mit einstellbarem Zeitraum (15 min bis 4 h, 180 oder 240 Werte à 5 bis 60 s) und frei laufendem Zeiger. Die 480 Werte à 30 s des Scripters lassen sich darin nicht zeitrichtig einordnen und kämen als plausibel aussehendes, falsches Diagramm an. Es füllt sich innerhalb seines Zeitraums von selbst wieder.
Die Basiswerte, sofern die tc_options.cfg mit hochgeladen wird — siehe Schritt 3. Kontrolle danach: der Tagesverbrauch auf der Hauptseite muss zum alten Gerät passen.
wval / wval2 (Wochenwerte aus 2_SML_Chart_PV3) haben in sml_chart_common.tc kein Gegenstück und entfallen.