SSH Sensor

I’ve been having some issues with the site to site VPN on my UniFi USG and some details are only available at the command line after logging in via SSH. There is no apparent way to access this data any other way.

The result is a SSH sensor, which performs a remote login to a server, executes a command and returns the result.

Based on the Unifi AP Direct device_tracker source and the pexpect library.

Now available at

1 Like

Very nice,
is there a way to query this sensor only on demand. In my case i need a value once a day or only when i trigger it.

Geetings from germany

This is in 0.81.0

We have a new service home_assistant.update_entity to request the update of an entity, rather than waiting for the next scheduled update. This means you can set a really long scan_interval in the platform_options and then update on demand, ideal for those services where you have low API limit.

1 Like

Sensor has now belatedly been update to the new file structure

Hi

SSH password is still required. Kinda not safe…How about SSH key??

Is it possible to use several commands to get data?

I have modem which gives response only after several commands:
When logging I have this:

ADB#

to get data I need to enter:

ADB#configure (enter)
ADB(cfg)#interface (enter)
ADB(cfg-intf)#dsl Line1 (enter)
ADB(cfg-intf-dsl:Line1)#show_dslChannels (enter)

only then I get data:

DSL Channel1                   |  LowerLayer Line1
----------------------------------------------------------------------
Current upstream bit rate      |  5119
Current downstream bit rate    |  42091
----------------------------------------------------------------------

Would it be possible with this sensor?

I believe you should be able to simply put in semi colons to issue a series of commands, e.g.

cd testdirectory;ls

would show the contents of the sub-directory rather than the current one. I believe that should work, although I havn’t tested. Please let us know how you get on.

Tried with command: configure;interface;dsl Line1;show_dslChannels

Got this error:

Error while setting up platform ssh
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 149, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.7/asyncio/coroutines.py", line 120, in coro
    res = func(*args, **kw)
  File "/config/custom_components/ssh/sensor.py", line 48, in async_setup_platform
    dev.append(SSHSensor(hass, config))
  File "/config/custom_components/ssh/sensor.py", line 66, in __init__
    self._connect()
  File "/config/custom_components/ssh/sensor.py", line 137, in _connect
    password=self._password, port=self._port)
  File "/usr/local/lib/python3.7/site-packages/pexpect/pxssh.py", line 434, in login
    self.before, self.PROMPT,))
pexpect.pxssh.ExceptionPxssh: could not set shell prompt (received: b" unset\r\nERROR: unknown command\r\nADB# \x07PROMPT_COMMAND\r\nERROR: unknown command\r\nADB# \x07PS1='[PEXPECT]\\$\r\nERROR: unknown command\r\nADB# \x07'\r\nERROR: unknown command\r\nADB# \x07set\r\nERROR: unknown command\r\nADB# \x07prompt='[PEXPECT]\\$\r\nERROR: unknown command\r\nADB# \x07'\r\nERROR: unknown command\r\nADB# \x07", expected: '\\[PEXPECT\\][\\$\\#] ').

In last line it does get to ADB# part so I guess login was successful.