đ ī¸Development
You can easily create your own modules for exposing any sensor you want for controlling or monitoring it.
How to start
Create a python app yourmodule.py
with a unique name which starts with the class Addon:
Get Sensor information
The method get_info
should return the value of the sensor you want to create. This can be one of these categories:
String
Integer
Boolean
JSON that contains keys with any of the above types
Control System
You can write the command you want to run when the topic containing the commands
string is published to the MQTT server. The argument topic is a list separated with a slash (/
). The argument data is a string or a json.
Expose Sensors and Controls
A new method under the Addon
class has to be created which returns a dictionary with options specific for the sensor you want:
Bellow you can read more about each available option
type
This is required which is responsible for sending the appropriate type of command to the discovery of home assistant. These are the available types that are supported:
sensor
binary_sensor
button
switch
text
number
select
camera
image
update
value_template
This is required only if the get_info
method returns a dictionary and you want to get a value from that to display. You can change the status to the dictionary key you want:
attributes_template
This will add attributes under the sensor that is created. It is recommended that these attributes should not change because it will populate the Home Assistant database.
icon
Any icon supported by home assistant can be added. More information on their site.
unit
This is used only for types sensor
and number
which defines the unit of measurement of the sensor.
device_class
This is used for the sensors binary_sensor
, button
, number
, sensor
, switch
, update
and defines. Each sensor has different options, so you will have to read the documentation on each integration on Home Assistant website.
state_class
This is used only for the type sensor
which is described here. These are the available options:
measurement
total
total_increasing
entity_category
This changes the category of the sensor to be one of these:
diagnostic
config
enabled
It tells home assistant to enable or disable the entity. By default it is True
.
entity_picture
This is used only for the update
sensor.
title
This is used only for the update
sensor.
expire_after
This is used only for types sensor
and binary_sensor
which defines the number of seconds after the sensorâs state expires, if itâs not updated. After expiry, the sensorâs state becomes unavailable
.
install
This is used only for update
sensor. It can be anything and it's used to enable the install option on Home Assistant.
Last updated