#Assistance with command_line sensor

1 messages · Page 1 of 1 (latest)

tranquil spoke
#

I am struggling with a command_line sensor I am trying to add to my configuration.yaml so that I can send an SSH command that retrieves the nvme drive temperature(s) in my debian-based homelab. I've set up passwordless SSH from the HA box to the homelab machine, AND i've set up the actual command in a script that I can call from HA.
At this point, if I open up the Terminal Add-On and run this:

ssh josh@192.168.5.226 "/usr/local/bin/nvme_temp" -o StrictHostKeyChecking=no

Then I get the answer I want "105 104" (there's 2 drives I'm checking on simultaneously).

But when I put this into my configuration.yaml, I dont see my new sensors anywhere, nor do I see any errors in the logs that seem relevant:

  - platform: command_line
    name: superminitemp1
    command: 'ssh josh@192.168.5.226 "/usr/local/bin/nvme_temp" -o StrictHostKeyChecking=no'
    unit_of_measurement: "°F"
    scan_interval: 60
    value_template: "{{ value.split()[0] | int }}"

  - platform: command_line
    name: superminitemp2
    command: 'ssh josh@192.168.5.226 "/usr/local/bin/nvme_temp" -o StrictHostKeyChecking=no'
    unit_of_measurement: "°F"
    scan_interval: 60
    value_template: "{{ value.split()[1] | int }}"
sturdy vineBOT
#

To format your text as code, enter three backticks on the first line, press Enter for a new line, paste your code, press Enter again for another new line, and lastly three more backticks.
```yaml
example: here
```
Don't forget you can edit your post rather than repeatedly posting the same thing.

devout viper
tranquil spoke
#

Could you be more specific? I’ve looked at that page a few times.

devout viper
#

You're using 2 year old syntax

#

Note that there's no 'platform: command_line' there

tranquil spoke
#

Oh…
So I should remove this from sensors: part of my config and make a new section entirely called command_line:?

I thought that whole part was mean to be embedded under sensors:

Is that right?

devout viper
#

Yes, you need a block as shown in the docs

tranquil spoke
#

Thanks! I think I got stuck assuming the docs were discussing putting it inside of sensor: block. Lemme run with this for a bit.

Thanks for the nudge in the right direction!

tranquil spoke
#
command_line:
  - sensor:
      name: superminitemp1
      command: 'ssh josh@192.168.5.226 "/usr/local/bin/nvme_temp" -o StrictHostKeyChecking=no'
      unit_of_measurement: "°F"
      scan_interval: 60
      value_template: "{{ value.split()[0] | int }}"

  - sensor:
      name: superminitemp2
      command: 'ssh josh@192.168.5.226 "/usr/local/bin/nvme_temp" -o StrictHostKeyChecking=no'
      unit_of_measurement: "°F"
      scan_interval: 60
      value_template: "{{ value.split()[1] | int }}"

So that's where I am at now. Looks a lot more like the docs, and HA DOES finally acknowledge the existence of superminitemp1 and superminitemp2. However, both show as "unknown".

Can I get your opinion of the value_template portion? I wonder if there's something awry in there?

#

if it helps, that nvme_temp file just has these lines in it:

#!/bin/bash
temp0=$(sudo /usr/sbin/nvme smart-log /dev/nvme0 | awk -F':' '/temperature/ {gsub(/ °F.*/, "", $2); print $2}')
temp1=$(sudo /usr/sbin/nvme smart-log /dev/nvme1 | awk -F':' '/temperature/ {gsub(/ °F.*/, "", $2); print $2}')
echo "$temp0 $temp1"
#

I've tried simplifying. I created a new file that only asks for 1 drive of data. It reliably just says "40". I can call upon that file from the Terminal&SSH Add-on and it gets me the same answer "40". But my new sensor is still "unknown". I made a new HA sensor that just calls that new file. What am I missing?

#
command_line:
  - sensor:
      name: superminitemp0
      command: 'ssh josh@192.168.5.226 "/usr/local/bin/nvme_temp0" -o StrictHostKeyChecking=no'
devout viper
#

Look through the HA logs

tranquil spoke
#

I did some something in logs before I got this far. now I see nothing in the logs about these sensors.

#

no wait i take that back!

devout viper
#

If it says unknown, there's almost certainly an error

tranquil spoke
#

Command failed (with return code 255): ssh josh@192.168.5.226 "/usr/local/bin/nvme_temp" -o StrictHostKeyChecking=no
Command failed (with return code 255): ssh josh@192.168.5.226 "/usr/local/bin/nvme_temp0" -o StrictHostKeyChecking=no

#

return code 255? where do I find more info about that?

devout viper
#

You should run the command from within the container and see

tranquil spoke
#

If I run it in the SSH&Terminal add-on, isn't that the same thing?

#

it works in there!

devout viper
#

No

tranquil spoke
#

ruhroh

devout viper
#

Everything is a separate container

#

My guess is that you set up a key for your user and it's looking at root

tranquil spoke
#

I think my issue is here:
However there is one key exception, do not store your key file in the default location. The default location for ssh-keygen is ~/.ssh which translates to /root/.ssh

I believe I stored my key in the default location.

devout viper
#

Yes, that's what I meant

#

See that post for how to point to it

#

A) put the key somewhere in /config B) point to it in the command

tranquil spoke
#

My plan:
Re-run this from the HA SSH&Terminal Add-on: ssh-keygen -t rsa -b 4096
Instead of saving to default location, i'll tell it to save to /config/.ssh

The next step in my instructions is to send a copy of that key over to the server with this command: ssh-copy-id josh@192.168.7.178

#

What do you mean with your comment "B) point to it in the command" ?

devout viper
#

The -i in the post

tranquil spoke
#

isn't that just for testing?

devout viper
#

No

#

You have to tell it where it is

#

It's important to understand what you're doing there

#

Otherwise it will look in the root directory in the container

tranquil spoke
#

I see a reference to adding this: -i /config/.ssh/id_ed25519 into the configuration.yaml entry for the sensor. How do I know the id_ed25519 part?

devout viper
#

Whatever the key is

#

You're pointing it to your file

tranquil spoke
#

the terminal gave back "your public key has been saved in /config/.ssh.pub" Is that what I want ?

#
      name: superminitemp0
      command: 'ssh josh@192.168.5.226 -i /config/.ssh "/usr/local/bin/nvme_temp0" -o StrictHostKeyChecking=no'
#
  - sensor:
      name: superminitemp0
      command: 'ssh josh@192.168.5.226 -i /config/.ssh "/usr/local/bin/nvme_temp0" -o StrictHostKeyChecking=no'
#

No I still get error:
Command failed (with return code 255): ssh josh@192.168.5.226 -i /config/.ssh "/usr/local/bin/nvme_temp" -o StrictHostKeyChecking=no

#

Command failed (with return code 255): ssh josh@192.168.5.226 -i /config/.ssh.pub "/usr/local/bin/nvme_temp" -o StrictHostKeyChecking=no

#

also no

#

wtf

devout viper
#

You need to get the permissions correct. Please go through that thread

#

However you're running key gen, that's not the right place or name for the key

tranquil spoke
#

I get to here:
This is where disabling protection mode comes in. While SSH’ed into HA execute the following command (thanks @VDRainer!):

docker exec -it homeassistant bash

But that command doesn't work when I try it while ssh'd into homeassistant using the Terminal&SSH add-on to enable SSH.

#

I get
-bash: docker: command not found

#

am i using the wrong version of terminal&SSH add-on?

#

why is it that if I open up the target machine and run josh@N150SuperMini:~$ cat ~/.ssh/authorized_keys

I see a lengthy cryptic key... but it doesn't match the lengthy cryptic key I find in /config/.ssh or /config/.ssh.pub

Where is the step that tells the target machine to accept these keys? Can I just manually move the .ssh and/or .ssh.pub file(s) over to somewhere on the target machine so it will accept these keys?

tranquil spoke
#

It still feels like I cant get home assistant's command_line to use the proper SSH authentication file. I keep getting the return code 255.

tranquil spoke
#

I FINALLY GOT IT!

#

holymoley what a pain.

#

Final resolution... using the 'Advanced SSH & Web Terminal' Add-on - Disable Protection Mode. Then use that to emulate what HomeAssistant itself sends as SSH. Once there, I was able to get past the remaining problem and now I have data! YAY!

sick oriole
tranquil spoke
#

I did that 'ssh-copy-id' sooo many times.