LNXlink
GitHubDiscordPayPal
  • 🌩️LNXlink
  • 🖥️Setup
  • 📂Configuration
  • 🎬Media Player
  • 🔗Modules Settings
  • 🔱Modules Usage
  • 🤯Automations
  • 🛠️Development
Powered by GitBook
On this page
  • How to start
  • Get Sensor information
  • Control System
  • Expose Sensors and Controls

Development

For simple tasks, use the bash module, but for more advanced control or monitoring, you can create custom modules to expose any sensor.

How to start

Create a python app yourmodule.py with a unique name which starts with the class Addon:

class Addon():
    """Addon module"""

    def __init__(self, lnxlink):
        """Setup addon"""
        self.name = "New Module"

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

    def get_info(self):
        """Gather information from the system"""
        return {
            "status": 5
        }

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.

    def start_control(self, topic, data):
        """Control system"""
        print(topic)
        print(data)

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:

    def exposed_controls(self):
        """Exposes to home assistant"""
        return {
            "New Module": {
                "type": "sensor",
            },
        }

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:

  "value_template": "{{ value_json.status }}"

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.

  "attributes_template": "{{ value_json.get('attributes') | tojson }}"

icon

  "icon": "mdi:battery"

unit

This is used only for types sensor and number which defines the unit of measurement of the sensor.

  "unit": "%"

device_class

  "device_class": "battery"

state_class

  • measurement

  • total

  • total_increasing

  "state_class": "measurement"

entity_category

This changes the category of the sensor to be one of these:

  • diagnostic

  • config

  "entity_category": "diagnostic"

enabled

It tells home assistant to enable or disable the entity. By default it is True.

  "enabled": False

entity_picture

This is used only for the update sensor.

  "entity_picture": "https://github.com/bkbilly/lnxlink/raw/master/logo.png?raw=true"

title

This is used only for the update sensor.

  "title": "LNXlink"

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.

  "expire_after": 5

install

This is used only for update sensor. It can be anything and it's used to enable the install option on Home Assistant.

  "install": "install"

PreviousAutomations

Last updated 13 days ago

Any icon supported by home assistant can be added. More information on their .

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 .

This is used only for the type sensor which is described . These are the available options:

🛠️
site
Home Assistant website
here