diff --git a/lib/weewx_proxy/http/ecowitt.ex b/lib/weewx_proxy/http/ecowitt.ex index 5c26b5b..002a261 100644 --- a/lib/weewx_proxy/http/ecowitt.ex +++ b/lib/weewx_proxy/http/ecowitt.ex @@ -24,7 +24,15 @@ defmodule WeewxProxy.HTTP.Ecowitt do _ = Logger.debug("Removing keys: `#{inspect(sdr_keys)}'") partial_data = Map.drop(data, sdr_keys) :ok = Publisher.publish("weewx/ingest_us", partial_data) - Publisher.publish_value_map("hadata/weewx/us", partial_data) + :ok = Publisher.publish_value_map("hadata/weewx/us", partial_data) + + hadata_si = convert_data_ha(partial_data) + + if map_size(hadata_si) > 0 do + Publisher.publish_value_map("hadata/weewx/si", hadata_si) + else + :ok + end else _ = Logger.error("Not publishing record because data appears invalid: #{inspect(data)}") :ok @@ -121,4 +129,17 @@ defmodule WeewxProxy.HTTP.Ecowitt do defp valid_data?(data) do Map.has_key?(data, :outTemp) and is_number(data.outTemp) end + + @spec convert_data_ha(map()) :: map() + defp convert_data_ha(data) do + result = %{} + + result = if Map.has_key?(data, :outTemp), do: Map.put(result, :outTemp, (data.outTemp - 32.0) / 1.8), else: result + result = if Map.has_key?(data, :outHumidity), do: Map.put(result, :outHumidity, data.outHumidity), else: result + + result = if Map.has_key?(data, :inTemp), do: Map.put(result, :inTemp, (data.inTemp - 32.0) / 1.8), else: result + result = if Map.has_key?(data, :inHumidity), do: Map.put(result, :inHumidity, data.inHumidity), else: result + + result + end end