Skip to content

Commit

Permalink
added kennfeld bitmap
Browse files Browse the repository at this point in the history
  • Loading branch information
OStrama committed Dec 9, 2024
1 parent 353cc07 commit 77851e6
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 51 deletions.
66 changes: 34 additions & 32 deletions custom_components/weishaupt_modbus/kennfeld.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import numpy as np
from numpy.polynomial import Chebyshev

import matplotlib.pyplot as plt

from .configentry import MyConfigEntry

from .const import CONF, CONST
Expand Down Expand Up @@ -99,6 +101,7 @@ def __init__(self, config_entry: MyConfigEntry) -> None:
self._max_power = []
self._interp_y = []
self._r_to_interpolate = 0
self._all_t = None

async def initialize(self):
"""Initialize the power map."""
Expand Down Expand Up @@ -159,14 +162,18 @@ async def initialize(self):

# at second step, power vs. outside temp are interpolated using cubic splines
# we want to have samples at every integer °C
t = np.linspace(-30, 40, 71)
self._all_t = np.linspace(-30, 40, 71)
# cubic spline interpolation of power curves
for idx in range(len(self._r_to_interpolate)):
if SPLINE_AVAILABLE is True:
f = CubicSpline(self.known_x, self._interp_y[idx], bc_type="natural")
else:
f = Chebyshev.fit(self.known_x, self._interp_y[idx], deg=8)
self._max_power.append(f(t))
self._max_power.append(f(self._all_t))

await self._config_entry.runtime_data.hass.async_add_executor_job(
self.plot_kennfeld_to_file
)

def map(self, x, y):
"""Map."""
Expand All @@ -179,34 +186,29 @@ def map(self, x, y):

return self._max_power[int(y)][int(x)]

def plot_kennfeld_to_file(self):
"""plots the kennfeld file into png image for display"""
plt.plot(self._all_t, np.transpose(self._max_power))
plt.ylabel("Max Power")
plt.xlabel("°C")
plt.grid()
plt.xlim(-25, 40)
plt.ylim(2000, 12000)

# map = PowerMap()

# plt.plot(t, np.transpose(map.max_power))
# plt.ylabel("Max Power")
# plt.xlabel("°C")
# plt.show()

# kennfeld = {'known_x': map.known_x,
# 'known_y': map.known_y,
# 'known_t': map.known_t}

# with open("sample1.json", "w") as outfile:
# outfile.write(kennfeld)


# with open("sample2.json", "w") as outfile:
# json.dump(kennfeld, outfile)

# with open('sample2.json', 'r') as openfile:

# Reading from json file
# json_object = json.load(openfile)

# map.known_x = json_object['known_x']
# map.known_y = json_object['known_y']
# map.known_t = json_object['known_t']

# print(map.known_x)
# print(map.known_y)
# print(map.known_t)
try:
filepath = (
self._config_entry.runtime_data.config_dir
+ "/www/local/"
+ CONST.DOMAIN
+ "_powermap.png"
)
plt.savefig(filepath)
log.info(
"Write power map image file %s",
filepath,
)
except OSError:
log.warning(
"Error writing power map image file %s",
filepath,
)
2 changes: 1 addition & 1 deletion custom_components/weishaupt_modbus/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"iot_class": "local_polling",
"issue_tracker": "https://github.com/OStrama/weishaupt_modbus/issues",
"loggers": ["weishaupt_modbus"],
"requirements": ["pymodbus>=3.6.8", "aiofiles>=24.1.0", "beautifulsoup4>=4.12.3"],
"requirements": ["pymodbus>=3.6.8", "aiofiles>=24.1.0", "beautifulsoup4>=4.12.3", "matplotlib>=3.9.2"],
"version": "1.0.5"
}

10 changes: 5 additions & 5 deletions custom_components/weishaupt_modbus/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1554,19 +1554,19 @@
}
},
"tagesarbeitszahl_heute": {
"name": "{prefix}Tagesarbeitszahl heute"
"name": "{prefix}Daily performance factor today"
},
"spreizung": {
"name": "{prefix}Spreizung"
"name": "{prefix}Spread"
},
"jahresarbeitszahl": {
"name": "{prefix}Jahresarbeitszahl"
"name": "{prefix}Annual performance factor"
},
"tagesarbeitszahl_gestern": {
"name": "{prefix}Tagesarbeitszahl gestern"
"name": "{prefix}Daily performance factor yesterday"
},
"monatsarbeitszahl": {
"name": "{prefix}Monatsarbeitszahl"
"name": "{prefix}Monthly performance factor"
},
"ww_energie_yesterday": {
"name": "{prefix}Hot water energy yesterday"
Expand Down
29 changes: 16 additions & 13 deletions custom_components/weishaupt_modbus/translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -1323,19 +1323,7 @@
"name" : "{prefix}Voorlooptemperatuur precies (Summenvorlauf(B7))"
},
"vl_temp" : {
"name" : "{prefix}Voorloop streeftemperatuur"
},
"vl_temp2" : {
"name" : "{prefix}Voorloop streeftemperatuur 2"
},
"vl_temp3" : {
"name" : "{prefix}Voorloop streeftemperatuur 3"
},
"vl_temp4" : {
"name" : "{prefix}Voorloop streeftemperatuur 4"
},
"vl_temp5" : {
"name" : "{prefix}Voorloop streeftemperatuur 5"
"name" : "{prefix}aanvoertemperatuur"
},
"w2_konf" : {
"name" : "{prefix}W2_Configuratie",
Expand Down Expand Up @@ -1548,6 +1536,21 @@
"hp_stoerungsfrei" : "Geen fout"
}
},
"tagesarbeitszahl_heute": {
"name": "{prefix}Dagelijkse prestatiefactor vandaag"
},
"spreizung": {
"name": "{prefix}Spreiding"
},
"jahresarbeitszahl": {
"name": "{prefix}Jaarlijkse prestatiefactor"
},
"tagesarbeitszahl_gestern": {
"name": "{prefix}Dagelijkse prestatiefactor gisteren"
},
"monatsarbeitszahl": {
"name": "{prefix}Maandelijks prestatiefactor"
},
"ww_energie_yesterday" : {
"name" : "{prefix}Warm water energie gisteren"
},
Expand Down

0 comments on commit 77851e6

Please sign in to comment.