zhbjsh/homeassistant-ssh

Systemd switch not working as expected

Closed this issue · 1 comments

Hi Adrian,
Copying your example systemctl -a | awk '/hyperion.service|pure-ftpd.service/ {print $1 "," $4}' create the switch just when the service is running.
As soon as the switch is turned off, it became unavaiable I suppose because the systemctl -a does not return anything if the service is not active.

2024-04-14 00:32:27.306 DEBUG (MainThread) [custom_components.ssh] raspberrypi: systemctl -a | awk '/kodi.service|hyperion.service|drm-capture.service|pure-ftpd.service/ {print $1 "," $4}' => ['hyperion.service,running'], [], 0
2024-04-14 00:32:27.307 DEBUG (MainThread) [custom_components.ssh] raspberrypi: service_hyperion_service => True
2024-04-14 00:32:27.307 DEBUG (MainThread) [custom_components.ssh] Finished fetching raspberrypi service data in 0.037 seconds (success: True)

image

Do you have any suggestion?
Thank you

Hi!

If systemctl -a doesnt list inactive services, you could create a static switch for each service, maybe you could try something like this:

- command: systemctl is-active kodi.service || true
  scan_interval: 300
  sensors:
    - type: binary
      name: Kodi
      command_on: systemctl start kodi.service
      command_off: systemctl stop kodi.service
      payload_on: active

Let me know if it works for you!