Skip to content

Commit

Permalink
Backend optimisation works with dynamo data
Browse files Browse the repository at this point in the history
  • Loading branch information
Big-Tree committed Feb 13, 2024
1 parent 45ea051 commit 9e91f63
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
10 changes: 6 additions & 4 deletions custom_components/optispark/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,25 @@

NAME = "Optispark"
DOMAIN = "optispark"
VERSION = "0.1.7"
VERSION = "0.1.8"
ATTRIBUTION = "Data provided by http://jsonplaceholder.typicode.com/"

LAMBDA_TEMP = 'temps'
LAMBDA_TEMP_CONTROLS = 'temps'
LAMBDA_PRICE = 'prices'
LAMBDA_OPTIMISED_DEMAND = 'optimised_demand'
LAMBDA_BASE_DEMAND = 'base_demand'
LAMBDA_BASE_COST = 'base_cost'
LAMBDA_OPTIMISED_COST = 'optimised_cost'
LAMBDA_PROJECTED_PERCENT_SAVINGS = 'projected_percent_savings'
# Lambda parameters
LAMBDA_SET_POINT = 'set_point'
LAMBDA_SET_POINT = 'temp_set_point'
LAMBDA_TEMP_RANGE = 'temp_range'
LAMBDA_POSTCODE = 'postcode'
LAMBDA_HOUSE_CONFIG = 'house_config'
LAMBDA_USER_HASH = 'user_hash'
LAMBDA_INITIAL_INTERNAL_TEMP = 'initial_internal_temp'

HISTORY_DAYS = 3 # the number of days initially required by our algorithm
HISTORY_DAYS = 28 # the number of days initially required by our algorithm
DYNAMO_HISTORY_DAYS = 365*5
MAX_UPLOAD_HISTORY_READINGS = 5000
DATABASE_COLUMN_SENSOR_HEAT_PUMP_POWER = 'heat_pump_power'
Expand Down
20 changes: 14 additions & 6 deletions custom_components/optispark/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ def __init__(
self._switch_enabled = False # The switch will set this at startup
self._available = False
self._lambda_args = {
const.LAMBDA_HOUSE_CONFIG: None,
const.LAMBDA_SET_POINT: 20.0,
const.LAMBDA_TEMP_RANGE: 3.0,
const.LAMBDA_POSTCODE: self.postcode}
const.LAMBDA_TEMP_RANGE: 2.0,
const.LAMBDA_POSTCODE: self.postcode,
const.LAMBDA_USER_HASH: user_hash,
const.LAMBDA_INITIAL_INTERNAL_TEMP: None # <-- This will be set to current temp
}
self._lambda_update_handler = LambdaUpdateHandler(
hass=self.hass,
client=self.client,
Expand Down Expand Up @@ -124,7 +126,7 @@ def convert_climate_from_celcius(self, entity, temp):

async def update_heat_pump_temperature(self, data):
"""Set the temperature of the heat pump using the value from lambda."""
temp: float = data[const.LAMBDA_TEMP]
temp: float = data[const.LAMBDA_TEMP_CONTROLS]
climate_entity = get_entity(self.hass, self._climate_entity_id)

try:
Expand Down Expand Up @@ -246,7 +248,10 @@ def external_temp(self):

@property
def lambda_args(self):
"""Returns the lamba arguments."""
"""Returns the lambda arguments.
Updates the initial_internal_temp."""
self._lambda_args[const.LAMBDA_INITIAL_INTERNAL_TEMP] = self.house_temperature
return self._lambda_args

@property
Expand Down Expand Up @@ -416,7 +421,9 @@ async def upload_old_history(self):
missing_old_histories_states)
if histories == {}:
self.history_upload_complete = True
LOGGER.debug('History upload complete\n')
LOGGER.debug('History upload complete, recalculate heating profile...\n')
# Now that we have all the history, recalculate heating profile
self.manual_update = True
return
dynamo_data = history.histories_to_dynamo_data(
self.hass,
Expand Down Expand Up @@ -507,6 +514,7 @@ def get_closest_time(self):
const.LAMBDA_BASE_DEMAND,
const.LAMBDA_PRICE,
const.LAMBDA_TEMP,
const.LAMBDA_TEMP_CONTROLS,
const.LAMBDA_OPTIMISED_DEMAND]
non_time_based_keys = [
const.LAMBDA_BASE_COST,
Expand Down
2 changes: 1 addition & 1 deletion custom_components/optispark/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/Big-Tree/HomeAssistant-OptiSpark/issues",
"requirements": ["geopy==2.4.1"],
"version": "0.1.7"
"version": "0.1.8"
}

0 comments on commit 9e91f63

Please sign in to comment.