OpenBK7231T_App icon indicating copy to clipboard operation
OpenBK7231T_App copied to clipboard

Allow SetupEnergyStats for non BL / Tuya power meters

Open analystcmyk opened this issue 2 years ago • 3 comments

The power statistics command (SetupEnergyStats) is a great tool, but unfortunately hardcoded to be used only for power measured using the BL driver.

definition

Suggestion : allow statistics to be collected for other type of meters, eg Tuya powermeters.

My autoexec.bat ( using EARU EAMPDW-TY-63 ) :

startdriver SSDP
startDriver TuyaMCU
startDriver NTP
tuyaMcu_defWiFiState 4
setChannelType 1 toggle
linkTuyaMCUOutputToChannel 16 1 1
setChannelType 2 Voltage_div10
setChannelType 3 Power
setChannelType 4 Current_div1000
setChannelType 5 EnergyTotal_kWh_div100
linkTuyaMCUOutputToChannel 1 0 5
linkTuyaMCUOutputToChannel 6 RAW_TAC2121C_VCP
linkTuyaMCUOutputToChannel 15 1 7
ntp_timeZoneOfs 2:00

Thank you for considering.

analystcmyk avatar Nov 06 '23 17:11 analystcmyk

Maybe overstretching and out of scope here, but possibly this would not be strictly to be limited to power.

Any value could be "statted" using the sample period , but it would mean having to calculate and store min/max/avg per sample period, while currently we only hold the total per sample period.

Example : Value = Temperature , Sample time = 5 seconds, Sample count = 2

image

analystcmyk avatar Nov 09 '23 07:11 analystcmyk

Any plans for moving the stats out of the BLE code? Even just a daily diff like https://github.com/openshwprojects/OpenBK7231T_App/blob/c07f66f3818c7067e60acbf27cb1a5d86f77e692/src/driver/drv_bl_shared.c#L187 would be nice (instead of the full fledged configurable powermeter)

Maybe a script can do the same thing, ill try that as well.

analystcmyk avatar Mar 26 '24 10:03 analystcmyk

Show energy usage of last hour:

  • global total is CH5
  • create intermediate counter CH10
  • create intermediate counter to store usage of last hour CH11
  • every 3600 seconds, store global total (CH5) in CH10
  • if CH5 changes, calculate the difference between CH5 and CH10, and store in CH11

Of course this is not a real running hourly total, as it will reset to zero every hour. A moving window would be better, sharing here anyway.

// measure 1 hr usage, $CH5 holds total kWh

// store the last measured value
setChannelType 10 EnergyTotal_kWh_div100
setChannelLabel 10 EnergyTotal_1hr

// set to total when booting 
// check if you need a wait time, some tuya's do not have this value yet when booting
setChannel 10 $CH5;

// channel to hold the usage of last hour
setChannelType 11 EnergyTotal_kWh_div100
setChannelLabel 11 EnergyUse_1hr

// every hour, reset the counter
addRepeatingEventID 3600 -1 111 measure1hr

// and keep updating the hour totals when the energytotal changes 
addEventHandler OnChannelChange 5 measure1hr_update

alias measure1hr backlog setChannel 11 $CH5-$CH10; publishChannel 10; setChannel 10 $CH5;
alias measure1h_rupdate backlog setChannel 11 $CH5-$CH10; publishChannel  11;

analystcmyk avatar Mar 27 '24 13:03 analystcmyk