How to add sensor for NVME ssd (Pi 5)?

Dear all,
How to add a sensor to read NVME temperature on a Pi 5 HAS system?
System Monitor does not show this.

I tried a command line sensor, like this:

command_line:
  - sensor:
      name: NVMe Temperature
      command: "smartctl -a /dev/nvme0 | grep '194 Temperature' | awk '{print $10}'"
      value_template: >
        {% set temp_str = value | regex_findall_index('temperature\s*:\s*(\d+)', ignorecase=True) %}
        {{ (temp_str | float / 256) | round(1) }}
      unit_of_measurement: "°C"

The sensor is created, but contains no data. The command line is obviously not corrrect, but I cannot find proper info.

Any suggestions, anyone?
Thanks!

Try this.

command_line:
  - sensor:
      name: NVMe Temperature
      command: "smartctl -a /dev/nvme0 | grep -m1 'Temperature:' | awk '{print $2}'"
      unit_of_measurement: "°C"

NVMe reports °C directly, so you don’t need to divide by 256

Error:
ValueError: Sensor sensor.nvme_temperature has device class ‘None’, state class ‘None’ unit ‘°C’ and suggested precision ‘None’ thus indicating it has a numeric value; however, it has the non-numeric value: ‘’ (<class ‘str’>)

Tried this:

command_line:
  - sensor:
      name: NVMe Temperature
      command: "smartctl -a /dev/nvme0 | grep -m1 'Temperature:' | awk '{print $2}'"
      value_template: >
        {{ (temp_str | float) | round(1) }}
      unit_of_measurement: "°C"

No errors, but also no data. I think command is incorrect and is not getting proper data.

Just to clearify, I have no additional tools installed to extract NVMe temps etc.

Ops… sorry.

Try this please.

command_line:
  - sensor:
      name: NVMe Temperature
      command: "smartctl -a /dev/nvme0 | grep -m1 'Temperature:' | awk '{print $3}'"
      unit_of_measurement: "°C"
      value_template: "{{ value | int }}"

Thanks, but again no luck.
Error:
ValueError: Template error: int got invalid input ‘’ when rendering template ‘{{ value | int }}’ but no default was specified

Sensor not created.

command_line:
  - sensor:
      name: NVMe Temperature
      command: "smartctl -a /dev/nvme0 | grep -m1 'Temperature' | awk '{for(i=1;i<=NF;i++) if($i ~ /^[0-9]+$/) print $i; exit}'"
      unit_of_measurement: "°C"
      value_template: "{{ value | int(0) }}"

This I got on my system and it works. Give a try please.
For test… Run this on your shell:

smartctl -a /dev/nvme0 | grep -m1 'Temperature' | awk '{for(i=1;i<=NF;i++) if($i ~ /^[0-9]+$/) print $i; exit}'

Must show something like… 42, 40 or whatever

@showup thanks.

In terminal
zsh: command not found: smartctl

As stated, I am running HAS op a Pi5, could this be the issue?

Your last suggestion does not result in any errors, just no temps are found. Empty value for sensor.

I run also pi5… and is working. Strange

You say run in shell. Is this same as using terminal?

Try this please.
Go to settings → Add-ons → Add-on Store in Home Assistant.
Install Glances.
Configure it to expose system sensors (it includes CPU, RAM, disk temps, etc.).
Then in HA, enable the Glances integration → it will automatically create sensors for your disks, including NVMe temperatures if supported.

p.s. I believe the smartctl binary is not available by default inside the HA container. That’s why you see ssh: command not found: smartctl

1 Like

Okay, got Glances setup and found a whole lot of data, including several temps.

Got Sensor 1 temperature, Sensor 2 temperature and Composite temperature, I assume are related to the NVMe ssd. The Composite temperature probably is what I need.

More info

But will dive in more later.

Lots of thanks for now @showup !