Skip to content

Commit

Permalink
Commit of new feature to subtract inuse amps from consumption value
Browse files Browse the repository at this point in the history
  • Loading branch information
ngardiner committed Oct 7, 2019
1 parent ee8b5f9 commit db14659
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
23 changes: 20 additions & 3 deletions TWCManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ def delete_slave(deleteSlaveID):
pass

def total_amps_actual_all_twcs():
global config, slaveTWCRoundRobin, config
global config, master, slaveTWCRoundRobin, config

totalAmps = 0
for slaveTWC in slaveTWCRoundRobin:
Expand All @@ -496,6 +496,7 @@ def total_amps_actual_all_twcs():
print("Total amps all slaves are using: " + str(totalAmps))
hassstatus.setStatus(bytes("all", 'UTF-8'), "total_amps_in_use", totalAmps)
mqttstatus.setStatus(bytes("all", 'UTF-8'), "totalAmpsInUse", totalAmps)
master.setTotalAmpsInUse(totalAmps)
return totalAmps


Expand Down Expand Up @@ -1097,7 +1098,7 @@ def background_tasks_thread():
backgroundTasksQueue.task_done()

def check_green_energy():
global maxAmpsToDivideAmongSlaves, config, hass, backgroundTasksLock
global maxAmpsToDivideAmongSlaves, config, hass, backgroundTasksLock, master

# Check solar panel generation using an API exposed by
# the HomeAssistant API.
Expand All @@ -1108,11 +1109,12 @@ def check_green_energy():
#
greenEnergyConsumptionVal = 0
greenEnergyConsumptionVal += hass.getConsumption()
greenEnergyConsumptionVal -= (master.getTotalAmpsInUse() * 240)

greenEnergyGenerationVal = 0
greenEnergyGenerationVal += hass.getGeneration()

# Calculate our current consumption in watts
# Calculate our current generation and consumption in watts
solarW = int(float(greenEnergyGenerationVal) - float(greenEnergyConsumptionVal))

# Generation may be below zero if consumption is greater than generation
Expand Down Expand Up @@ -1272,7 +1274,19 @@ def update_location(self):
#
##############################

class TWCMaster:

totalAmpsInUse = 0
TWCID = None

def __init__(self, TWCID):
self.TWCID = TWCID

def getTotalAmpsInUse(self):
return self.totalAmpsInUse

def setTotalAmpsInUse(self, amps):
self.totalAmpsInUse = amps

##############################
#
Expand Down Expand Up @@ -2334,6 +2348,9 @@ def set_last_amps_offered(self, desiredAmpsOffered):
% ( ("Master" if config['config']['fakeMaster'] else "Slave"), \
ord(fakeTWCID[0:1]), ord(fakeTWCID[1:2]), ord(slaveSign)))

# Instantiate a master object
master = TWCMaster(fakeTWCID)

# Create fronius EMS plugin instance
fronius = Fronius(config['config']['debugLevel'], config['sources']['Fronius'])

Expand Down
1 change: 1 addition & 0 deletions lib/TWCManager/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__

0 comments on commit db14659

Please sign in to comment.