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.
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.
DSL Channel1 | LowerLayer Line1
----------------------------------------------------------------------
Current upstream bit rate | 5119
Current downstream bit rate | 42091
----------------------------------------------------------------------
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.
John,
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.
Just wanted to follow up with anyone who might find this thread. I’ve created an alternative ssh custom_componet that allows both a sensor and/or switch.
Thank you! I’ve installed your component and was able to create a switch that enables/disables internet on particular device using OpenWRT firewall rule. Here is my config that might save somebody some time as an example:
I had issues with key field. It is mandatory but in case base64.b64decode function fails there is “Connection refused. SSH enabled?” error anyway. So it’s important for key to be in base64 format.
Sorry, I’ve already shared everything I can. As I remember, that kind of error happens not only if connection is really refused, there might be other reason as well.
I found a name at unapplied changes inside Luci interface. Just pressed Save instead of Save&Apply and checked the name of the rule. Not sure it is truly persistent but it didn’t change since that time.
Logger: homeassistant.components.sensor
Source: custom_components/ssh/sensor.py:136
Integration: Сенсор (documentation, issues)
First occurred: 20:30:53 (1 occurrences)
Last logged: 20:30:53
Error while setting up ssh platform for sensor
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 249, in _async_setup_platform
await asyncio.shield(task)
File "/usr/local/lib/python3.9/asyncio/coroutines.py", line 124, 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 136, in _connect
self._ssh.login(self._host, self._username,
File "/usr/local/lib/python3.9/site-packages/pexpect/pxssh.py", line 386, in login
raise ExceptionPxssh('Could not establish connection to host')
pexpect.pxssh.ExceptionPxssh: Could not establish connection to host