feat: measure home energy usage
Some checks failed
Build / build (push) Has been cancelled

This commit is contained in:
Daniel Kempkens 2024-08-03 20:55:56 +02:00
parent 495723fb32
commit 1066a980de
Signed by: daniel
SSH key fingerprint: SHA256:Ks/MyhQYcPRQiwMKLAKquWCdCPe3JXlb1WttgnAoSeM

View file

@ -57,6 +57,29 @@ defmodule WeewxProxy.Modbus.Deye do
{:ok, state} {:ok, state}
end end
@impl true
def handle_message(["bitshake", "tele", "smartmeter", topic], publish, state) do
if topic == "SENSOR" do
{:ok, meter_data} = Jason.decode(publish)
timestamp = DateTime.utc_now() |> DateTime.to_unix()
day = get_in(meter_data, ["eBZ", "E_in"])
active = get_in(meter_data, ["eBZ", "Power"])
mqtt_data = %{
dateTime: timestamp,
homeEnergyDay: day,
homeEnergyActive: active
}
:ok = Publisher.publish("weewx/ingest_si", mqtt_data)
{:ok, state}
else
{:ok, state}
end
end
@impl true @impl true
def handle_message(topic, publish, state) do def handle_message(topic, publish, state) do
full_topic = Enum.join(topic, "/") full_topic = Enum.join(topic, "/")