@@ -4150,33 +4150,32 @@ def get_html_plan_header(self, plan_debug):
4150
4150
html += "</tr>"
4151
4151
return html
4152
4152
4153
-
4154
4153
def publish_json_plan(self, pv_forecast_minute_step, pv_forecast_minute_step10, load_minutes_step, load_minutes_step10, end_record):
4155
4154
output = {}
4156
4155
4157
4156
plan_debug = self.get_arg("plan_debug")
4158
4157
"""
4159
4158
Publish the current plan in JSON format
4160
4159
"""
4161
- output[' plan_starts' ] = self.now_utc.strftime("%Y-%m-%d %H:%M")
4162
- output[' last_updated' ] = self.now_utc_real.strftime("%H:%M:%S")
4163
- output[' version' ] = THIS_VERSION
4164
- output[' config' ] = {}
4165
- output[' config'][' best_soc_min' ] = self.best_soc_min
4166
- output[' config'][' best_soc_max' ] = self.best_soc_max
4167
- output[' config'][' best_soc_keep' ] = self.best_soc_keep
4168
- output[' config'][' carbon_metric' ] = self.carbon_metric
4169
- output[' config'][' metric_self_sufficiency' ] = self.metric_self_sufficiency
4170
- output[' config'][' metric_battery_value_scaling' ] = self.metric_battery_value_scaling
4171
- output[' config'][' currency' ] = self.currency_symbols
4160
+ output[" plan_starts" ] = self.now_utc.strftime("%Y-%m-%d %H:%M")
4161
+ output[" last_updated" ] = self.now_utc_real.strftime("%H:%M:%S")
4162
+ output[" version" ] = THIS_VERSION
4163
+ output[" config" ] = {}
4164
+ output[" config"][" best_soc_min" ] = self.best_soc_min
4165
+ output[" config"][" best_soc_max" ] = self.best_soc_max
4166
+ output[" config"][" best_soc_keep" ] = self.best_soc_keep
4167
+ output[" config"][" carbon_metric" ] = self.carbon_metric
4168
+ output[" config"][" metric_self_sufficiency" ] = self.metric_self_sufficiency
4169
+ output[" config"][" metric_battery_value_scaling" ] = self.metric_battery_value_scaling
4170
+ output[" config"][" currency" ] = self.currency_symbols
4172
4171
4173
4172
minute_now_align = int(self.minutes_now / 30) * 30
4174
4173
end_plan = min(end_record, self.forecast_minutes) + minute_now_align
4175
4174
rowspan = 0
4176
4175
in_span = False
4177
4176
start_span = False
4178
4177
4179
- output[' slots' ] = []
4178
+ output[" slots" ] = []
4180
4179
4181
4180
for minute in range(minute_now_align, end_plan, 30):
4182
4181
slot = {}
@@ -4263,123 +4262,120 @@ def publish_json_plan(self, pv_forecast_minute_step, pv_forecast_minute_step10,
4263
4262
metric_end = self.predict_metric_best.get(minute_relative_slot_end, metric_start)
4264
4263
metric_change = metric_end - metric_start
4265
4264
4266
- slot['state'] = {}
4267
-
4268
- slot['state']['soc'] = {}
4269
- slot['state']['soc']['percent'] = soc_percent
4270
- slot['state']['soc']['percent_end'] = soc_percent_end
4271
- slot['state']['soc']['percent_end_window'] = soc_percent_end_window
4272
- slot['state']['soc']['percent_max'] = soc_percent_max
4273
- slot['state']['soc']['percent_min'] = soc_percent_min
4274
- slot['state']['soc']['percent_max_window'] = soc_percent_max_window
4275
- slot['state']['soc']['percent_min_window'] = soc_percent_min_window
4276
- slot['state']['soc']['change'] = self.dp2(soc_change)
4265
+ slot["state"] = {}
4277
4266
4267
+ slot["state"]["soc"] = {}
4268
+ slot["state"]["soc"]["percent"] = soc_percent
4269
+ slot["state"]["soc"]["percent_end"] = soc_percent_end
4270
+ slot["state"]["soc"]["percent_end_window"] = soc_percent_end_window
4271
+ slot["state"]["soc"]["percent_max"] = soc_percent_max
4272
+ slot["state"]["soc"]["percent_min"] = soc_percent_min
4273
+ slot["state"]["soc"]["percent_max_window"] = soc_percent_max_window
4274
+ slot["state"]["soc"]["percent_min_window"] = soc_percent_min_window
4275
+ slot["state"]["soc"]["change"] = self.dp2(soc_change)
4278
4276
4279
4277
if minute in self.manual_idle_times:
4280
- slot[' state'][' override' ] = True
4278
+ slot[" state"][" override" ] = True
4281
4279
4282
4280
split = False
4283
4281
4284
- slot['pv' ] = {}
4285
- slot['pv'][' forecast' ] = pv_forecast
4286
- slot['pv'][' forecast10' ] = pv_forecast10
4282
+ slot["pv" ] = {}
4283
+ slot["pv"][" forecast" ] = pv_forecast
4284
+ slot["pv"][" forecast10" ] = pv_forecast10
4287
4285
4288
4286
if plan_debug and pv_forecast10 > 0.0:
4289
- slot['pv'][' debug' ] = str(pv_forecast10)
4287
+ slot["pv"][" debug" ] = str(pv_forecast10)
4290
4288
4291
- slot[' load' ] = {}
4292
- slot[' load'][' forecast' ] = load_forecast
4293
- slot[' load'][' forecast10' ] = load_forecast10
4289
+ slot[" load" ] = {}
4290
+ slot[" load"][" forecast" ] = load_forecast
4291
+ slot[" load"][" forecast10" ] = load_forecast10
4294
4292
4295
4293
if plan_debug and load_forecast10 > 0.0:
4296
- slot[' load'][' debug' ] = str(load_forecast10)
4294
+ slot[" load"][" debug" ] = str(load_forecast10)
4297
4295
4298
4296
if charge_window_n >= 0:
4299
4297
limit = self.charge_limit_best[charge_window_n]
4300
4298
limit_percent = int(self.charge_limit_percent_best[charge_window_n])
4301
4299
if limit > 0.0:
4302
4300
if self.set_charge_freeze and (limit == self.reserve):
4303
- slot[' state'][' mode' ] = ' Freeze charge'
4301
+ slot[" state"][" mode" ] = " Freeze charge"
4304
4302
limit_percent = soc_percent
4305
4303
elif limit_percent == soc_percent_min_window:
4306
- slot[' state'][' mode' ] = ' Hold charge'
4304
+ slot[" state"][" mode" ] = " Hold charge"
4307
4305
elif limit_percent < soc_percent_min_window:
4308
- slot[' state'][' mode' ] = ' No charge'
4306
+ slot[" state"][" mode" ] = " No charge"
4309
4307
else:
4310
- slot[' state'][' mode' ] = ' Charge'
4308
+ slot[" state"][" mode" ] = " Charge"
4311
4309
4312
4310
if self.charge_window_best[charge_window_n]["start"] in self.manual_charge_times:
4313
- slot[' state'][' override' ] = True
4311
+ slot[" state"][" override" ] = True
4314
4312
elif self.charge_window_best[charge_window_n]["start"] in self.manual_freeze_charge_times:
4315
- slot[' state'][' override' ] = True
4313
+ slot[" state"][" override" ] = True
4316
4314
4317
- slot[' state'][' limit' ] = limit_percent
4315
+ slot[" state"][" limit" ] = limit_percent
4318
4316
else:
4319
4317
if discharge_window_n >= 0:
4320
4318
start = self.discharge_window_best[discharge_window_n]["start"]
4321
4319
if start > minute:
4322
4320
soc_change_this = self.predict_soc_best.get(max(start - self.minutes_now, 0), 0.0) - self.predict_soc_best.get(minute_relative_start, 0.0)
4323
- slot[' state'][' soc'][' change' ] = self.dp2(soc_change_this)
4321
+ slot[" state"][" soc"][" change" ] = self.dp2(soc_change_this)
4324
4322
4325
4323
if discharge_window_n >= 0:
4326
4324
limit = self.discharge_limits_best[discharge_window_n]
4327
4325
if limit == 99:
4328
4326
# TODO: figure out the split state logic, and how to reflect it here
4329
- slot[' state'][' mode' ] = ' Freeze discharge'
4330
- slot[' state'][' limit' ] = limit
4327
+ slot[" state"][" mode" ] = " Freeze discharge"
4328
+ slot[" state"][" limit" ] = limit
4331
4329
elif limit < 100:
4332
4330
# TODO: figure out the split state logic, and how to reflect it here
4333
4331
if limit > soc_percent_max_window:
4334
- slot[' state'][' mode' ] = ' Hold discharge'
4332
+ slot[" state"][" mode" ] = " Hold discharge"
4335
4333
else:
4336
- slot[' state'][' mode' ] = ' Discharge'
4337
- slot[' state'][' limit' ] = limit
4334
+ slot[" state"][" mode" ] = " Discharge"
4335
+ slot[" state"][" limit" ] = limit
4338
4336
4339
4337
if self.discharge_window_best[discharge_window_n]["start"] in self.manual_discharge_times:
4340
- slot[' state'][' override' ] = True
4338
+ slot[" state"][" override" ] = True
4341
4339
elif self.discharge_window_best[discharge_window_n]["start"] in self.manual_freeze_discharge_times:
4342
- slot['state']['override'] = True
4343
-
4340
+ slot["state"]["override"] = True
4344
4341
4345
- slot[' rate' ] = {}
4346
- slot[' rate'][' start' ] = rate_start.strftime("%a %H:%M")
4342
+ slot[" rate" ] = {}
4343
+ slot[" rate"][" start" ] = rate_start.strftime("%a %H:%M")
4347
4344
4348
4345
# Import and export rates -> to JSON
4349
- slot[' rate'][' import' ] = {}
4350
- slot[' rate'][' import'][' value' ] = rate_value_import
4351
- slot[' rate'][' import'][' adjust_type' ] = self.rate_import_replicated.get(minute, None)
4346
+ slot[" rate"][" import" ] = {}
4347
+ slot[" rate"][" import"][" value" ] = rate_value_import
4348
+ slot[" rate"][" import"][" adjust_type" ] = self.rate_import_replicated.get(minute, None)
4352
4349
4353
4350
if plan_debug:
4354
- slot[' rate'][' import'][' debug' ] = "%02.02f" % (rate_value_import / self.battery_loss / self.inverter_loss + self.metric_battery_cycle)
4351
+ slot[" rate"][" import"][" debug" ] = "%02.02f" % (rate_value_import / self.battery_loss / self.inverter_loss + self.metric_battery_cycle)
4355
4352
4356
4353
if charge_window_n >= 0:
4357
- slot[' rate'][' import'][' charge' ] = True
4354
+ slot[" rate"][" import"][" charge" ] = True
4358
4355
4359
- slot[' rate'][' export' ] = {}
4360
- slot[' rate'][' export'][' value' ] = rate_value_export
4361
- slot[' rate'][' export'][' adjust_type' ] = self.rate_export_replicated.get(minute, None)
4356
+ slot[" rate"][" export" ] = {}
4357
+ slot[" rate"][" export"][" value" ] = rate_value_export
4358
+ slot[" rate"][" export"][" adjust_type" ] = self.rate_export_replicated.get(minute, None)
4362
4359
4363
4360
if plan_debug:
4364
- slot[' rate'][' export'][' debug' ] = "%02.02f" % (rate_value_export * self.battery_loss_discharge * self.inverter_loss - self.metric_battery_cycle)
4361
+ slot[" rate"][" export"][" debug" ] = "%02.02f" % (rate_value_export * self.battery_loss_discharge * self.inverter_loss - self.metric_battery_cycle)
4365
4362
4366
4363
if discharge_window_n >= 0:
4367
- slot[' rate'][' export'][' discharge' ] = True
4364
+ slot[" rate"][" export"][" discharge" ] = True
4368
4365
4369
-
4370
- slot['cost'] = {}
4366
+ slot["cost"] = {}
4371
4367
4372
4368
# Total cost at start of slot, add leading minus if negative
4373
- slot[' cost'][' start' ] = metric_start
4374
- slot[' cost'][' change' ] = self.dp2(metric_change)
4369
+ slot[" cost"][" start" ] = metric_start
4370
+ slot[" cost"][" change" ] = self.dp2(metric_change)
4375
4371
4376
4372
# Car charging?
4377
- slot[' car' ] = {}
4373
+ slot[" car" ] = {}
4378
4374
if self.num_cars > 0:
4379
- slot[' car'][' charging_kwh' ] = self.car_charge_slot_kwh(minute_start, minute_end)
4375
+ slot[" car"][" charging_kwh" ] = self.car_charge_slot_kwh(minute_start, minute_end)
4380
4376
4381
4377
# iBoost
4382
- slot[' iboost' ] = {}
4378
+ slot[" iboost" ] = {}
4383
4379
if self.iboost_enable:
4384
4380
iboost_slot_end = minute_relative_slot_end
4385
4381
iboost_amount = self.predict_iboost_best.get(minute_relative_start, 0)
@@ -4394,40 +4390,38 @@ def publish_json_plan(self, pv_forecast_minute_step, pv_forecast_minute_step10,
4394
4390
)
4395
4391
else:
4396
4392
iboost_change = max(iboost_amount_end - iboost_amount, 0.0)
4397
- slot[' iboost'][' change' ] = iboost_change
4398
- slot[' iboost'][' amount' ] = iboost_amount
4399
- slot[' iboost'][' amount_end' ] = iboost_amount_end
4400
- slot[' iboost'][' amount_prev' ] = iboost_amount_prev
4393
+ slot[" iboost"][" change" ] = iboost_change
4394
+ slot[" iboost"][" amount" ] = iboost_amount
4395
+ slot[" iboost"][" amount_end" ] = iboost_amount_end
4396
+ slot[" iboost"][" amount_prev" ] = iboost_amount_prev
4401
4397
4402
- slot[' carbon' ] = {}
4398
+ slot[" carbon" ] = {}
4403
4399
if self.carbon_enable:
4404
4400
# Work out carbon intensity and carbon use
4405
- slot['carbon']['amount'] = self.predict_carbon_best.get(minute_relative_start, 0)
4406
- slot['carbon']['amount_end'] = self.predict_carbon_best.get(minute_relative_slot_end, 0)
4407
- slot['carbon']['change'] = self.dp2(carbon_amount_end - carbon_amount)
4408
- slot['carbon']['intensity'] = self.dp0(self.carbon_intensity.get(minute_relative_start, 0))
4409
-
4401
+ slot["carbon"]["amount"] = self.predict_carbon_best.get(minute_relative_start, 0)
4402
+ slot["carbon"]["amount_end"] = self.predict_carbon_best.get(minute_relative_slot_end, 0)
4403
+ slot["carbon"]["change"] = self.dp2(carbon_amount_end - carbon_amount)
4404
+ slot["carbon"]["intensity"] = self.dp0(self.carbon_intensity.get(minute_relative_start, 0))
4410
4405
4411
4406
if start_span:
4412
- slot[' span' ] = ' start'
4407
+ slot[" span" ] = " start"
4413
4408
elif in_span:
4414
- slot[' span' ] = ' in_span'
4409
+ slot[" span" ] = " in_span"
4415
4410
elif not in_span:
4416
- slot[' span' ] = ' not in_span'
4411
+ slot[" span" ] = " not in_span"
4417
4412
else:
4418
- slot[' span' ] = ' unknown'
4413
+ slot[" span" ] = " unknown"
4419
4414
4420
- output[' slots' ].append(slot)
4415
+ output[" slots" ].append(slot)
4421
4416
4422
- #output['raw'] = {}
4423
- #output['raw']['pv_forecast_minute_step'] = pv_forecast_minute_step
4424
- #output['raw']['pv_forecast_minute_step10'] = pv_forecast_minute_step10
4425
- #output['raw']['load_minutes_step'] = load_minutes_step
4426
- #output['raw']['load_minutes_step10'] = load_minutes_step10
4417
+ # output['raw'] = {}
4418
+ # output['raw']['pv_forecast_minute_step'] = pv_forecast_minute_step
4419
+ # output['raw']['pv_forecast_minute_step10'] = pv_forecast_minute_step10
4420
+ # output['raw']['load_minutes_step'] = load_minutes_step
4421
+ # output['raw']['load_minutes_step10'] = load_minutes_step10
4427
4422
4428
4423
self.dashboard_item(self.prefix + ".plan_json", state="", attributes={"json": json.dumps(output), "friendly_name": "Plan in JSON", "icon": "mdi:web-box"})
4429
4424
4430
-
4431
4425
def publish_html_plan(self, pv_forecast_minute_step, pv_forecast_minute_step10, load_minutes_step, load_minutes_step10, end_record):
4432
4426
"""
4433
4427
Publish the current plan in HTML format
0 commit comments