Homex.Entity.Sensor behaviour (homex v0.1.0)
View SourceA sensor entity for Homex
Implements a Homex.Entity. See module for available callbacks.
https://www.home-assistant.io/integrations/sensor.mqtt/
Options
:name(String.t/0) - Required. the name of the entity:update_interval- the interval in milliseconds in whichhandle_timer/1get's called. Can also be:neverto disable the timer callback The default value is10000.:retain(boolean/0) - if the last state should be retained The default value isfalse.:state_class- Type of state. If notnil, 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 isnil.:device_class- Type of sensor. Available device classes: https://developers.home-assistant.io/docs/core/entity/sensor/#available-device-classes The default value isnil.: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 isnil.
Overridable Functions
The following functions can be overridden in your entity:
handle_init/1- FromHomex.Entityhandle_timer/1- FromHomex.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
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
Summary
Callbacks
Sets the entity value
Callbacks
@callback set_value(entity :: Homex.Entity.t(), value :: term()) :: entity :: Homex.Entity.t()
Sets the entity value