bkbilly / lnxlink

🖥 Effortlessly manage your Linux machine using MQTT.

Home Page:https://bkbilly.gitbook.io/lnxlink

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Battery status not showing in HA

hermannw opened this issue · comments

What type of installation are you running?

Desktop

Which Linux OS are you using?

Linux Mint Mate

Which version of LNXLink has the issue?

2023.6.1

The problem

Hi, me again :-)
I got everything installed and running. The messages are all showing correct in MQTT Explorer. Most of the values are also shown and updated regularly in Home Assistant, except the one that is most important to me: Battery status.
MQTT Explorer shows for example this:
battery = {"status": 51.0, "SanyoDELL 5K1GW03G": 51.0, "Wacom HID 482D": 0.0}
The Battery icon is shown in HA, but when I click it, it shows:

image

Also: Would it be possible to add the CPU temperature to the outputs? I have seen the examples on the website, but my Python programming skills are a bit limited...

Logs

No response

I am not sure there is a way to distinguish the CPU temperature out of all the temperature sensors on your system, but I'll see what I can do.

You should check through MQTT Explorer if the state is sent in a regular interval. If it is not, then it automatically becomes unavailable.
You should also send me the logs. This is the command that will give you the logs:
journalctl --user -u lnxlink -n 300 --no-pager

It looks like the state of the battery is sent to HA only once (and it is retained) about 8 minutes after the tablet starts. But I cannot see any value sent.
image

This is the part that journalctl shows for today:

-- Boot 0bad024ec53244c29471402668995f66 --
Jun 25 10:30:36 hermann-Latitude-5175 systemd[941]: Started LNXlink.
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]: LNXlink 2023.6.1 started: 3.10.6
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]: Loaded addon: battery
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]: Loaded addon: cpu
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]: Loaded addon: idle
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]: Loaded addon: screen_onoff
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]: Loaded addon: bash
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]: Loaded addon: boot_select
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]: Loaded addon: brightness
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]: Loaded addon: camera_used
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]: Loaded addon: disk_usage
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]: Loaded addon: keep_alive
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]: Loaded addon: media
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]: Loaded addon: memory
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]: Loaded addon: microphone_used
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]: Loaded addon: network
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]: Loaded addon: notify
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]: Loaded addon: required_restart
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]: Loaded addon: restart
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]: Loaded addon: send_keys
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]: Loaded addon: shutdown
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]: Loaded addon: suspend
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]: Loaded addon: webcam
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]: Loaded addon: xdg_open
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]: Traceback (most recent call last):
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]:   File "/home/hermann/.local/bin/lnxlink", line 8, in <module>
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]:     sys.exit(main())
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]:   File "/home/hermann/.local/lib/python3.10/site-packages/lnxlink/__main__.py", line 335, in main
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]:     lnxlink = LNXlink(config_file)
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]:   File "/home/hermann/.local/lib/python3.10/site-packages/lnxlink/__main__.py", line 42, in __init__
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]:     self.setup_mqtt()
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]:   File "/home/hermann/.local/lib/python3.10/site-packages/lnxlink/__main__.py", line 102, in setup_mqtt
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]:     self.client.connect(self.config['mqtt']['server'], self.config['mqtt']['port'], 60)
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]:   File "/home/hermann/.local/lib/python3.10/site-packages/paho/mqtt/client.py", line 914, in connect
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]:     return self.reconnect()
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]:   File "/home/hermann/.local/lib/python3.10/site-packages/paho/mqtt/client.py", line 1044, in reconnect
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]:     sock = self._create_socket_connection()
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]:   File "/home/hermann/.local/lib/python3.10/site-packages/paho/mqtt/client.py", line 3685, in _create_socket_connection
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]:     return socket.create_connection(addr, timeout=self._connect_timeout, source_address=source)
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]:   File "/usr/lib/python3.10/socket.py", line 845, in create_connection
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]:     raise err
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]:   File "/usr/lib/python3.10/socket.py", line 833, in create_connection
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]:     sock.connect(sa)
Jun 25 10:30:37 hermann-Latitude-5175 lnxlink[950]: OSError: [Errno 101] Network is unreachable
Jun 25 10:30:37 hermann-Latitude-5175 systemd[941]: lnxlink.service: Main process exited, code=exited, status=1/FAILURE
Jun 25 10:30:37 hermann-Latitude-5175 systemd[941]: lnxlink.service: Failed with result 'exit-code'.
Jun 25 10:30:37 hermann-Latitude-5175 systemd[941]: lnxlink.service: Consumed 1.360s CPU time.
Jun 25 10:30:38 hermann-Latitude-5175 systemd[941]: lnxlink.service: Scheduled restart job, restart counter is at 1.
Jun 25 10:30:38 hermann-Latitude-5175 systemd[941]: Stopped LNXlink.
Jun 25 10:30:38 hermann-Latitude-5175 systemd[941]: lnxlink.service: Consumed 1.360s CPU time.
Jun 25 10:30:38 hermann-Latitude-5175 systemd[941]: Started LNXlink.

It seems that a lot of the logs after are missing.
Can you run it manually to get the error logs?

Follow these commands by replacing the config.yaml with your config file that you've used:

systemctl --user stop lnxlink.service
lnxlink -c config.yaml

When I run lnxlink from my home directory (where config.yaml is), I get this:

hermann@hermann-Latitude-5175:~$ lnxlink -c config.yaml
LNXlink 2023.6.1 started: 3.10.6
Loaded addon: battery
Loaded addon: cpu
Loaded addon: idle
Loaded addon: screen_onoff
Loaded addon: bash
Loaded addon: boot_select
Loaded addon: brightness
Loaded addon: camera_used
Loaded addon: disk_usage
Loaded addon: keep_alive
Loaded addon: media
Loaded addon: memory
Loaded addon: microphone_used
Loaded addon: network
Loaded addon: notify
Loaded addon: required_restart
Loaded addon: restart
Loaded addon: send_keys
Loaded addon: shutdown
Loaded addon: suspend
Loaded addon: webcam
Loaded addon: xdg_open
Connected to MQTT with code 0
Can't load addon: idle
Traceback (most recent call last):
  File "/home/hermann/.local/lib/python3.10/site-packages/lnxlink/__main__.py", line 77, in monitor_run
    pub_data = addon.getInfo()
  File "/home/hermann/.local/lib/python3.10/site-packages/lnxlink/modules/idle.py", line 16, in getInfo
    idle_ms = monitor.get_dbus_idle()
  File "/home/hermann/.local/lib/python3.10/site-packages/dbus_idle/__init__.py", line 105, in get_dbus_idle
    idle_sec = int(stdout.strip())
ValueError: invalid literal for int() with base 10: ''
Can't load addon: brightness
Traceback (most recent call last):
  File "/home/hermann/.local/lib/python3.10/site-packages/lnxlink/__main__.py", line 81, in monitor_run
    pub_data = addon.getControlInfo()
  File "/home/hermann/.local/lib/python3.10/site-packages/lnxlink/modules/brightness.py", line 12, in getControlInfo
    avg_brightness = sum(displays.values()) / len(displays.values())
ZeroDivisionError: division by zero
Can't load addon: idle
Traceback (most recent call last):
  File "/home/hermann/.local/lib/python3.10/site-packages/lnxlink/__main__.py", line 77, in monitor_run
    pub_data = addon.getInfo()
  File "/home/hermann/.local/lib/python3.10/site-packages/lnxlink/modules/idle.py", line 16, in getInfo
    idle_ms = monitor.get_dbus_idle()
  File "/home/hermann/.local/lib/python3.10/site-packages/dbus_idle/__init__.py", line 105, in get_dbus_idle
    idle_sec = int(stdout.strip())
ValueError: invalid literal for int() with base 10: ''
Can't load addon: brightness
Traceback (most recent call last):
  File "/home/hermann/.local/lib/python3.10/site-packages/lnxlink/__main__.py", line 81, in monitor_run
    pub_data = addon.getControlInfo()
  File "/home/hermann/.local/lib/python3.10/site-packages/lnxlink/modules/brightness.py", line 12, in getControlInfo
    avg_brightness = sum(displays.values()) / len(displays.values())
ZeroDivisionError: division by zero

The Traceback... lines are then repeated every few seconds. It is interesting that it says cannot load idle and brightness. When I run this as a service, I see the value of idle changing and I can set the brightness of the screen from HA.
Is there any other log I can check?

The config.yaml looks like this:


mqtt:
  prefix: lnxlink
  clientId: DESKTOP-Linux
  statsPrefix: monitor/stats
  server: 192.168.1.120
  port: 1883
  auth:
    user:
    pass:
  discovery:
    enabled: true
  lwt:
    enabled: true
    qos: 1
    retain: true
    connectMsg: 'ON'
    disconnectMsg: 'OFF'
update_interval: 5
modules:
- battery
- cpu
- idle
- screen_onoff
- bash
- boot_select
- brightness
- camera_used
- disk_usage
- keep_alive
- media
- memory
- microphone_used
- network
- notify
- required_restart
- restart
- send_keys
- shutdown
- suspend
- webcam
- xdg_open

You can check if the individual commands work. Send me the results to see what's the problem.

For Brightness

xrandr --verbose --current | grep Brightness

For Idle

python3.10
from dbus_idle import IdleMonitor
float(IdleMonitor.get_monitor().get_dbus_idle())

Not sure what changed today, but

lnxlink -c config.yaml 

did not give me any more errors.

hermann@hermann-Latitude-5175:~$ lnxlink -c config.yaml
LNXlink 2023.6.1 started: 3.10.6
Loaded addon: battery
Loaded addon: cpu
Loaded addon: idle
Loaded addon: screen_onoff
Loaded addon: bash
Loaded addon: boot_select
Loaded addon: brightness
Loaded addon: camera_used
Loaded addon: disk_usage
Loaded addon: keep_alive
Loaded addon: media
Loaded addon: memory
Loaded addon: microphone_used
Loaded addon: network
Loaded addon: notify
Loaded addon: required_restart
Loaded addon: restart
Loaded addon: send_keys
Loaded addon: shutdown
Loaded addon: suspend
Loaded addon: webcam
Loaded addon: xdg_open
Connected to MQTT with code 0
hermann@hermann-Latitude-5175:~$ xrandr --verbose --current | grep Brightness
	Brightness: 1.0

This changes to the value I set in HA.

hermann@hermann-Latitude-5175:~$ python3.10
Python 3.10.6 (main, May 29 2023, 11:10:38) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from dbus_idle import IdleMonitor
>>> float(IdleMonitor.get_monitor().get_dbus_idle())
6.0
>>> float(IdleMonitor.get_monitor().get_dbus_idle())
8.0
>>> float(IdleMonitor.get_monitor().get_dbus_idle())
7.0
>>> 

The numbers keep changing every time I call it.

The value changes because it only measures milliseconds and its the time you last moved the mouse or pressed a key.

Seems that the issue has been fixed for you, so I am going to close it.
Feel free to open it's not the case.

I worked around it by reading the MQTT values with node-red.