Hi
I’m trying to setup a KWh total for the last 7 days but I’m struggling to find the necessary code that needs modifying, Ive created the following code in process_processlist.php.
// Power to KWh Week (Last 7 Days)
public function power_to_kwhw($feedid, $time_now, $value)
{
$new_kwh = 0;
// Get last value
$last = $this->feed->get_timevalue($feedid);
if (!isset($last['value'])) $last['value'] = 0;
if (!isset($last['time'])) $last['time'] = $time_now;
$last_kwh = $last['value']*1;
$last_time = $last['time']*1;
$current_slot = $this->getstartday($time_now);
$last_slot = $this->getstartday($last_time);
$time_elapsed = ($time_now - $last_time);
if ($time_elapsed>0 && $time_elapsed<7200) { // 2hrs
// kWh calculation
$kwh_inc = ($time_elapsed * $value) / 3600000.0;
} else {
// in the event that redis is flushed the last time will
// likely be > 7200s ago and so kwh inc is not calculated
// rather than enter 0 we dont increase it
$kwh_inc = 0;
}
if($last_slot == $current_slot) {
$new_kwh = $last_kwh + $kwh_inc;
} else {
# We are working in a new slot (new day) so don't increment it with the data from yesterday
$new_kwh = $kwh_inc;
}
$this->log->info("power_to_kwhd() feedid=$feedid last_kwh=$last_kwh kwh_inc=$kwh_inc new_kwh=$new_kwh last_slot=$last_slot current_slot=$current_slot");
$this->feed->update_data($feedid, $time_now, $current_slot, $new_kwh);
return $value;
}
For the life of me I cant find the part of the script that resets at midnight.
Also
How easy would it be to have a reset button on the dashboard?
Regards
Dave