Nerves Home Assistant integration

Just a quick update:

The project is called homex and can be found at GitHub - kevinschweikert/homex: A bridge between Elixir and Home Assistant · GitHub .

There is a nerves example project at GitHub - kevinschweikert/Homex-Nerves-Example: An example project using Homex in Nerves · GitHub

I’m currenlty waiting on a new Hex release of the emqtt library which i am using as the MQTT client.

Some sample code:

defmodule HomexDemo.TemperatureSensor do
  @moduledoc """
  A Homex.Entity for the BME680 sensors temperature values
  """

  use Homex.Entity.Sensor,
    name: "bme680 temp",
    device_class: "temperature",
    unit_of_measurement: "°C"

  def handle_timer(entity) do
    {:ok, measurements} = BMP280.measure(BME680)
    entity |> set_value(Float.round(measurements.temperature_c, 2))
  end
end
defmodule HomexDemo.Relay do
  @moduledoc """
  A Homex.Entity for a relay.
  Uses `put_private/3` and `get_private/2` to keep the i2c bus handle in state and reference it
  """

  use Homex.Entity.Switch, name: "quiick_relay"

  def handle_init(entity) do
    {:ok, bus} = Circuits.I2C.open("i2c-1")
    entity |> put_private(:bus, bus) |> set_off()
  end

  def handle_on(entity) do
    bus = entity |> get_private(:bus)
    Circuits.I2C.write!(bus, 0x18, <<0x01>>)
    entity
  end

  def handle_off(entity) do
    bus = entity |> get_private(:bus)
    Circuits.I2C.write!(bus, 0x18, <<0x00>>)
    entity
  end
end

and some pictures

i will write an announcement post when the hex version is published. But in the meantime feel free to play around with it and give feedback!

8 Likes