Temperature from another pi via ssh

Hello
i want to get the temperature from another pi. I found some information and a thread from 2017 https://community.home-assistant.io/t/read-data-from-another-pi/30655/2
I have installed the SSH Server addon and configured the ssh-key.
In the configuration i wrote

sensor pi_hole:
  - platform: command_line
    name: Pi-Hole Temperatur
    command: "ssh [email protected] echo $((`cat /sys/class/thermal/thermal_zone0/temp|cut -c1-2`)).$((`cat /sys/class/thermal/thermal_zone0/temp|cut -c3-4`))"
    unit_of_measurement: "°C"

But the temperature would not show.
If i type it in the terminal window they show me the temperature without asking the password.
Can anyone help me?

What’s in the logs?

Probably need to disable pseudo tty allocation

command: "ssh -T [email protected] ..."

How are you running Home Assistant? Docker, venv etc?

If you are running in a venv, did you activate the venv before configuring the ssh-keys?

If you’re running ssh from Hassio, then take a look at this:

There’s just a few steps to get ssh running smoothly in that context.

hi, i check it like that:

  - platform: command_line
    name: rpi3_cputemp_ssh
    command: "ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no  [email protected] -i /home/homeassistant/.keys/ssh2rpi3 'sudo cat /sys/class/thermal/thermal_zone0/temp' || echo Connection failed."
    unit_of_measurement: "°C"
    value_template: '{{ value | multiply(0.001) | round(1) }}'

HomeAssistant in a venv

Thank you all for your reply.
@jocnnor
the log say this

Command failed: ssh [email protected] echo $((`cat /sys/class/thermal/thermal_zone0/temp|cut -c1-2`)).$((`cat /sys/class/thermal/thermal_zone0/temp|cut -c3-4`))

the command with -T also doesnt work

@tjntomas
I downloaded the image from the homepage and installed it on an mircosd and run it on a raspberry pi 4

@Bit-River @void
i havent try it now. i will do this in the next time

Hello everybody,
@Bit-River
I tried it but at the point with the chown command it says “unknown user/group hassio:hassio”
@void
I tried your commands but it is the same problem

Ah, I got that error too, but it didn’t stop the ssh command from working.

Do you get the same error message when the command line sensor tries to connect?

i got this error in the log

Command failed: ssh -i /config/ssh/id_rsa -o StrictHostKeyChecking=no [email protected] echo $((“cat /sys/class/thermal/thermal_zone0/temp|cut -c1-2”)).$((“cat /sys/class/thermal/thermal_zone0/temp|cut -c3-4”))

Hmmm, is the command part after the IP address surrounded by quotes?

I’m wondering if the ssh part is working, but now the command itself is causing the problem. Sometimes a command with a lot of quotes / special characters won’t work.

Also a good rule of thumb - if there are double-quotes in the command, then use single-quotes to surround it.

So, something like:

ssh -i /config/ssh/id_rsa -o StrictHostKeyChecking=no [email protected] 'echo $((“cat /sys/class/thermal/thermal_zone0/temp|cut -c1-2”)).$((“cat /sys/class/thermal/thermal_zone0/temp|cut -c3-4”))'

An alternative is to have a bash script on the Pi that runs the command, and your command_line sensor calls the script.

So:

ssh -i /config/ssh/id_rsa -o StrictHostKeyChecking=no [email protected] '/home/pi/my_temperature_script.sh'

Here look. if i put the command from my first post in the terminal it works.
i would try it with the bash script.
thank you