This is a Linux service for integrating your system with an external application like Home Assistant using MQTT. It is inspired by IOT Link.
- System control: Shutdown, Restart, Send Keys, Notify, Media, Screen On/Off, open URL/File, bash.
- System monitor: CPU, Ram, Network, Media, Microphone, Idle, Bluetooth battery.
- Home Assistant: Uses MQTT Autodiscovery to create entities.
- No sudo required: No need to be root user to install and use, unless used on server setup.
- Easily expanded: Any new module is automatically imported.
Install or update:
sudo apt install patchelf meson libdbus-glib-1-dev libglib2.0-dev libasound2-dev python3-pip
pip3 install -U lnxlink
# When asked, it's recommended to install as a user service.
lnxlink -c config.yaml
You can manually update the configuration file config.yaml
and restart the service with the use of systemctl:
systemctl --user restart lnxlink.service
The headless installation is used for linux environments that don't use a Graphical Interface like servers.
sudo apt install patchelf meson libdbus-glib-1-dev libglib2.0-dev libasound2-dev python3-pip
sudo pip3 install -U lnxlink
# When asked, it's recommended to answer false on install as a user service.
sudo lnxlink -c config.yaml
Some modules depend on graphical interface, so if you choose to use this option for installation, you will have to find which ones stop lnxlink from starting and remove them from the config file.
sudo systemctl restart lnxlink.service
service: mqtt.publish
data:
topic: {prefix}/{clientId}/commands/notify
payload: >-
{ "title": "Notification Title",
"message": "Testing notification",
"iconUrl": "http://hass.local:8123/local/myimage.jpg" }
service: mqtt.publish
data:
topic: {prefix}/{clientId}/commands/send_keys
payload: "<CTRL>+t"
service: mqtt.publish
data:
topic: {prefix}/{clientId}/commands/bash
payload: "xdotool key ctrl+t"
service: mqtt.publish
data:
topic: lnxlink/desktop-linux/commands/xdg_open
payload: "https://www.google.com" # or "myimg.jpeg" for file
Combine with Wake on Lan to control your PC with one switch:
switch:
- platform: template
switches:
my_pc:
friendly_name: "My PC"
unique_id: my_pc
value_template: "{{ not is_state('button.shutdown', 'unavailable') }}"
turn_on:
service: switch.turn_on
data:
entity_id: switch.pc_wol
turn_off:
service: button.press
data:
entity_id: button.shutdown
Create a media player using mqtt-mediaplayer using the information collected from the media sensor:
Your config file is located at the directory you were when you first run lnxlink. This can be anything you write instead of the config.yaml
that I suggested. You can find where it is from the systemd service:
cat ~/.config/systemd/user/lnxlink.service | grep -i ExecStart
If you want to create the service from scratch, you will have to disable the running service and start lnxlink again:
systemctl --user disable lnxlink.service
lnxlink -c config.yaml
Idle time module is dependend on idle-time which only supports Gnome Mutter for now. If you want support for this, you can install the newest version from my github:
pip3 uninstall idle_time
pip3 install 'idle_time @ git+https://github.com/bkbilly/idle_time.git'
systemctl --user restart lnxlink.service
Technical Notes (click to expand)
To expand the supported features, create a new python file on modules folder and use this template:
class Addon():
name = 'Example'
icon = 'mdi:home-assistant'
unit = ''
def startControl(self, topic, data):
''' When a command is sent, it will run this method '''
print(topic, data)
def getInfo(self):
''' Returns any type that can be converted to JSON '''
return 15
def exposedControls(self):
''' Optional method which exposes an entity '''
return {
"mybutton": {
"type": "button",
"icon": "mdi:button-cursor",
}
}