Read data from another Pi

I have another Pi running Pi-Hole, and id like to display some basic info about the Pi within Pi-Hole, such as temperatuere, uptime etc.
Specifically not pi-hole data…I have the Pi-hole sensor running for this.

I have a very basic server running which displays the data in basic html.

But I cant figure out how to ‘tap into’ the 2nd Pi.

Both on the same network.

There are a lot of way to get the info into another pi. I run HA on two systems and link them with mqtt statestream. If you don’t want to setup HA on the PI hole, you can setup a mqtt server to send states to HA.

I use a separate SSH key to remotely execute commands on my other Pi. For instance, to get the uptime of another Pi from my HASS Pi, I do this:

sensor:
  - platform: command_line
    name: Pi2 Temperature
    command: 'ssh user@pi2 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'
  - platform: command_line
    name: Pi2 Uptime
    command: "ssh user@pi2 cat /proc/uptime | cut -d ' ' -f 1"
    value_template: '{{ (value | float / 86400) | round(0) }}'
    unit_of_measurement: 'days'

I’ll stress again that I use a separate SSH key that isn’t used or stored anywhere else.

snmp component

This is the kind of thing I was looking for,
ive never used keys to log in to my Pis, always with a user and password.

How would / should I progress to using keys?

In general, I’m a proponent of using keys over password-based auth. Lots of documentation out on the internet; here’s a guide from Linode which should apply reasonably closely to a Pi: https://www.linode.com/docs/security/securing-your-server

Make sure you get a good handle on how the above works before proceeding. Once you do: I launch HASS via a shell script that looks like this:

#!/bin/sh

# Automatically accept various SSH hosts:
/usr/bin/ssh-keyscan -H pi2 >> /root/.ssh/known_hosts
/usr/bin/ssh-keyscan -H pi3 >> /root/.ssh/known_hosts

# Start app services:
/usr/bin/supervisord -c /etc/supervisor.conf

Focus on the first two instructions. These add two other Pis (assuming hostnames of pi2 and pi3) to the local SSH’s known_hosts file, which will prevent SSH from confirming them before logging in – if that isn’t in place, the HASS Pi won’t be able to connect.

1 Like

Is there a way to control how often the commands are run?

Definitely – from the docs:

scan_interval (Optional): Defines number of seconds for polling interval (defaults to 60 seconds).

Thanks, found it over the weekend. Other than by trial and error and reloads of HA, is there a list of what probe types this can be used with? I would like to use it with snmp probes as well and have not tried it yet.

What do you mean by probe types?

Sorry, intermapper user here. I mean, can I use the scan_interval with anything that asks other devices questions via snmp, command line and the such. I assume that I can.