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


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


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:


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/", line 149, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/local/lib/python3.7/asyncio/", line 442, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.7/asyncio/", line 120, in coro
    res = func(*args, **kw)
  File "/config/custom_components/ssh/", line 48, in async_setup_platform
    dev.append(SSHSensor(hass, config))
  File "/config/custom_components/ssh/", line 66, in __init__
  File "/config/custom_components/ssh/", line 137, in _connect
    password=self._password, port=self._port)
  File "/usr/local/lib/python3.7/site-packages/pexpect/", 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.

Thanks for the project. It was almost exactly what I needed, but I couldn’t get it working with the pexpect library for my usage needs. So, I developed a similar sensor and also a switch component that works across the ssh tunnel using the paramiko library. Any interest in consolidating and submitting to the core code of hass?

To all,
So far, I am still working out the final bugs, so, use my code at your own risk.

1 Like

Yes my time to spend on this is very limited currently, but happy for you to take things on and will help where I can!