In my TOU R script posted here:
I decided to do the TOU cost calculations for all devices on an hourly basis, but then separate out by device Name, as well as BillingMonth and TOU Period when it comes time to aggregate.
# Aggregate data by billing month
SenseBill <- aggregate(cbind(kWh, Cost) ~ BillMonth + BillTo + Name + TOUPeriod, data=SenseDaily, FUN=sum)
When it came to aggregating kWh to do the Tiering calculation, I used:
data = SenseBill[SenseBill$Name %in% Totals,] where Totals is c(“Total Usage”, “Solar Production”).
to filter out just the mains and solar, in this step:
# Aggregate all Total Usage and Solar Production regardless of TOU to get monthly usage for tiered costing
NetBillkWh <- aggregate(kWh ~ BillMonth + BillTo, data = SenseBill[SenseBill$Name %in% Totals,], FUN=sum )
I should also note that with PG&E, Tiered pricing and TOU pricing are mutually exclusive. Tiered pricing is the default, but typically more expensive for big users of electricity (folks with EVs and AC).