-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fast relay switching based on power increase #21
Comments
Hi,
you get the power in the >T section. this is normally sampled on teleperiod time only at max every 10 seconds.
you can verify that by printing a time stamp in the >T section
e.g. print tele var at %upsecs%
i dont know the internals of the gosund driver and how we could get a faster access to the power register.
as far as i know there is a tasmota cmd to set limits also.
you might set such a limit and receive the alarm in the >E section
this approach may be faster
… Am 21.05.2020 um 10:09 schrieb tobetobe66 ***@***.***>:
Hi Gemu,
thanks a lot for the beautiful scripting feature.
I am using a Gosund SP1, GPIO4: 134, GPIO5: 132, GPIO12: 131, GPIO14: 21.
I am monitoring power and switch off the relay as soon as power is over 1 Watt using the following code:
T
_pow=ENERGY#Power
F
.
.
.
if ((_pow>1) and (_s==S)) {
->power1 0
e_eP=1
}
This works perfectly fine, however it takes sometimes way above 1 second for the relay to switch off. This is a bit too slow for me. The load is 800W, power rise should be instant.
Is there a way to do this faster? Maybe it's not possible at all, because sampling rate of power measurement is too slow.
I would be grateful for some ideas.
Thank you very much.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub <#21>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ACY3QY4FU2EXRLCW2FNUSH3RSTOSPANCNFSM4NGUNWAA>.
|
Thank you. |
OK, I found some cmds that might be of help. Have to do a bit of reading and testing. Will report back once done. |
because if found this an interesting application i implemented direct access to some energy registers which are updated instantly. try my new version! enrg[0] = should be total energy |
you need to define |
updated again after testing with my MODBus device for a single phase meter only p1 values should be > 0 |
OK, what I tried so far is using cmd powerdelta and cmd powerhigh.
_pow is still in T-Section. The result is comparable to what I had before doing polling in the F-Section. My application is a network of Gosunds to do load managment of the devices attatched to them. I need this. because I am partly OFFGRID and my inverter is limited in power. Therefor I have to detect if a device attached to a Gosund is switched on by the user. This has to be done in a very short time, as the inverter can take some overload for a short amount of time. |
Thank you for the energy registers. I will give it a try and report. |
you may also speed up relay switching by directly setting the relay GPIO by spin(x 1) |
I already compared spin vs ->power, there is not much difference. However I still had relay 1 defined, because otherwise power measurement didn't work. Just found out today that there is a switch to enable power measurement when power is off. Might give that a try later and compare spin vs ->power again, however I do not expect any speedup. Just compiled your version, will check energy registers now. |
Hi Gemu, holy cow, it works!! It is fast and reliable with respect to switching time.
In the above example I used current instead of power, however that does not make a difference. Thank you so much. I have another issue which is not bothering me anymore because I found a work around. Anyway, I noticed a strange behavior using the short form of if, then, else, i.e. if {} else {}. Once enclosed in a subroutine it was gone. I will do some further testing with respect to this and maybe come back to you. Best regards |
glad that it worked!
if script size is important, use the new compress option!
#define USE_SCRIPT_COMPRESSION
(script is deleted after 1. install, so have a copy)
gives you about 50% more space
i do frequent prs every 2 or 3 days, until then use my fork
… Am 21.05.2020 um 16:57 schrieb tobetobe66 ***@***.***>:
Hi Gemu,
holy cow, it works!! It is fast and reliable with respect to switching time.
I am way below 1 second all the time.
T
;_pow=ENERGY#Power
F
if ((enrg[4]>0.01) and (_s==S)) {
;->power1 0
spin(14 0)
e_eP=1
}
In the above example I used current instead of power, however that does not make a difference.
Using the registers I can skip the T-Section, saving script space, which is prime to me. Will you include the registers feature in a PR? That would be very helpful.
Thank you so much.
I have another issue which is not bothering me anymore because I found a work around. Anyway, I noticed a strange behavior using the short form of if, then, else, i.e. if {} else {}. Once enclosed in a subroutine it was gone. I will do some further testing with respect to this and maybe come back to you.
Best regards
Tobi
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <#21 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ACY3QY6Y54Z7R2AUCIAZTJLRSU6N5ANCNFSM4NGUNWAA>.
|
I read about rule buffer being compressed. Was hoping for that to happen for scripting also. Great. |
leave open, better to find for others |
Hi Gemu, Just noticed that every time I access a register a mqtt message is sent: tele/DVES_XXXXX/SENSOR = {"Time":"2020-05-22T17:34:38","ENERGY":{"TotalStartTime":"2019-04-07T18:00:28","Total":0.085,"Yesterday":0.003,"Today":0.042,"Power":0,"ApparentPower":0,"ReactivePower":0,"Factor":0.00,"Voltage":238,"Current":0.000}} Is there a way to switch this off as it is causing a lot of traffic? Am I missing a Tasmota switch to turn it off? Thanks. |
Hi tobi, this is a tele message that should be generated every teleperiod seconds. Greets Gerhard |
Hmmm, strange. |
OK, got it. Running three Gosunds in parallel, one had teleperiod on 300. thats the one I checked. |
Hi Gemu, is it possible to change the last will and testament to a different topic from within the script? Thanks a lot |
Hi Tobi
i have not much knowledge about this MQTT stuff. scripter may only manipulate those settings via tasmota cmds.
if there is no Tasmota cmd for changing these items you might make a feature request to Tasmota dev.
Greets Gerhard
… Am 23.05.2020 um 09:59 schrieb tobetobe66 ***@***.***>:
Hi Gemu,
is it possible to change the last will and testament to a different topic from within the script?
The standard seems to be: tele/DVES_XXXXXXX/LWT.
I would like to change it for example to: abc/LWT.
Thanks a lot
Tobi
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <#21 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ACY3QY4H5SGARN535CZQQGDRS565TANCNFSM4NGUNWAA>.
|
OK. |
Hi Gerhard, the following script gives me a hard time:
print end It seems like the break terminates the whole B section, as I get the following output: and nothing else. Thx |
Hi Tobi, This was a bug! Gerhard |
Thanks Gerhard. Tobi |
Hello Gerhard, see below the result of a fast polling of enrg7 and enrg3 on my gosunds after switching off. Tobi 08:25:26 P: 0.00 I: 0.00 |
Hi Tobi
i get the values from the energy driver, do not know how this is wired with your device
may be another register would be better, there a plenty of them, see below
could it be that your devices resolution is only 13.8 Watts?
then 1 bit noise could produce this result
Gerhard
scripter =>
switch ((uint32_t)fvar) {
case 0:
fvar=Energy.total;
break;
case 1:
fvar=Energy.voltage[0];
break;
case 2:
fvar=Energy.voltage[1];
break;
case 3:
fvar=Energy.voltage[2];
break;
case 4:
fvar=Energy.current[0];
break;
case 5:
fvar=Energy.current[1];
break;
case 6:
fvar=Energy.current[2];
break;
case 7:
fvar=Energy.active_power[0];
break;
case 8:
fvar=Energy.active_power[1];
break;
case 9:
fvar=Energy.active_power[2];
break;
=> energy driver struct
struct ENERGY {
float voltage[3] = { 0, 0, 0 }; // 123.1 V
float current[3] = { 0, 0, 0 }; // 123.123 A
float active_power[3] = { 0, 0, 0 }; // 123.1 W
float apparent_power[3] = { NAN, NAN, NAN }; // 123.1 VA
float reactive_power[3] = { NAN, NAN, NAN }; // 123.1 VAr
float power_factor[3] = { NAN, NAN, NAN }; // 0.12
float frequency[3] = { NAN, NAN, NAN }; // 123.1 Hz
// float import_active[3] = { NAN, NAN, NAN }; // 123.123 kWh
float export_active[3] = { NAN, NAN, NAN }; // 123.123 kWh
float start_energy = 0; // 12345.12345 kWh total previous
float daily = 0; // 123.123 kWh
float total = 0; // 12345.12345 kWh total energy
unsigned long kWhtoday_delta = 0; // 1212312345 Wh 10^-5 (deca micro Watt hours) - Overflows to Energy.kWhtoday (HLW and CSE only)
unsigned long kWhtoday_offset = 0; // 12312312 Wh * 10^-2 (deca milli Watt hours) - 5764 = 0.05764 kWh = 0.058 kWh = Energy.daily
unsigned long kWhtoday; // 12312312 Wh * 10^-2 (deca milli Watt hours) - 5764 = 0.05764 kWh = 0.058 kWh = Energy.daily
unsigned long period = 0; // 12312312 Wh * 10^-2 (deca milli Watt hours) - 5764 = 0.05764 kWh = 0.058 kWh = Energy.daily
uint8_t fifth_second = 0;
uint8_t command_code = 0;
uint8_t data_valid[3] = { 0, 0, 0 };
uint8_t phase_count = 1; // Number of phases active
bool voltage_common = false; // Use single voltage
bool frequency_common = false; // Use single frequency
bool kWhtoday_offset_init = false;
bool voltage_available = true; // Enable if voltage is measured
bool current_available = true; // Enable if current is measured
bool type_dc = false;
bool power_on = true;
#ifdef USE_ENERGY_MARGIN_DETECTION
uint16_t power_history[3] = { 0 };
uint8_t power_steady_counter = 8; // Allow for power on stabilization
bool power_delta = false;
bool min_power_flag = false;
bool max_power_flag = false;
bool min_voltage_flag = false;
bool max_voltage_flag = false;
bool min_current_flag = false;
bool max_current_flag = false;
#ifdef USE_ENERGY_POWER_LIMIT
uint16_t mplh_counter = 0;
uint16_t mplw_counter = 0;
uint8_t mplr_counter = 0;
uint8_t max_energy_state = 0;
#endif // USE_ENERGY_POWER_LIMIT
#endif // USE_ENERGY_MARGIN_DETECTION
} Energy;
… Am 25.05.2020 um 09:46 schrieb tobetobe66 ***@***.***>:
Hello Gerhard,
see below the result of a fast polling of enrg7 and enrg3 on my gosunds after switching off.
Power (left column) still gives values long after switch off and is oscillating, whereas current is zero as it should be. As I use current it does not bother me, however the behaviour of enrg7 seems strange.
Tobi
08:25:26 P: 0.00 I: 0.00
08:25:26 P: 13.80 I: 0.00
08:25:26 P: 13.80 I: 0.00
08:25:26 P: 13.80 I: 0.00
08:25:26 P: 13.80 I: 0.00
08:25:26 P: 13.80 I: 0.00
08:25:26 P: 0.00 I: 0.00
08:25:27 P: 13.80 I: 0.00
08:25:27 P: 13.80 I: 0.00
08:25:27 P: 13.80 I: 0.00
08:25:27 P: 13.80 I: 0.00
08:25:27 P: 13.80 I: 0.00
08:25:27 P: 0.00 I: 0.00
08:25:27 P: 13.80 I: 0.00
08:25:27 P: 13.80 I: 0.00
08:25:27 P: 13.80 I: 0.00
08:25:27 P: 13.80 I: 0.00
08:25:28 P: 13.80 I: 0.00
08:25:28 P: 0.00 I: 0.00
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <#21 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ACY3QYZADPOWVCR3P2OVOULRTIO33ANCNFSM4NGUNWAA>.
|
Energy resolution is far better than 13.8Watts. I don't think its because of noise. Was just wondering about the readings of the power register. It reads 13.8W long after the device is switched off and also when current is already 0 for some time. |
Dear Gerhard, the docu states: Does this NOT mixing refer to the whole script or just to not nesting both formats? Thx |
Hi Tobi,
just messing in one condition is not supported.
Gerhard
… Am 26.05.2020 um 15:38 schrieb tobetobe66 ***@***.***>:
Dear Gerhard,
the docu states:
There are two syntax alternatives for conditional statements (if, then, else or if {} else {}). You may NOT mix both formats.
Does this NOT mixing refer to the whole script or just to not nesting both formats?
Thx
Tobi
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <#21 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ACY3QY6MQ7QT4MDPGVVRFWLRTPA55ANCNFSM4NGUNWAA>.
|
Hi Gerhard, I have a strange behavior in the following code if I change the highlighted section from if then to if{}. The function FSM is called from the F Section. If I use {} the part with seems to be skipped. I.E. in the print statement e_Mr is 1 instead of zero. Thx Tobi #FSM case N case O print clear events print EOF FSM: sc:%sc% State:%_s% e_eP: %e_eP%, e_Te: %e_Te% e_Mr: %e_Mr% |
Ok, mache ich gleich. Nur fürs Protokoll:
dann |
z.B. >B >S print %res% |
so noch ne kleine Änderung >B >S print %res% wenn man 128 auf die Pin Nummer draufzählt |
va bene, gerade am testen. |
Läuft so wie es aussieht. Danke. Das ist der Output bei in S-Section flippendem GPIO5. Passt also. Getestet mit res=mpt(128+4) |
Die Möglichkeit, im Script zwischen den Messarten mit res=mpt(128+4) oder res=mpt(4) umzuschalten, ist grossartig. |
Morgen Tobi, so habe mal drüber geschlafen und weiter verbessert. mpt(x) definiert den Pin mpt(-1) liest die high low Zeit und weil diese Funktion sicher selten gebraucht wird und kostbaren IRAM verbraucht habe ich sie optional gemacht mit anderen seltenen Funktionen Grüße Gerhard |
Moin Gerhard, Perfekt. Die Erkennung des Sync hätte auch so funktioniert, aber so ist es viel besser. Vielen Dank. |
Hab jetzt noch was ganz verwegenes eingebaut. |
Das ist ja ein Träumchen. Danke |
ja den kann man auch setzen! |
ja das mit der >I section war leider ein Irrtum. Da der Interrupt auch während eines Flash update passieren kann darf man von dort keine Flash Programme aufrufen. |
Schade, das wäre der Knaller gewesen. |
Morgen Gerhard, so habe jetzt einen alten Funkwecker zerlegt und versucht das DCF-Signal zu verwenden. Hat leider nicht lange funktioniert:-). Danach noch einen zerlegt, den kann ich jetzt zum Testen verwenden. Liefert auch schöne 100ms und 200ms Pulse am Oszi. Mit deiner letzten Version liefert folgendes Skript:
Den folgenden Output: 06:40:57 897.00 Man erkennt sehr schön den langen Sync-Puls.
Eigentlich müsste ich doch bei Aufruf von -1, nur jeweils einen Wert (100 oder 200) bekommen und bei Aufruf von -2 jeweils auch nur einen Wert (800, 900, 1800, 1900) oder? Danke |
Moin Tobi,
Sehr merkwürdig,
die Werte sollten doch 100,200 oder 800,900 liefern.
DCF ist doch alle Sekunde ein Impuls ?
Finde auf Anhieb keinen Fehler in meinem Kode. Glitches ?
Werde jetzt mal einen Testaufbau machen und Signale vom Funktionsgenerator einspeisen.
Melde mich dann wieder
Grüße
Gerhard
PS spinm() brauchst du nicht, macht schon mpt()
… Am 05.06.2020 um 07:48 schrieb tobetobe66 ***@***.***>:
Morgen Gerhard,
so habe jetzt einen alten Funkwecker zerlegt und versucht das DCF-Signal zu verwenden. Hat leider nicht lange funktioniert:-). Danach noch einen zerlegt, den kann ich jetzt zum Testen verwenden. Liefert auch schöne 100ms und 200ms Pulse am Oszi.
Mit deiner letzten Version liefert folgendes Skript:
D
res=0
B
; definiere GPIO 4 als Pulse Timer
res=mpt(4)
spinm(4 0)
F
res=mpt(-2)
print %res%
Den folgenden Output:
06:40:57 897.00
06:40:57 0.00
06:40:57 1099.00
06:40:57 0.00
06:40:57 0.00
06:40:57 0.00
06:40:57 0.00
06:40:58 0.00
06:40:58 0.00
06:40:58 0.00
06:40:58 0.00
06:40:58 0.00
06:40:58 0.00
06:40:58 0.00
06:40:58 0.00
06:40:58 0.00
06:40:58 0.00
06:40:59 0.00
06:40:59 0.00
06:40:59 0.00
06:40:59 1798.00
06:40:59 1900.00
06:40:59 0.00
06:40:59 0.00
06:40:59 0.00
06:40:59 0.00
06:40:59 0.00
06:41:00 0.00
06:41:00 0.00
06:41:00 0.00
06:41:00 898.00
06:41:00 0.00
06:41:00 1100.00
06:41:00 0.00
06:41:00 0.00
06:41:00 0.00
06:41:00 0.00
06:41:01 0.00
06:41:01 0.00
06:41:01 0.00
06:41:01 796.00
06:41:01 894.00
06:41:01 0.00
06:41:01 0.00
06:41:01 0.00
06:41:01 0.00
06:41:01 0.00
06:41:02 0.00
06:41:02 0.00
06:41:02 0.00
06:41:02 902.00
06:41:02 0.00
06:41:02 1105.00
Man erkennt sehr schön den langen Sync-Puls.
Auffällig ist:
Es werden immer 2 Werte geliefert
ein Aufruf von res=mpt(-1) anstatt -2 liefert immer 0
Eigentlich müsste ich doch bei Aufruf von -1, nur jeweils einen Wert (100 oder 200) bekommen und bei Aufruf von -2 jeweils auch nur einen Wert (800, 900, 1800, 1900) oder?
Danke
Grüsse
Tobi
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <#21 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ACY3QY6GLAXSYRGLS3UTERLRVCBLZANCNFSM4NGUNWAA>.
|
Hab das mal jetzt aufgebaut und erst mal mit einem Taster ausprobiert. Die Ergebnisse sind plausibel. |
so, habe jetzt mit Funktionsgenerator getestet und alles funktioniert wie es soll. |
Ich teste |
Hallo Gerhard, bei mir läuft jetzt auch alles wie es soll. |
Ich vergass, Abhilfe schufen 2 Widerstände und ein NPN Transistor. |
Hi Tobi, Habe Mac und PC version Gruß Gerhard |
Hallo Gerhard, natürlich helfe ich beim Testen. Ist doch klar. Bezüglich DCF77: Ist aufwändiger als gedacht. Eigentlich einfach, Problem ist aber tatsächlich die Synchronisation. Da ich in der F-Section arbeiten muss, kann es vorkommen, dass aufgrund unterschiedlicher Laufzeiten der Section sich das Sampling-Fenster verschiebt. Kann gerade nicht mehr weitertesten, da mein Testrechner belegt ist. Sind aber bisher alles nur Vermutungen. Die I-Section wäre extrem hilfreich gewesen. Ein Interrupt der im Script zugänglich ist, wäre der Knaller gewesen. Gruss Tobi |
Moin Tobi https://www.dropbox.com/s/pj44bmxzkipebzd/uVariotest.zip?dl=0 Die scripts müssen .txt suffix haben und in der ersten Zeile muss >D stehen, dann erkennt er die Datei als Tasmota script. Du kannst jetzt beliebig kommentieren und einrücken. in irgend einer Zeile muss IP=xxx.xxx.xxx.xxx Jetzt CMD R oder im Menu run eingeben und das script wird gesendet und sofort gestartet. Viel Spass damit Gerhard |
War gerade am ausprobieren. Gruss |
Moin Gerhard. Ich versuche dir schon seit Tagen auf deine Nachricht zu Antworten. Allerdings zickt das Forum wieder. Gibt es in GH eigentlich eine PN Funktion?
Oh und wie verhält es sich mit dem Kompressionsfaktor, wenn man beim Kompilieren Viele Grüße |
Nur fürs Protokoll: Ich habe nicht viel gemacht :-) |
Hi Gemu,
thanks a lot for the beautiful scripting feature.
I am using a Gosund SP1, GPIO4: 134, GPIO5: 132, GPIO12: 131, GPIO14: 21.
I am monitoring power and switch off the relay as soon as power is over 1 Watt using the following code:
This works perfectly fine, however it takes sometimes way above 1 second for the relay to switch off. This is a bit too slow for me. The load is 800W, power rise should be instant.
Is there a way to do this faster? Maybe it's not possible at all, because sampling rate of power measurement is too slow.
I would be grateful for some ideas.
Thank you very much.
The text was updated successfully, but these errors were encountered: