juham-automation 0.0.2__py3-none-any.whl → 0.0.4__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.
@@ -0,0 +1,70 @@
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
+ super().on_message(client, userdata, msg)
30
+ if msg.topic == self.power_topic:
31
+ m = json.loads(msg.payload.decode())
32
+ self.record_power(m)
33
+
34
+ def record_power(self, em: dict[str, Any]) -> None:
35
+ """Write from the power (energy) meter to the time
36
+ series database accordingly.
37
+
38
+ Args:
39
+ ts (float): utc time
40
+ em (dict): energy meter message
41
+ """
42
+ point = (
43
+ self.measurement("powermeter")
44
+ .tag("sensor", "em0")
45
+ .field("real_A", em["real_a"])
46
+ .field("real_B", em["real_b"])
47
+ .field("real_C", em["real_c"])
48
+ .field("total_real_power", em["real_total"])
49
+ .time(epoc2utc(em["timestamp"]))
50
+ )
51
+ try:
52
+ self.write(point)
53
+ # self.debug(
54
+ # f"PowerMeter event recorded {epoc2utc(em['timestamp'])} - {em['real_a']} {em['real_b']} {em['real_c']}"
55
+ # )
56
+ except Exception as e:
57
+ self.error(f"Writing to influx failed {str(e)}")
58
+
59
+ def to_dict(self) -> Dict[str, Any]:
60
+ data: Dict[str, Any] = super().to_dict()
61
+ data["_powermeter_record"] = {
62
+ "power_topic": self.power_topic,
63
+ }
64
+ return data
65
+
66
+ def from_dict(self, data: Dict[str, Any]) -> None:
67
+ super().from_dict(data)
68
+ if "_powermeter_record" in data:
69
+ for key, value in data["_powermeter_record"].items():
70
+ setattr(self, key, value)
@@ -0,0 +1,45 @@
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
+ super().on_message(client, userdata, msg)
29
+ m = json.loads(msg.payload.decode())
30
+ schedule = m["Schedule"]
31
+ uoi = m["UOI"]
32
+ ts = m["Timestamp"]
33
+
34
+ point = (
35
+ self.measurement("powerplan")
36
+ .tag("unit", m["Unit"])
37
+ .field("state", m["State"]) # 1 on, 0 off
38
+ .field("name", m["Unit"]) # e.g main_boiler
39
+ .field("type", "C") # C=consumption, S = supply
40
+ .field("power", 16.0) # kW
41
+ .field("Schedule", schedule) # figures of merit
42
+ .field("UOI", float(uoi)) # Utilitzation Optimizing Index
43
+ .time(epoc2utc(ts))
44
+ )
45
+ self.write(point)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: juham-automation
3
- Version: 0.0.2
3
+ Version: 0.0.4
4
4
  Summary: Juha's Ultimate Home Automation Masterpiece
5
5
  Author-email: J Meskanen <juham.api@gmail.com>
6
6
  Maintainer-email: "J. Meskanen" <juham.api@gmail.com>
@@ -0,0 +1,23 @@
1
+ juham_automation/__init__.py,sha256=ncdniRzO-yUzvxCjuzrtyrLBmsiHO5lJzP-teloVkHU,850
2
+ juham_automation/japp.py,sha256=zD5ulfIcaSzwbVKjHv2tdXpw79fpw97B7P-v-ncY6e4,1520
3
+ juham_automation/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
4
+ juham_automation/automation/__init__.py,sha256=73Mw0jkipeMCoUtpREHJPATfKe368ZyNeqfbjamBx_Q,481
5
+ juham_automation/automation/energycostcalculator.py,sha256=7GGKLv5JpHAY3XVjbkboXuQBk-whpWkBwNuQ68Tv4Pc,11091
6
+ juham_automation/automation/hotwateroptimizer.py,sha256=pLiYf284ggHdLOmQs2K7QaBbvbum5UBby8bzb48ddyY,21032
7
+ juham_automation/automation/powermeter_simulator.py,sha256=0g0gOD9WTqxUj9IbENkea_33JrJ2sZDSQVtmxVUHcD8,4688
8
+ juham_automation/automation/spothintafi.py,sha256=WcVvglrY3s9vfXl-CoxLJJkhgfZxpRff4I_VDrYKJYo,3863
9
+ juham_automation/automation/watercirculator.py,sha256=d7PQFNajtVafizS_y2R_6GWhm_GYb8uV4-QScz1Sggo,6569
10
+ juham_automation/ts/__init__.py,sha256=oRxMmzRj1l0z3sOx8uvm3kJzRrXCTJFzwEJ8zSniRSU,550
11
+ juham_automation/ts/electricityprice_ts.py,sha256=1lgXeLqNrou1Gd1salshlywR_rKNZhouMGEZv17pS9Q,1557
12
+ juham_automation/ts/energycostcalculator_ts.py,sha256=CAqhQVSFqM6WYzWTi-XRYCwJVmBOLIEmVmYdP97pAbw,1320
13
+ juham_automation/ts/forecast_ts.py,sha256=jn0-JEQ-GD_HtAsAbKi2Hm4PVEMtvOF4-JnTF-SPwGw,3255
14
+ juham_automation/ts/log_ts.py,sha256=DPfeJhbSMQChY37mjAxEmE73Ys3dxUvNsN78PSuBm9Y,1807
15
+ juham_automation/ts/power_ts.py,sha256=esNbtH1xklyUaf0YJQ2wDuxTAV3SnEfx-FtiBGPaSVA,1448
16
+ juham_automation/ts/powermeter_ts.py,sha256=zSATxZAzz1KJeU1wFK8CP86iySWnHil89mridz7WHos,2421
17
+ juham_automation/ts/powerplan_ts.py,sha256=-Lhc7v5Cj7USy2MfmyUEusXSox9UbEoDtYGReDEt3cw,1527
18
+ juham_automation-0.0.4.dist-info/LICENSE.rst,sha256=D3SSbUrv10lpAZ91lTMCQAke-MXMvrjFDsDyM3vEKJI,1114
19
+ juham_automation-0.0.4.dist-info/METADATA,sha256=HzBDsaoPoC2okQFY05knpkvLGv0TSCYVGKM2WTAQKoI,4727
20
+ juham_automation-0.0.4.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
21
+ juham_automation-0.0.4.dist-info/entry_points.txt,sha256=7yrw-Tdpm3xqJcxdUI5E5iSfSyd3s5Kj1-hAjB3aoHI,502
22
+ juham_automation-0.0.4.dist-info/top_level.txt,sha256=jfohvtocvX_gfT21AhJk7Iay5ZiQsS3HzrDjF7S4Qp0,17
23
+ juham_automation-0.0.4.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- juham_automation/__init__.py,sha256=ibC2uN4z7PHdkg-A4wcFrX91jU_PIhMwhcaBsZeFOdk,1035
2
- juham_automation/japp.py,sha256=HjCPU4mG6MLeZQztxw1e8NkWwg11peWBd27glJPQzYE,1931
3
- juham_automation/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
4
- juham_automation-0.0.2.dist-info/LICENSE.rst,sha256=D3SSbUrv10lpAZ91lTMCQAke-MXMvrjFDsDyM3vEKJI,1114
5
- juham_automation-0.0.2.dist-info/METADATA,sha256=RxItoeHCWpunLKgmTCt-1eGj-RFQoZhBoq9kTiMfl3o,4727
6
- juham_automation-0.0.2.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
7
- juham_automation-0.0.2.dist-info/entry_points.txt,sha256=7yrw-Tdpm3xqJcxdUI5E5iSfSyd3s5Kj1-hAjB3aoHI,502
8
- juham_automation-0.0.2.dist-info/top_level.txt,sha256=jfohvtocvX_gfT21AhJk7Iay5ZiQsS3HzrDjF7S4Qp0,17
9
- juham_automation-0.0.2.dist-info/RECORD,,