juham-automation 0.0.2__py3-none-any.whl → 0.2.8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- juham_automation/__init__.py +42 -37
- juham_automation/automation/__init__.py +23 -0
- juham_automation/automation/energybalancer.py +281 -0
- juham_automation/automation/energycostcalculator.py +310 -0
- juham_automation/automation/heatingoptimizer.py +971 -0
- juham_automation/automation/leakdetector.py +162 -0
- juham_automation/automation/spothintafi.py +140 -0
- juham_automation/automation/watercirculator.py +140 -0
- juham_automation/japp.py +53 -55
- juham_automation/ts/__init__.py +27 -0
- juham_automation/ts/electricityprice_ts.py +51 -0
- juham_automation/ts/energybalancer_ts.py +73 -0
- juham_automation/ts/energycostcalculator_ts.py +45 -0
- juham_automation/ts/forecast_ts.py +97 -0
- juham_automation/ts/log_ts.py +60 -0
- juham_automation/ts/power_ts.py +52 -0
- juham_automation/ts/powermeter_ts.py +68 -0
- juham_automation/ts/powerplan_ts.py +64 -0
- juham_automation-0.2.8.dist-info/METADATA +199 -0
- juham_automation-0.2.8.dist-info/RECORD +25 -0
- {juham_automation-0.0.2.dist-info → juham_automation-0.2.8.dist-info}/WHEEL +1 -1
- {juham_automation-0.0.2.dist-info → juham_automation-0.2.8.dist-info}/entry_points.txt +4 -2
- {juham_automation-0.0.2.dist-info → juham_automation-0.2.8.dist-info/licenses}/LICENSE.rst +25 -25
- juham_automation-0.0.2.dist-info/METADATA +0 -103
- juham_automation-0.0.2.dist-info/RECORD +0 -9
- {juham_automation-0.0.2.dist-info → juham_automation-0.2.8.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from typing import Any
|
|
3
|
+
from typing_extensions import override
|
|
4
|
+
|
|
5
|
+
from masterpiece.mqtt import MqttMsg
|
|
6
|
+
|
|
7
|
+
from juham_core import JuhamTs
|
|
8
|
+
from juham_core.timeutils import epoc2utc
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class EnergyBalancerTs(JuhamTs):
|
|
12
|
+
"""Record energy balance data to time series database.
|
|
13
|
+
|
|
14
|
+
This class listens the "energybalance" MQTT topic and records the
|
|
15
|
+
messages to time series database.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
def __init__(self, name: str = "energybalancer_ts") -> None:
|
|
19
|
+
"""Construct record object with the given name."""
|
|
20
|
+
|
|
21
|
+
super().__init__(name)
|
|
22
|
+
self.topic_in_status = self.make_topic_name("energybalance/status")
|
|
23
|
+
self.topic_in_diagnostics = self.make_topic_name("energybalance/diagnostics")
|
|
24
|
+
|
|
25
|
+
@override
|
|
26
|
+
def on_connect(self, client: object, userdata: Any, flags: int, rc: int) -> None:
|
|
27
|
+
super().on_connect(client, userdata, flags, rc)
|
|
28
|
+
if rc == 0:
|
|
29
|
+
self.subscribe(self.topic_in_status)
|
|
30
|
+
self.subscribe(self.topic_in_diagnostics)
|
|
31
|
+
|
|
32
|
+
@override
|
|
33
|
+
def on_message(self, client: object, userdata: Any, msg: MqttMsg) -> None:
|
|
34
|
+
if msg.topic == self.topic_in_status:
|
|
35
|
+
self.on_status(json.loads(msg.payload.decode()))
|
|
36
|
+
elif msg.topic == self.topic_in_diagnostics:
|
|
37
|
+
self.on_diagnostics(json.loads(msg.payload.decode()))
|
|
38
|
+
else:
|
|
39
|
+
super().on_message(client, userdata, msg)
|
|
40
|
+
|
|
41
|
+
def on_status(self, m: dict[str, Any]) -> None:
|
|
42
|
+
"""Handle energybalance message.
|
|
43
|
+
Args:
|
|
44
|
+
m (dict[str, Any]): Message from energybalance topic.
|
|
45
|
+
"""
|
|
46
|
+
if not "Power" in m or not "Timestamp" in m:
|
|
47
|
+
self.error(f"INVALID STATUS msg {m}")
|
|
48
|
+
return
|
|
49
|
+
point = (
|
|
50
|
+
self.measurement("energybalance")
|
|
51
|
+
.tag("Unit", m["Unit"])
|
|
52
|
+
.field("Mode", m["Mode"])
|
|
53
|
+
.field("Power", float(m["Power"]))
|
|
54
|
+
.time(epoc2utc(m["Timestamp"]))
|
|
55
|
+
)
|
|
56
|
+
self.write(point)
|
|
57
|
+
|
|
58
|
+
def on_diagnostics(self, m: dict[str, Any]) -> None:
|
|
59
|
+
"""Handle energybalance diagnostics.
|
|
60
|
+
Args:
|
|
61
|
+
m (dict[str, Any]): Message from energybalance topic.
|
|
62
|
+
"""
|
|
63
|
+
if not "Timestamp" in m:
|
|
64
|
+
self.error(f"INVALID DIAGNOSTICS msg {m}")
|
|
65
|
+
return
|
|
66
|
+
point = (
|
|
67
|
+
self.measurement("energybalance")
|
|
68
|
+
.tag("EnergyBalancer", m["EnergyBalancer"])
|
|
69
|
+
.field("CurrentBalance", m["CurrentBalance"])
|
|
70
|
+
.field("NeededBalance", m["NeededBalance"])
|
|
71
|
+
.time(epoc2utc(m["Timestamp"]))
|
|
72
|
+
)
|
|
73
|
+
self.write(point)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
from typing_extensions import override
|
|
3
|
+
import json
|
|
4
|
+
|
|
5
|
+
from masterpiece.mqtt import MqttMsg
|
|
6
|
+
|
|
7
|
+
from juham_core import JuhamTs
|
|
8
|
+
from juham_core.timeutils import (
|
|
9
|
+
epoc2utc,
|
|
10
|
+
timestampstr,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class EnergyCostCalculatorTs(JuhamTs):
|
|
15
|
+
"""The EnergyCostCalculator recorder."""
|
|
16
|
+
|
|
17
|
+
def __init__(self, name: str = "ecc_ts") -> None:
|
|
18
|
+
super().__init__(name)
|
|
19
|
+
self.topic_net_energy_balance = self.make_topic_name("net_energy_cost")
|
|
20
|
+
|
|
21
|
+
@override
|
|
22
|
+
def on_connect(self, client: object, userdata: Any, flags: int, rc: int) -> None:
|
|
23
|
+
super().on_connect(client, userdata, flags, rc)
|
|
24
|
+
if rc == 0:
|
|
25
|
+
self.subscribe(self.topic_net_energy_balance)
|
|
26
|
+
|
|
27
|
+
@override
|
|
28
|
+
def on_message(self, client: object, userdata: Any, msg: MqttMsg) -> None:
|
|
29
|
+
if msg.topic == self.topic_net_energy_balance:
|
|
30
|
+
m = json.loads(msg.payload.decode())
|
|
31
|
+
self.record_powerconsumption(m)
|
|
32
|
+
else:
|
|
33
|
+
super().on_message(client, userdata, msg)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def record_powerconsumption(self, m: dict[str, Any]) -> None:
|
|
37
|
+
"""Record powerconsumption
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
m (dict[str, Any]): to be recorded
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
self.write_point(
|
|
44
|
+
"energycost", {"site": m["name"]}, m, timestampstr(m["ts"])
|
|
45
|
+
)
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from typing import Any
|
|
3
|
+
from typing_extensions import override
|
|
4
|
+
|
|
5
|
+
from masterpiece.mqtt import MqttMsg
|
|
6
|
+
from juham_core import JuhamTs
|
|
7
|
+
from juham_core.timeutils import epoc2utc
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class ForecastTs(JuhamTs):
|
|
11
|
+
"""Forecast database record.
|
|
12
|
+
|
|
13
|
+
This class listens the forecast topic and writes to the time series
|
|
14
|
+
database.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
def __init__(self, name: str = "forecast_ts") -> None:
|
|
18
|
+
"""Construct forecast record object with the given name."""
|
|
19
|
+
super().__init__(name)
|
|
20
|
+
self.forecast_topic = self.make_topic_name("forecast")
|
|
21
|
+
|
|
22
|
+
@override
|
|
23
|
+
def on_connect(self, client: object, userdata: Any, flags: int, rc: int) -> None:
|
|
24
|
+
"""Standard mqtt connect notification.
|
|
25
|
+
|
|
26
|
+
This method is called when the client connection with the MQTT
|
|
27
|
+
broker is established.
|
|
28
|
+
"""
|
|
29
|
+
super().on_connect(client, userdata, flags, rc)
|
|
30
|
+
self.subscribe(self.forecast_topic)
|
|
31
|
+
self.debug(f"Subscribed to {self.forecast_topic}")
|
|
32
|
+
|
|
33
|
+
@override
|
|
34
|
+
def on_message(self, client: object, userdata: Any, msg: MqttMsg) -> None:
|
|
35
|
+
"""Standard mqtt message notification method.
|
|
36
|
+
|
|
37
|
+
This method is called upon new arrived message.
|
|
38
|
+
"""
|
|
39
|
+
if msg.topic == self.forecast_topic:
|
|
40
|
+
m = json.loads(msg.payload.decode())
|
|
41
|
+
self.on_forecast(m)
|
|
42
|
+
else:
|
|
43
|
+
super().on_message(client, userdata, msg)
|
|
44
|
+
|
|
45
|
+
def on_forecast(self, em: dict[Any, Any]) -> None:
|
|
46
|
+
"""Handle weather forecast data. Writes the received hourly forecast
|
|
47
|
+
data to timeseries database.
|
|
48
|
+
|
|
49
|
+
Args:
|
|
50
|
+
em (dict): forecast
|
|
51
|
+
"""
|
|
52
|
+
|
|
53
|
+
# List of fields you want to add
|
|
54
|
+
fields = [
|
|
55
|
+
"ts",
|
|
56
|
+
"day",
|
|
57
|
+
"solarradiation",
|
|
58
|
+
"solarenergy",
|
|
59
|
+
"cloudcover",
|
|
60
|
+
"snowdepth",
|
|
61
|
+
"uvindex",
|
|
62
|
+
"pressure",
|
|
63
|
+
"humidity",
|
|
64
|
+
"windspeed",
|
|
65
|
+
"winddir",
|
|
66
|
+
"temp",
|
|
67
|
+
"feels",
|
|
68
|
+
]
|
|
69
|
+
days: int = 0
|
|
70
|
+
for m in em:
|
|
71
|
+
senderid: str = "unknown"
|
|
72
|
+
if "id" in m:
|
|
73
|
+
senderid = m["id"]
|
|
74
|
+
if not "hour" in m:
|
|
75
|
+
self.error(
|
|
76
|
+
f"No hour key in forecast record from {senderid}, skipped", str(m)
|
|
77
|
+
)
|
|
78
|
+
else:
|
|
79
|
+
point = (
|
|
80
|
+
self.measurement("forecast")
|
|
81
|
+
.tag("hour", m.get("hour"))
|
|
82
|
+
.tag("source", senderid)
|
|
83
|
+
.field("hr", str(m["hour"]))
|
|
84
|
+
)
|
|
85
|
+
# Conditionally add each field
|
|
86
|
+
for field in fields:
|
|
87
|
+
if field in m:
|
|
88
|
+
if field == "day" or field == "ts":
|
|
89
|
+
point = point.field(field, m[field])
|
|
90
|
+
else:
|
|
91
|
+
point = point.field(field, float(m[field]))
|
|
92
|
+
point = point.time(epoc2utc(m["ts"]))
|
|
93
|
+
self.write(point)
|
|
94
|
+
days = days + 1
|
|
95
|
+
self.info(
|
|
96
|
+
f"Forecast from {senderid} for the next {days} days written to time series database"
|
|
97
|
+
)
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from typing import Any
|
|
3
|
+
from typing_extensions import override
|
|
4
|
+
|
|
5
|
+
from masterpiece.mqtt import MqttMsg
|
|
6
|
+
from juham_core import JuhamTs
|
|
7
|
+
from juham_core.timeutils import epoc2utc
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class LogTs(JuhamTs):
|
|
11
|
+
"""Class recording application events, such as warnings and errors,
|
|
12
|
+
to time series database."""
|
|
13
|
+
|
|
14
|
+
def __init__(self, name: str = "log_ts") -> None:
|
|
15
|
+
"""Creates mqtt client for recording log events to time series
|
|
16
|
+
database.
|
|
17
|
+
|
|
18
|
+
Args:
|
|
19
|
+
name (str): name for the client
|
|
20
|
+
"""
|
|
21
|
+
super().__init__(name)
|
|
22
|
+
self.topic_name = self.make_topic_name("log")
|
|
23
|
+
|
|
24
|
+
@override
|
|
25
|
+
def on_connect(self, client: object, userdata: Any, flags: int, rc: int) -> None:
|
|
26
|
+
"""Connects the client to mqtt broker.
|
|
27
|
+
|
|
28
|
+
Args:
|
|
29
|
+
client (obj): client to be connected
|
|
30
|
+
userdata (any): caller specific data
|
|
31
|
+
flags (int): implementation specific shit
|
|
32
|
+
|
|
33
|
+
Returns:
|
|
34
|
+
rc (bool): True if successful
|
|
35
|
+
"""
|
|
36
|
+
super().on_connect(client, userdata, flags, rc)
|
|
37
|
+
if rc == 0:
|
|
38
|
+
self.subscribe(self.topic_name)
|
|
39
|
+
|
|
40
|
+
@override
|
|
41
|
+
def on_message(self, client: object, userdata: Any, msg: MqttMsg) -> None:
|
|
42
|
+
if msg.topic == self.topic_name:
|
|
43
|
+
m = json.loads(msg.payload.decode())
|
|
44
|
+
ts = epoc2utc(m["Timestamp"])
|
|
45
|
+
|
|
46
|
+
point = (
|
|
47
|
+
self.measurement("log")
|
|
48
|
+
.tag("class", m["Class"])
|
|
49
|
+
.field("source", m["Source"])
|
|
50
|
+
.field("msg", m["Msg"])
|
|
51
|
+
.field("details", m["Details"])
|
|
52
|
+
.field("Timestamp", m["Timestamp"])
|
|
53
|
+
.time(ts)
|
|
54
|
+
)
|
|
55
|
+
try:
|
|
56
|
+
self.write(point)
|
|
57
|
+
except Exception as e:
|
|
58
|
+
print(f"ERROR: Cannot write log event {m['Msg']} {e}")
|
|
59
|
+
else:
|
|
60
|
+
super().on_message(client, userdata, msg)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from typing import Any
|
|
3
|
+
from typing_extensions import override
|
|
4
|
+
|
|
5
|
+
from masterpiece.mqtt import MqttMsg
|
|
6
|
+
|
|
7
|
+
from juham_core import JuhamTs
|
|
8
|
+
from juham_core.timeutils import epoc2utc
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class PowerTs(JuhamTs):
|
|
12
|
+
"""Power utilization record.
|
|
13
|
+
|
|
14
|
+
This class listens the power utilization message and writes the
|
|
15
|
+
state to time series database.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
def __init__(self, name: str = "power_ts") -> None:
|
|
19
|
+
"""Construct power record object with the given name."""
|
|
20
|
+
|
|
21
|
+
super().__init__(name)
|
|
22
|
+
self.topic_name = self.make_topic_name("power")
|
|
23
|
+
|
|
24
|
+
@override
|
|
25
|
+
def on_connect(self, client: object, userdata: Any, flags: int, rc: int) -> None:
|
|
26
|
+
super().on_connect(client, userdata, flags, rc)
|
|
27
|
+
self.subscribe(self.topic_name)
|
|
28
|
+
self.debug(f"Subscribed to {self.topic_name}")
|
|
29
|
+
|
|
30
|
+
@override
|
|
31
|
+
def on_message(self, client: object, userdata: Any, msg: MqttMsg) -> None:
|
|
32
|
+
"""Standard mqtt message notification method.
|
|
33
|
+
|
|
34
|
+
This method is called upon new arrived message.
|
|
35
|
+
"""
|
|
36
|
+
if msg.topic == self.topic_name:
|
|
37
|
+
m = json.loads(msg.payload.decode())
|
|
38
|
+
if not "Unit" in m:
|
|
39
|
+
return
|
|
40
|
+
unit = m["Unit"]
|
|
41
|
+
ts = m["Timestamp"]
|
|
42
|
+
state = m["State"]
|
|
43
|
+
point = (
|
|
44
|
+
self.measurement("power")
|
|
45
|
+
.tag("unit", unit)
|
|
46
|
+
.field("state", state)
|
|
47
|
+
.time(epoc2utc(ts))
|
|
48
|
+
)
|
|
49
|
+
self.write(point)
|
|
50
|
+
else:
|
|
51
|
+
super().on_message(client, userdata, msg)
|
|
52
|
+
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from typing import Any, Dict
|
|
3
|
+
from typing_extensions import override
|
|
4
|
+
|
|
5
|
+
from masterpiece.mqtt import MqttMsg
|
|
6
|
+
from juham_core import JuhamTs
|
|
7
|
+
from juham_core.timeutils import epoc2utc
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class PowerMeterTs(JuhamTs):
|
|
11
|
+
"""Power meter recorder.
|
|
12
|
+
|
|
13
|
+
Listens 'powerconsumption' topic and records the corresponding
|
|
14
|
+
time series.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
def __init__(self, name: str = "powermeter_record") -> None:
|
|
18
|
+
super().__init__(name)
|
|
19
|
+
self.power_topic = self.make_topic_name("powerconsumption") # topic to listen
|
|
20
|
+
|
|
21
|
+
@override
|
|
22
|
+
def on_connect(self, client: object, userdata: Any, flags: int, rc: int) -> None:
|
|
23
|
+
super().on_connect(client, userdata, flags, rc)
|
|
24
|
+
if rc == 0:
|
|
25
|
+
self.subscribe(self.power_topic)
|
|
26
|
+
|
|
27
|
+
@override
|
|
28
|
+
def on_message(self, client: object, userdata: Any, msg: MqttMsg) -> None:
|
|
29
|
+
if msg.topic == self.power_topic:
|
|
30
|
+
m = json.loads(msg.payload.decode())
|
|
31
|
+
self.record_power(m)
|
|
32
|
+
else:
|
|
33
|
+
super().on_message(client, userdata, msg)
|
|
34
|
+
|
|
35
|
+
def record_power(self, em: dict[str, Any]) -> None:
|
|
36
|
+
"""Write from the power (energy) meter to the time
|
|
37
|
+
series database accordingly.
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
ts (float): utc time
|
|
41
|
+
em (dict): energy meter message
|
|
42
|
+
"""
|
|
43
|
+
point = (
|
|
44
|
+
self.measurement("powermeter")
|
|
45
|
+
.tag("sensor", "em0")
|
|
46
|
+
.field("real_A", em["real_a"])
|
|
47
|
+
.field("real_B", em["real_b"])
|
|
48
|
+
.field("real_C", em["real_c"])
|
|
49
|
+
.field("total_real_power", em["real_total"])
|
|
50
|
+
.time(epoc2utc(em["timestamp"]))
|
|
51
|
+
)
|
|
52
|
+
try:
|
|
53
|
+
self.write(point)
|
|
54
|
+
except Exception as e:
|
|
55
|
+
self.error(f"Writing to influx failed {str(e)}")
|
|
56
|
+
|
|
57
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
58
|
+
data: Dict[str, Any] = super().to_dict()
|
|
59
|
+
data["_powermeter_record"] = {
|
|
60
|
+
"power_topic": self.power_topic,
|
|
61
|
+
}
|
|
62
|
+
return data
|
|
63
|
+
|
|
64
|
+
def from_dict(self, data: Dict[str, Any]) -> None:
|
|
65
|
+
super().from_dict(data)
|
|
66
|
+
if "_powermeter_record" in data:
|
|
67
|
+
for key, value in data["_powermeter_record"].items():
|
|
68
|
+
setattr(self, key, value)
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from typing import Any
|
|
3
|
+
from typing_extensions import override
|
|
4
|
+
|
|
5
|
+
from masterpiece.mqtt import MqttMsg
|
|
6
|
+
from juham_core import JuhamTs
|
|
7
|
+
from juham_core.timeutils import epoc2utc
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class PowerPlanTs(JuhamTs):
|
|
11
|
+
"""Power plan time series record.
|
|
12
|
+
|
|
13
|
+
Listens powerplan topic and updates time series database
|
|
14
|
+
accordingly.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
def __init__(self, name: str = "powerplan_ts") -> None:
|
|
18
|
+
super().__init__(name)
|
|
19
|
+
self.powerplan_topic = self.make_topic_name("powerplan")
|
|
20
|
+
|
|
21
|
+
@override
|
|
22
|
+
def on_connect(self, client: object, userdata: Any, flags: int, rc: int) -> None:
|
|
23
|
+
super().on_connect(client, userdata, flags, rc)
|
|
24
|
+
self.subscribe(self.powerplan_topic)
|
|
25
|
+
|
|
26
|
+
@override
|
|
27
|
+
def on_message(self, client: object, userdata: Any, msg: MqttMsg) -> None:
|
|
28
|
+
if msg.topic == self.powerplan_topic:
|
|
29
|
+
m = json.loads(msg.payload.decode())
|
|
30
|
+
schedule = m["Schedule"]
|
|
31
|
+
uoi = m["UOI"]
|
|
32
|
+
ts = m["Timestamp"]
|
|
33
|
+
|
|
34
|
+
# optional fields
|
|
35
|
+
tempForecast = m.get("NextDayTemperature")
|
|
36
|
+
solarForecast = m.get("NextDaySolarpower")
|
|
37
|
+
minTemp = m.get("MinTempLimit")
|
|
38
|
+
maxTemp = m.get("MaxTempLimit")
|
|
39
|
+
|
|
40
|
+
point = (
|
|
41
|
+
self.measurement("powerplan")
|
|
42
|
+
.tag("unit", m["Unit"])
|
|
43
|
+
.field("state", m["State"]) # 1 on, 0 off
|
|
44
|
+
.field("name", m["Unit"]) # e.g main_boiler
|
|
45
|
+
.field("type", "C") # C=consumption, S = supply
|
|
46
|
+
.field("power", 16.0) # kW
|
|
47
|
+
.field("Schedule", schedule) # figures of merit
|
|
48
|
+
.field("UOI", float(uoi)) # Utilitzation Optimizing Index
|
|
49
|
+
.time(epoc2utc(ts))
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
# Add optional fields only if they are present in the message
|
|
53
|
+
if minTemp is not None:
|
|
54
|
+
point = point.field("MinTemp", float(minTemp))
|
|
55
|
+
if maxTemp is not None:
|
|
56
|
+
point = point.field("MaxTemp", float(maxTemp))
|
|
57
|
+
if tempForecast is not None:
|
|
58
|
+
point = point.field("TempForecast", float(tempForecast))
|
|
59
|
+
if solarForecast is not None:
|
|
60
|
+
point = point.field("SolarForecast", float(solarForecast))
|
|
61
|
+
|
|
62
|
+
self.write(point)
|
|
63
|
+
else:
|
|
64
|
+
super().on_message(client, userdata, msg)
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: juham-automation
|
|
3
|
+
Version: 0.2.8
|
|
4
|
+
Summary: Juha's Ultimate Home Automation Masterpiece
|
|
5
|
+
Author-email: J Meskanen <juham.api@gmail.com>
|
|
6
|
+
Maintainer-email: "J. Meskanen" <juham.api@gmail.com>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Project-URL: Homepage, https://gitlab.com/juham/juham/juham-automation
|
|
9
|
+
Project-URL: Bug Reports, https://gitlab.com/juham/juham/juham-automationt
|
|
10
|
+
Project-URL: Funding, https://meskanen.com
|
|
11
|
+
Project-URL: Say Thanks!, http://meskanen.com
|
|
12
|
+
Project-URL: Source, https://gitlab.com/juham/juham/juham-automation
|
|
13
|
+
Keywords: home,automation,juham
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Topic :: Software Development
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
18
|
+
Requires-Python: >=3.8
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE.rst
|
|
21
|
+
Requires-Dist: juham_core>=0.2.4
|
|
22
|
+
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: check-manifest; extra == "dev"
|
|
24
|
+
Requires-Dist: coverage>=7.0; extra == "dev"
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
|
|
27
|
+
Welcome to Juham™ - Juha's Ultimate Home Automation Masterpiece
|
|
28
|
+
===============================================================
|
|
29
|
+
|
|
30
|
+
Project Description
|
|
31
|
+
-------------------
|
|
32
|
+
|
|
33
|
+
Beyond its super-cool name, this package provides essential home automation building blocks that address most common needs.
|
|
34
|
+
|
|
35
|
+
It consists of two main sub-modules:
|
|
36
|
+
|
|
37
|
+
``automation``:
|
|
38
|
+
|
|
39
|
+
This folder contains automation classes that listen to Juham™ MQTT topics and control various home automation tasks.
|
|
40
|
+
|
|
41
|
+
- **spothintafi**: Acquires electricity prices in Finland.
|
|
42
|
+
- **watercirculator**: Automates a water circulator pump based on hot water temperature and motion detection.
|
|
43
|
+
- **heatingoptimizer**: Controls hot water radiators based on temperature sensors and electricity price data.
|
|
44
|
+
- **energycostcalculator**: Monitors power consumption and electricity prices, and computes the energy balance in euros.
|
|
45
|
+
- **energybalancer**: Handles real-time energy balancing and net billing.
|
|
46
|
+
|
|
47
|
+
``ts``:
|
|
48
|
+
|
|
49
|
+
This folder contains time series recorders that listen for Juham™ topics and store the data in a time series database for later inspection.
|
|
50
|
+
|
|
51
|
+
- **electricityprice_ts** : publishes electricity prices to timeseries database.
|
|
52
|
+
- **energybalancer_ts**: for monitoring the operation of energy balancer.
|
|
53
|
+
- **energycostcalculator_ts**: publishes actualized energy prices per hour and per day.
|
|
54
|
+
- **forecast_ts**: publishes the forecast datat to timeseries database.
|
|
55
|
+
- **log_ts**: Writes log events to timeseries datbase.
|
|
56
|
+
- **powerplan_ts**: publishes power plan data to timeseries database, when relays are planned to be switched on/off.
|
|
57
|
+
- **powermeter_ts**: publishes powermeter data to timeseries database.
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
Project Status
|
|
61
|
+
--------------
|
|
62
|
+
|
|
63
|
+
**Current State**: **Beta (Status 4)**
|
|
64
|
+
|
|
65
|
+
All classes have been tested to some extent, and no known bugs have been reported.
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
Project Links
|
|
69
|
+
-------------
|
|
70
|
+
|
|
71
|
+
- **Source code:** https://gitlab.com/juham/juham/juham-automation
|
|
72
|
+
- **Issue tracker:** https://gitlab.com/juham/juham/juham-automation/-/issues
|
|
73
|
+
- **Documentation:** https://juham-automation-c6383e.gitlab.io
|
|
74
|
+
- **PyPI page:** https://pypi.org/project/juham-automation
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
Features
|
|
79
|
+
--------
|
|
80
|
+
|
|
81
|
+
**HeatingAutomater** listens to the power meter to compute the net energy balance.
|
|
82
|
+
|
|
83
|
+
.. image:: _static/images/juham_powermeter.png
|
|
84
|
+
:alt: Powermeter
|
|
85
|
+
:width: 400px
|
|
86
|
+
|
|
87
|
+
Powermeter is needed to measure the real-time energy consumption
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
**Energy Revenue** is computed based on the electricity price and transmission costs. This is the total cost one has to pay for consuming energy.
|
|
91
|
+
|
|
92
|
+
.. image:: _static/images/juham_energyrevenue.png
|
|
93
|
+
:alt: Energy Revenue
|
|
94
|
+
:width: 400px
|
|
95
|
+
|
|
96
|
+
Energy revenue per hour and per day
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
**Real-time temperature** trends monitored by the **Shelly Plus Add-on** and **DS18B20** sensors
|
|
100
|
+
|
|
101
|
+
.. image:: _static/images/juham_boilertemperatures.png
|
|
102
|
+
:alt: Energy Revenue
|
|
103
|
+
:width: 400px
|
|
104
|
+
|
|
105
|
+
Temperature time series.
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
**Real-time humidity** trends monitored by the **Shelly Plus Add-on** and **DHT22** sensors
|
|
109
|
+
|
|
110
|
+
.. image:: _static/images/juham_humiditysensors.png
|
|
111
|
+
:alt: Energy Revenue
|
|
112
|
+
:width: 400px
|
|
113
|
+
|
|
114
|
+
Relative humidity time series.
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
**Utilization Optimization Index**: The Utilization Optimization Index predicts the optimal hours for energy consumption by factoring in electricity prices, temperature, and forecasts for wind and solar energy. It identifies the best times to activate heating systems. The cheapest hours within the current period may be skipped if the solar forecast predicts free electricity in the next period.period.
|
|
119
|
+
|
|
120
|
+
.. image:: _static/images/juham_uoi.png
|
|
121
|
+
:alt: Power Plan
|
|
122
|
+
:width: 400px
|
|
123
|
+
|
|
124
|
+
UOI cast for heating the primary and sun pre-heating boilers for two types of solar panels and boilers: electric-based panels and solar thermal panels, which use water circulation. The primary one is electrically heated, while the secondary ‘pre-heating’ boiler is heated by the hot water from the solar thermal panels, or by electricity when there's a positive energy balance.
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
**Power Plan** is computed for the next 12 hours based on the electricity price and solar energy forecast. If no solar energy is available, the power plan determines power consumption, e.g., when the hot water radiators are enabled.
|
|
128
|
+
|
|
129
|
+
.. image:: _static/images/juham_powerplan.png
|
|
130
|
+
:alt: Power Plan
|
|
131
|
+
:width: 400px
|
|
132
|
+
|
|
133
|
+
Powerplan optimizing consumers to use the cheapest hours
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
**Energy Balancer**: When the energy balance is positive (e.g., when solar panels produce more energy than is currently being consumed), the energy balancer is activated. It monitors the energy balance in 15-minute (or one-hour) intervals and computes when a consumer with a specific power demand should be activated to consume all the energy produced so far.
|
|
137
|
+
|
|
138
|
+
.. image:: _static/images/juham_automation_energybalancer.png
|
|
139
|
+
:alt: Energy Balancer
|
|
140
|
+
:width: 400px
|
|
141
|
+
|
|
142
|
+
Energy balancer activating consumers based on the actual real-time net energy
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
**Power Diagnosis**: All controlled relays are monitored to ensure their correct operation. This ensures that relays are enabled according to the power plan and energy balancer commands.
|
|
146
|
+
|
|
147
|
+
.. image:: _static/images/juham_automation_relays.png
|
|
148
|
+
:alt: Relays
|
|
149
|
+
:width: 400px
|
|
150
|
+
|
|
151
|
+
The operation of the relays for diagnosis.
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
Installing
|
|
155
|
+
----------
|
|
156
|
+
|
|
157
|
+
Juham™ ships with a minimal yet fully functional home automation application that can be found in the **examples** folder.
|
|
158
|
+
It creates a **PowerMeterSimulator** and **ShellyMotionSimulator** objets to generate simulated motion sensor and power meter readings.
|
|
159
|
+
Later, you can replace it with your actual power meter, as well as plug in other input sensors to read and relays to control.
|
|
160
|
+
|
|
161
|
+
1. Set up a Mosquitto MQTT broker service. For more information read the manuals.
|
|
162
|
+
|
|
163
|
+
.. code-block:: bash
|
|
164
|
+
|
|
165
|
+
sudo apt install mosquitto mosquitto-clients
|
|
166
|
+
|
|
167
|
+
2. Configure Juham to talk to Mosquitto.
|
|
168
|
+
|
|
169
|
+
In ``PahoMqtt.json``:
|
|
170
|
+
|
|
171
|
+
.. code-block:: json
|
|
172
|
+
|
|
173
|
+
{"paho_version" : 2}
|
|
174
|
+
|
|
175
|
+
In ``Juham.json``:
|
|
176
|
+
|
|
177
|
+
.. code-block:: json
|
|
178
|
+
|
|
179
|
+
{"mqtt_class_id": "PahoMqtt", "mqtt_root_topic": "myapp", "mqtt_host": "localhost", "mqtt_port": 1883}
|
|
180
|
+
|
|
181
|
+
In ``Timeseries.json``:
|
|
182
|
+
|
|
183
|
+
.. code-block:: json
|
|
184
|
+
|
|
185
|
+
{
|
|
186
|
+
"token": "your-influx-token",
|
|
187
|
+
"org": "your-organization",
|
|
188
|
+
"host": "https://us-east-1-1.aws.cloud2.influxdata.com",
|
|
189
|
+
"database": "your-database"
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
3. In the ``juham/examples`` folder, run:
|
|
193
|
+
|
|
194
|
+
.. code-block:: bash
|
|
195
|
+
|
|
196
|
+
python3 myapp.py
|
|
197
|
+
|
|
198
|
+
The application will start and time series data will show up in your InfluxDB database,
|
|
199
|
+
which you can then visualize with tools such as Grafana.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
juham_automation/__init__.py,sha256=Y_fUDerXnXFkv1z2p7FeqKQlJ2EuIDY6AEK7xVQ1tXE,914
|
|
2
|
+
juham_automation/japp.py,sha256=L2u1mfKvun2fiXhB3AEJD9zMDcdFZ3_doXZYJJzu9tg,1646
|
|
3
|
+
juham_automation/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
4
|
+
juham_automation/automation/__init__.py,sha256=0FYYSo2qSMMibH5YHIFgdT6gc5Cmf8XlpQHFSrswE5I,500
|
|
5
|
+
juham_automation/automation/energybalancer.py,sha256=Kw0Czah4JLOgDVAx6ca4nJpFpfZa9LXmv6pr612f-Fg,11473
|
|
6
|
+
juham_automation/automation/energycostcalculator.py,sha256=96pidMxi4tK9g8iLepn9XuTeauZhxi74qGXvvQJe-6s,13023
|
|
7
|
+
juham_automation/automation/heatingoptimizer.py,sha256=AO1VHBHfgQJ8kENsgZH3O3GHZjSksQx_CrsdZZoxjoM,39038
|
|
8
|
+
juham_automation/automation/leakdetector.py,sha256=Q-3X0NOFJf0C5MlR7R_QQp8yw5XvTt85oduuTRYIu_0,6003
|
|
9
|
+
juham_automation/automation/spothintafi.py,sha256=cZbi7w2fVweHX_fh1r5MTjGdesX9wDQta2mfVjtiwvw,4331
|
|
10
|
+
juham_automation/automation/watercirculator.py,sha256=QcLAP9oLA-tYYRH2SjnPT6_kIOdiQbOSf2tQPMitEN0,5471
|
|
11
|
+
juham_automation/ts/__init__.py,sha256=kTEzVkDi6ednH4-fxKxrY6enlTuTXmSw09pPAQX3CMc,612
|
|
12
|
+
juham_automation/ts/electricityprice_ts.py,sha256=kRIewAAtTPi5JvHLEgGGVp_28LkWyB6lGyUH_2dKqBQ,1677
|
|
13
|
+
juham_automation/ts/energybalancer_ts.py,sha256=XHl56G5fBjJOCSIJtdjzGpSTMAQN1xsnXpC4Ipl7ynw,2585
|
|
14
|
+
juham_automation/ts/energycostcalculator_ts.py,sha256=ceYvZOvpXftJmAMW7bb33zI1lh1o0nf71XBJGuijD0s,1296
|
|
15
|
+
juham_automation/ts/forecast_ts.py,sha256=Gk46hIlS8ijxs-zyy8fBvXrhI7J-8e5Gt2QEe6gFB6s,3158
|
|
16
|
+
juham_automation/ts/log_ts.py,sha256=GLOqnwmk2cJdoWPWlrC3XAADp-N1JdfZ407YNQxnxhA,1901
|
|
17
|
+
juham_automation/ts/power_ts.py,sha256=_i_mBPtaVFfH9ycv426uQ4VtSzHacLJB6mEApe26fhE,1571
|
|
18
|
+
juham_automation/ts/powermeter_ts.py,sha256=a4sVERj7k397QlJF_VFg-S7DXSg8oAanPcxdYQBzN4w,2218
|
|
19
|
+
juham_automation/ts/powerplan_ts.py,sha256=TXD4aI8TAv2oGrbHZRjxkhrWkOubJ4Lq3sdotsgAn2Q,2358
|
|
20
|
+
juham_automation-0.2.8.dist-info/licenses/LICENSE.rst,sha256=QVHD5V5_HSys2PdPdig_xKggDj8cGX33ALKqRsYyjtI,1089
|
|
21
|
+
juham_automation-0.2.8.dist-info/METADATA,sha256=swuuGZKrrFBlQCoJDqOUkPJVGJ5wqPOgk2OK-NcmOQs,7620
|
|
22
|
+
juham_automation-0.2.8.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
23
|
+
juham_automation-0.2.8.dist-info/entry_points.txt,sha256=h-KzuKjmGPd4_iX_oiGvxx4IEc97dVbGGlhdh5ctbpI,605
|
|
24
|
+
juham_automation-0.2.8.dist-info/top_level.txt,sha256=jfohvtocvX_gfT21AhJk7Iay5ZiQsS3HzrDjF7S4Qp0,17
|
|
25
|
+
juham_automation-0.2.8.dist-info/RECORD,,
|