SSH Integration - Connect your servers to Home Assistant

Hi,

Just wanted to say that this is a great add-on. I have been trying to perform actions and update sensors from my ZFS Server to no avail.
Then I stumbled upon this and had my sensors up and running within minutes.

Fantastic,
Much appreciated

Yay, this is exactly what I was looking for! Thanks a lot for the add-on, I love it! :slight_smile:

This integration really hits a sweet spot! I’m using it for some parent work - checking and setting TimeKPR time budgets for my kids’ laptops and workstations (okay, typically “play”-stations).

One thing I didn’t get to work out: I’ve got a controllable sensor for “time left”. However, timekpr gives me times in seconds - and I’d like (my wife) to be able to enter times in minutes. I tried using @{value * 60} and tinkered with templates but to no real avail. There’s probably a simple solution… could anyone help?

Just discovered this integration and I’m very excited to use it, as it will solve one of my long lasting problems - quick turning on/off port forwarding on my router, that can only be done either via GUI (requires to expose it to internet :frowning: ) or via SSH CLI, that is troublesome due to login requirement…
So I installed integration and configured my router as first device… and got stuck. Not really sure how to configure properly this integration to perform what I want.

Command to turn on appropriate open port policy on my router is:
srv nat openport 1 1 -a 1

To turn it it off:
srv nat openport 1 1 -a 0

To get state of policy I use:
srv nat openport 1 1 -v

and it provides output:

%% Status: Disable
%% Comment: Remote Desktop
%% WAN Interface: WAN1
%% Private IP address: 192.168.52.32
%% Source ip type: 0
%% Source ip idx: 0
Index   Protocal        Start Port      End Port
*****************************************************************
  1.    TCP/UDP         3389            3389
  2.    TCP/UDP         0               0
  3.    TCP/UDP         0               0
  4.    TCP/UDP         0               0
  5.    TCP/UDP         0               0
  6.    TCP/UDP         0               0
  7.    TCP/UDP         0               0
  8.    TCP/UDP         0               0
  9.    TCP/UDP         0               0
  10.   TCP/UDP         0               0

So based on this information I created following configuration for my router, within SSH integration:
Action commands:

- command: srv nat openport 1 1 -a 1
  name: Turn RDP On
- command: srv nat openport 1 1 -a 0
  name: Turn RDP Off

and sensor command:

- command: srv nat openport 1 1 -v
  sensors:
    - type: text
      name: RDP State
      value_template: "{{ value.split(': ')[1] }}"

Value template might require some tuning, but for now should be sufficient to get Disable or Enable values.
But none of these does not work. As I look for Router device state it shows all of these entities unavailable:


So seems that while network connection and SSH connection to Router works fine, none of defined actions works… Waht am I doing wrong here?

Have you tried the full path to the srv command?

What you mean by full path? This is exactly what I enter in router console, when connecting from terminal.

If you type find / -name srv what path does it say. Probably /usr/sbin/srv or something

This is not Linux based router, but using custom operating system (DrayOS), so its CLI does not accept any commands, but these defined to manage device… Nor, it accepts path in commands. I’m limited to:

HOME-ROUTER> ?
% Valid commands are:
csm           ddns          dos           exit          internet      ip
ipf           log           ldap          tacacsplus    mngt          msubnet
object        port          portmaptime   ppa           hwaccswap     prn
qos           hwqos         quit          show          smb           srv
switch        sys           testmail      fs            upnp          usb
vigbrg        fullbrg       vlan          vpn           wan           hsportal
radius        local_8021x   wol           user          appqos        nand
apm           sfp           ethoam        ha            swm           fw_backupmode
cert          service       dmn

Just found this amazing SSH integration - truly amazing - got it up and running to monitor the temperature of my Coral TPUs in a Frigate Unraid server… so cool…

Getting the above to work was as simple as modifying an example, very easy to copy that but….

Can someone point me to an example or point me in the correct direction to get the following parsed into ideally four sensors.

.

One for Size, Used, Available, % Used
Any help would be greatly appreciated Thanks and well done on such a great add on

Hello,

I added the following sensor to my server which I added to home-assistant using ssh-integration

  • command: df -Hl
    scan_interval: 1440
    sensors:
    • type: text
      name: Disk Usage
      key: disk_usage
      icon: mdi:download-box-outline

The problem I have is that I only see the title of the output and not all the lines …

afbeelding

Output of df -Hl command on server
Filesystem Size Used Avail Use% Mounted on
tmpfs 824M 4.6M 820M 1% /run
efivarfs 132k 87k 40k 69% /sys/firmware/efi/efivars
/dev/sdb2 244G 210G 22G 91% /
tmpfs 4.2G 0 4.2G 0% /dev/shm
tmpfs 5.3M 0 5.3M 0% /run/lock
/dev/sdb1 1.2G 6.5M 1.2G 1% /boot/efi
/dev/sda1 2.0T 153G 1.8T 9% /data/downloads
tmpfs 824M 13k 824M 1% /run/user/1000

any idea?

Thx

To answer my own question, it reports unknown when there are No updates available. When there are, it’ll report a number. It would be great if it would report 0 instead of ‘unknown’

I just installed this great integration and came across the same issue (“updates available” sensor showing “unknown” instead of 0). Although I realize we are more than a year later, I share below a workaround I found in case it can still help someone:

Instead of the original syntax

- command: apt-get -s -o Debug::NoLocking=true upgrade |grep -c ^Inst

use this one:

- command: >-
    resp=$(apt-get -s -q -o Debug::NoLocking=true upgrade | grep -c ^Inst);echo $resp

Although both (expectedly) show an identical result in the console, for some reason that I’m not smart enough to figure out, only the second variant (that echoes the result through an intermediate variable) will have a 0-value properly imported as 0.

1 Like