Temperature of Nextcloud server in Home Assistant

Good day and thank you for reading my FEATURE REQUEST for the NEXTCLOUD service.

I like to receive the CPU temperature of the Nextcloud server in Home Assistant. I run Nextcloud on a Raspberry Pi4.
The temperature is received by executing [/usr/bin/vcgencmd measure_temp] and is given in 'C.

By adding this, I can automate to run a fan when the temperature reaches a certain degree by switching a 110V outlet with a big fan.

Thank you in advance.

You can use the shell command integration as a sensor, and the shell command can run the vcgencmd program via SSH on your Nextcloud server.

Alternatively you can set up Prometheus to ingest node exporter telemetry from the Nextcloud server, and then use the scrape integration to ingest the current scraped temperature from the Prometheus server. This is in fact how the pros get telemetry and set up alerting for system conditions.

Why are so many people dressing up requests for help as a feature request?

1 Like

Thank you for your reply. It works manually, meaning I have to enter a password everytime the command is run: ssh [email protected] ‘bash -s’ < temp_nextcloud.sh.

I searched how to add the password in the ssh-command. sshpass should be the solution.
I used the Raspberry Pi4 image to get Home Assistant server to run, and believe it run in Docker (:man_shrugging:).

I found this command, but received a warning: docker run --rm -it sshpass -p password ssh -o StrictHostKeyChecking=no [email protected] “echo my-commands”

Before I am going to change all kind of security settings I do not know about, is this my way forward to get the value?
[Edit: I searched for the Protection mode option, but couldn’t find it. Can you guide me?]

I appreciate your feedback and comments.

Hi,
Hope you are doing well and thank you for your comment.
I installed the Nextcloud server integration and saw a lot of entities, but missed the temperature. My request was that the temperature would be build in into the Nextcloud integration.
I was given an alternative to get the same result, which I appreciated.
I wrote this reply to show you my way of thinking, reasoning and definition of feature request.
I apologize to you for bothering you with my reasoning and outcome.

Dont use password. That is very bad!

Use an SSH key (ssh-keygen).

Make the HA server user gain a private SSH key, and then put the public part in the remote server’s user’s authorized_keys file.

Then the command can execute without a password and securely.

You may have to make the connection manually one time so the HA server learns the remote side’s certificate (although it looks like you did that already so it may not be needed).

Thank you for your reply and feedback. I managed to get a password-less log on to retrieve the temperature.
I am struggeling to get the value into Home Asisstant.

I added the following to configuration.yaml:
sensor:
- platform: command_line
name: nc_temp
command: "ssh [email protected] 'bash -s' < ~/temp_nextcloud.sh"
scan_interval: 30

If I execute the command in the CLI, I retrieve a result:
config # ssh [email protected] 'bash -s' < ~/temp_nextcloud.sh
68.166
config #

The value of 68.166 needs to get into Home Assistant. Is the addition above sufficient? The entity sensor.nc_temp is available but I only get ‘unknown’ as value.

I wish this thread could be moved to a support thread. If appreciated, I will end this thread with all I did in steps.

[Edit]
Here: https://www.home-assistant.io/integrations/command_line/
I read that it is expected more like this, but it gives me an configuration error (most probably because of the degrees-symbol):
command_line:
- sensor:
name: nc_temp
command: "ssh [email protected] 'bash -s' < ~/temp_nextcloud.sh"
scan_interval: 30
unit_of_measurement: "°C"
value_template: "{{ value | multiply(0.001) | round(1) }}"

[Edit 2]
I added a second ‘sensor’ with the command line:
command "cat /proc/uptime"

This one has a value. So, it is in the command line. If I manually execute the command it works, in the script it does not.

[Edit 3]
Last one, I am going to sleep.
I added this and it didn’t give me a configuration error, than the one before:
command_line:
- sensor:
name: nc_temperature
command: "ssh [email protected] 'bash -s' < /home/ramin/temp_nextcloud.sh"
scan_interval: 10

The entity pops up, but value is unknown.

Thank you in advance!

Any idea?

You must check the home assistant debug log for errors. Maybe under HA it doesn’t run properly.

Hi,
Thank you again for your feedback.

home-assistant.log first lines are:
2023-07-17 09:28:38.999 ERROR (SyncWorker_0) [homeassistant.components.command_line.utils] Command failed (with return code 1): sudo ssh [email protected] 'bash -s' < /home/ramin/temp_nextcloud.sh
2023-07-17 09:28:39.006 ERROR (SyncWorker_1) [homeassistant.components.command_line.utils] Command failed (with return code 1): sudo ssh [email protected] 'bash -s' < /home/ramin/temp_nextcloud.sh
2023-07-17 09:28:49.369 ERROR (SyncWorker_0) [homeassistant.components.command_line.utils] Command failed (with return code 1): sudo ssh [email protected] 'bash -s' < /home/ramin/temp_nextcloud.sh

Further more:
2023-07-17 09:28:59.369 ERROR (SyncWorker_6) [homeassistant.components.command_line.utils] Command failed (with return code 1): sudo ssh [email protected] 'bash -s' < /home/ramin/temp_nextcloud.sh

The ERROR doesn’t say me anything, but DuckDuckGo gave me among others this page:

It mentioned the right users rights and permissions for the executing script, as the script is executed as user and not as root.
I changed it to (chown) ramin:ramin and (chmod) 755.

ramin # ls -laF
total 16
drwxr-sr-x 2 ramin ramin 4096 Jul 16 23:42 ./
drwxr-xr-x 1 root root 4096 Jul 15 13:17 ../
-rw-r--r-- 1 root ramin 13 Jul 15 13:17 .profile
-rwxr-xr-x 1 ramin ramin 28 Jul 16 23:42 temp_nextcloud.sh*
ramin #

I am connected to CLI via Putty, I used the Terminal in HA (browser) itself and tested if I could run the command. I received the result, so the rights are probably set right.

It feels I am sooooo close thanks to your help, but :face_with_symbols_over_mouth:

[Edit]
I changed the script to:
command_line:
- sensor:
name: nc_temp
command: "./home/ramin/temp_nextcloud.sh"
scan_interval: 5

This error was produced:
2023-07-17 11:56:31.373 ERROR (SyncWorker_7) [homeassistant.components.command_line.utils] Command failed (with return code 127): ./home/ramin/temp_nextcloud.sh

I also tried it without the dot (.) before /home/...

Seemingly, the script cannot be executed.
Changing the command to command: "echo 'Test'" worked.

Try with no dot.

Doesn’t work.