-
For some reason, I can't copy message links from Discord, so to summarize what leads me to opening this discussion... I am trying to use wattage changes as automation triggers. My goal is to flip a dumb switch on a device plugged into a sonoff and make other things happen. I have tried both PowerDelta and a combination of PowerLow/PowerHigh rules, but there's a delay of around 2 seconds regardless of the method for detecting the wattage change. I have a Sonoff S31 15A. [For further background, I have also tried a Currant brand outlet and I could set the same threshold on it and it detected the wattage change with almost no delay. The only problem with that was they didn't have a means of getting the triggers into Node RED.] So I've been studying the code to see if I can tweak anything to make detection of wattage changes closer to real-time (both via PowerDelta and low/high rules thresholds - which, BTW appear to be only negligibly different), ideally a fraction of a second. I found where Energy.active_power is calculated and set and the code looks like it should report power changes within 1 second. My initial hunch was that Energy.power_history might have been mis-handled (since my observation: https://drive.google.com/open?id=1_C4OFqSyKh6MxeL2yJqyaPd11vWmHUYI was that changes were detected in about 2 seconds and power_history contains readings from 2 seconds before "now" [note, I move the mouse when I flip the switch in the above video: up=on, down=off])... but it all looks right. My other hunch is that the power readings are averaged over a window, sampled once a second, thus causing an immediate change to be caught on a delay (>1s). My oberservations in the web GUI support this. When I flip the switch, it goes from 1W to 6W (1s later), then to the target 11W (1s after that). I have a question. Power readings are obtained from the sensor and active_power is calculated in a loop here: Tasmota/tasmota/xnrg_02_cse7766.ino Line 145 in dcbb3f1 It must be those values that possibly have the windowed-average I'm hoping to find. However, I can't determine how frequently that while loop cycles. Is it potentially looping faster than once a second and is that looping independently of the loop that checks the margins: Line 379 in 628f17d I guess even if that loop runs once a second, it's the sender that would be implementing the windowed average. Otherwise, the while loop would catch the change immediately... I guess I'm just thinking out loud here. Oh, BTW, the link to the PDF in the comments is stale: Tasmota/tasmota/xnrg_02_cse7766.ino Line 28 in dcbb3f1 I found the doc here: |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 12 replies
-
You might want to back up and explain more about why you are choosing this method. What are you really trying to do? When you put power measuring circuitry in between, you get the delay of measuring power accurately (averaging is usually involved), and the delay of reporting, which is not instant. Looking at the code:
Later it has this:
That says to me that, at best you are going to get a few samples per second for normal values of power. I am not really sure the order of the two modules (Energy (xdrv03) and CSE7766 (xnrg_02)). But, there is a lot of code there. It is NOT designed to be used for things that need to have a near instant response (as you have discovered, it can take some seconds for the action to occur). The WebUI updates 1/sec. When there is 0/low power utilization the CSE7766 takes more than a second to calculate it. So, when the power changes it will take it some time to figure this out. Power measurement takes time, you probably won't be able to make it work much faster. If you need real time support, use an actual switch input. |
Beta Was this translation helpful? Give feedback.
-
If you want to see quick response from a power switch flick you should start reading the response from the power management chip. In the case of your S31 enable |
Beta Was this translation helpful? Give feedback.
If you want to see quick response from a power switch flick you should start reading the response from the power management chip.
In the case of your S31 enable
weblog 4
and study the data received from the chip. In there you would like to see rapid changes if you flick the switch. If no rapid changes are reported all other software changes are useless.