Dear community, I’ve started to get (cue the late Steve Erwin’s voice) ‘weally weally daingerwous’ with HA
Yet I’m running into authentication problems getting remote ssh command based sensor results, following the directions for remote ssh, keygen and key upload above. Hoping somebody might be able to shed some light on what I’m missing
Setup: HA running in a virtual machine with MQTT broker, Zig and Zwave are radios running on a couple of Pi’s. All is working well, yet I’d like to monitor things like CPU temperature, pulling it over a remote ssh commandline.
However I’m unfortunately not seeing much success as I get no sensor updates and the HA server log has a ton of repeated entries like this:
However the wheels come off the cart when I implement the sensor in my configuration.yaml
sensor:
platform: command_line #<—forum is making the dash into a dot :-/
name: ZigPi CPU
command: “ssh [email protected] ‘cat /sys/class/thermal/thermal_zone0/temp’”
unit_of_measurement: “°C”
value_template: ‘{{ value | multiply(0.001) }}’
As soon as I validate the configuration and restart the HA server, the above logfile entries keep piling up and the sensor on the Overview appears but is empty as a result. If anyone has suggestions as how to troubleshoot this ,I’m all appreciative ears!
I had forgotten my earlier difficulty with this. When I setup up the ssh keys, I did so logged on as homeassistant. I could run my script manually, but not within an automation.
When homeassistant runs the script it does so as root, which makes the script fail because it looks for the credentials in /root/.ssh.
This is part of a script that is called via platform: command_line.
That makes good sense, yet how would one go about doing that on HomeAssistant OS? I’m already SSH’ed in as root and besides there’s no sudo available on HassOS.
Thinking out loud, perhaps the keyfile is in the wrong place?
Currently it’s being generated by ssh-keygen as /root/.ssh/id_rsa - could this be it or is HA executing the call with another user than root perhaps?
Thank you sir! - I’ve been playing around (wrestling) with this for a couple of days now, and finally saw some success. I tried the command line options as referenced in the link you provided, yet I found out (mostly by google, trial and error) that the -o UserKnownHostFile=/dev/null does not seem to work). Second, I did not have the /config/.ssh/ folder, so I had to create it and copy in the ID file. Something does not like referencing the file in /root/.ssh… Anyway this is what I ended up with for my sensor. Thanks again!
I followed your last message and did what you did I.e.
In the bash I created a folder I.e. config/ssh/key but then when I try to copy the generated file to the folder it somehow doesn’t work.
Hi @bachoo - you’re creating the config/.ssh folders in the root path right? Either way, I’m running the above against 2 separate pi’s respectively running Raspian Stretch and Buster, both seems to work nicely. I built out the same mechanism to report RSSI (wifi signal strength) on the pi’s using this entry:
The referenced shellscript rssi.sh just contains the line below, but I kept it as a script so I could tinker some more (awk is afaik preinstalled, but you may want to check)
I do this with multiple machines, using the same command via ssh. I show them in a Horizontal Stack card with guage card children. Here’s my lovelace display configuration for that (my temps are fahrenheit):
You don’t want to, that’s for one of my machines. You want to find and use the id of the sensor you created for your machine. Based on your first post my best guess it that it’s:
sensor.cpu_temperature
You should probably use Configuration - Devices & Services - Entities to find it though. And if you only have the one sensor you probably don’t want to put it in a horizontal stock card either, just add a guage card for it directly.
I’m in the US, so I know F, but all chip spec’s are in C, and I would actually prefer that also. However no matter what I tried I never could get a sensible value in C with my primary HA unit of measure set to F, I gave up on it.
I’ve gotten the Raspberry Pi temperature into HA using the old template format, but I can’t work out how to do it in the modern format. I’d like to try to stay with the modern format. Can anyone point out what I’m doing wrong?