# `Homex.Entity.Sensor`
[🔗](https://github.com/kevinschweikert/homex/blob/v0.1.2/lib/homex/entity/sensor.ex#L1)

A sensor entity for Homex

Implements a `Homex.Entity`. See module for available callbacks.

https://www.home-assistant.io/integrations/sensor.mqtt/

## Options

* `:name` (`t:String.t/0`) - Required. the name of the entity

* `:update_interval` - the interval in milliseconds in which `handle_timer/1` get's called. Can also be `:never` to disable the timer callback The default value is `10000`.

* `:retain` (`t:boolean/0`) - if the last state should be retained The default value is `false`.

* `:state_class` - Type of state. If not `nil`, the sensor is assumed to be numerical and will be displayed as a line-chart in the frontend instead of as discrete values. The default value is `nil`.

* `:device_class` - Type of sensor. Available device classes: https://developers.home-assistant.io/docs/core/entity/sensor/#available-device-classes The default value is `nil`.

* `:unit_of_measurement` - The unit of measurement that the sensor's value is expressed in. Available units in depending on device class (see second column): https://developers.home-assistant.io/docs/core/entity/sensor/#available-device-classes The default value is `nil`.

## Overridable Functions

The following functions can be overridden in your entity:

* `handle_init/1` - From `Homex.Entity`
* `handle_timer/1` - From `Homex.Entity`

### Default Implementations

All overridable functions have safe default implementations that return the entity unchanged.
You only need to override the functions you want to customize.

## Example

```elixir
defmodule MyTemperature do
  use Homex.Entity.Sensor,
    name: "my-temperature",
    unit_of_measurement: "°C",
    device_class: "temperature"

  def handle_timer(entity) do
    value = Sensor.read()
    entity |> set_value(value)
  end
end
```

# `set_value`

```elixir
@callback set_value(entity :: Homex.Entity.t(), value :: term()) ::
  entity :: Homex.Entity.t()
```

Sets the entity value

---

*Consult [api-reference.md](api-reference.md) for complete listing*
