Add calculated power values

for Battery, Panel and Load.
Should give better resolution than the integer panel and load numbers.
This commit is contained in:
Odd Stråbø 2021-11-20 09:12:21 +01:00
parent f7e359af6d
commit b2f29ec263
3 changed files with 29 additions and 1 deletions

View file

@ -94,6 +94,21 @@ MAP_VALUES: Dict[DataName, Dict[str, Any]] = {
}, },
DataName.PANEL_POWER: {"unit": "W", "type": "power", "state_class": "measurement"}, DataName.PANEL_POWER: {"unit": "W", "type": "power", "state_class": "measurement"},
# DataName.LOAD_ENABLED: {}, # DataName.LOAD_ENABLED: {},
DataName.CALCULATED_BATTERY_POWER: {
"unit": "W",
"type": "power",
"state_class": "measurement",
},
DataName.CALCULATED_PANEL_POWER: {
"unit": "W",
"type": "power",
"state_class": "measurement",
},
DataName.CALCULATED_LOAD_POWER: {
"unit": "W",
"type": "power",
"state_class": "measurement",
},
} }

View file

@ -12,7 +12,7 @@ from bluepy import btle
from libscrc import modbus from libscrc import modbus
from feasycom_ble import BTLEUart from feasycom_ble import BTLEUart
from solar_types import DATA_BATTERY_STATE, HISTORICAL_DATA, DataItem from solar_types import DATA_BATTERY_STATE, HISTORICAL_DATA, DataItem, DataName
from test_config import get_config, get_consumers from test_config import get_config, get_consumers
MAC = "DC:0D:30:9C:61:BA" MAC = "DC:0D:30:9C:61:BA"
@ -403,6 +403,15 @@ if __name__ == "__main__":
if per_voltages(now): if per_voltages(now):
data = try_read_parse(dev, 0x0100, 11, parse_battery_state) data = try_read_parse(dev, 0x0100, 11, parse_battery_state)
if data: if data:
data[DataName.CALCULATED_BATTERY_POWER] = data.get(
DataName.BATTERY_VOLTAGE, 0
) * data.get(DataName.BATTERY_CURRENT)
data[DataName.CALCULATED_PANEL_POWER] = data.get(
DataName.PANEL_VOLTAGE, 0
) * data.get(DataName.PANEL_CURRENT)
data[DataName.CALCULATED_LOAD_POWER] = data.get(
DataName.LOAD_VOLTAGE, 0
) * data.get(DataName.LOAD_CURRENT)
log(data) log(data)
for consumer in consumers: for consumer in consumers:
consumer.write(data) consumer.write(data)

View file

@ -36,6 +36,10 @@ class DataName(str, Enum):
TOTAL_PRODUCTION_ENERGY = "total_production_energy" TOTAL_PRODUCTION_ENERGY = "total_production_energy"
TOTAL_CONSUMPTION_ENERGY = "total_consumption_energy" TOTAL_CONSUMPTION_ENERGY = "total_consumption_energy"
CALCULATED_BATTERY_POWER = "calculated_battery_power"
CALCULATED_PANEL_POWER = "calculated_panel_power"
CALCULATED_LOAD_POWER = "calculated_load_power"
def __repr__(self): def __repr__(self):
return repr(self.value) return repr(self.value)