How to use value_template to extract data from the sensor

I have one sensor which as below. Is for checking the SSD temperature on the proxmox server.

  • platform: command_line
    name: SSD Temp on Proxmox
    command: “ssh -i /config/id_rsa -o StrictHostKeyChecking=no [email protected] -t ‘hddtemp /dev/sda’”

which output come out as below but without the quote

“/dev/sda: TS512GMTS430S: 60°C”

what is the correct command of value_template to extract just the value of “60°C” ? I try to seach through the forum but non of the topic match my question.

Thanks in advance.

Please format your code correctly with the </> button.

Easiest way would be to get the command to give you the right output. I don’t have hddtemp to hand, but try these on the proxmox server command line to see if you get just the number reported:

hddtemp -n
hddtemp -n | split -d \  -f 3

Note there are two spaces after the backslash. If one of those gives just a number, put that in the command of your sensor.

If that doesn’t work, you could use:

- platform: command_line
  name: SSD Temp on Proxmox
  command: "ssh -i /config/id_rsa -o StrictHostKeyChecking=no [email protected] -t 'hddtemp /dev/sda'"
  unit_of_measurement: "°C"
  device_class: temperature
  unique_id: 2e01043e-d562-4c73-ad46-6778832ed4ed
  value_template: "{{ value|regex_replace('^.*:','')|regex_replace('[^0-9]','') }}"

which takes the value, removes anything before and up to a colon, then removes anything non-numeric from the remainder.

at first, thanks for reply.

hddtemp -n won’t work as it need specify a device

root@proxmox:~# hddtemp -n
Too few arguments: you must specify one drive, at least.

root@proxmox:~# hddtemp /dev/sda
/dev/sda: TS512GMTS430S: 60°C

I use below command on HA config file & it successfully generate just the number only.

  • platform: command_line
    name: SSD Temp on Proxmox
    command: “ssh -i /config/id_rsa -o StrictHostKeyChecking=no [email protected] -t ‘hddtemp /dev/sda’”
    unit_of_measurement: “°C”
    value_template: “{{ value|regex_replace(’^.*:’,’’)|regex_replace(’[^0-9]’,’’) }}”

how do you generate that unique_id ? by the way, is that necessarily to specify the device_class?

Please format your code correctly with the </> button. If you don’t we can’t see indentation errors, and all your quotes are converted into smart quotes.

hddtemp -n /dev/sda

should work then? If it does give just a number and no disk label information, you can remove the value_template in the sensor.

unique_id just has to be unique. I use https://www.uuidgenerator.net/. device_class isn’t necessary but it gives you appropriate icons in the UI.

1 Like

below command working !

root@proxmox:~# hddtemp -n /dev/sda
61

yes, I will remove the value template & use above command. Really thanks for your help :slight_smile:

1 Like