Command Line Integration in configuration.yaml

I wanted to share my configuration.yaml and how access RAM and CPU parameters and request feedback from the community. Thanks and hopefully it helps others!

# Example configuration.yaml entry
command_line:
  - sensor:
      name: CPU Temperature
      command: "cat /sys/class/thermal/thermal_zone0/temp"
      # If errors occur, make sure configuration file is encoded as UTF-8
      unit_of_measurement: "°C"
      value_template: "{{ value | multiply(0.001) | round(1) }}"


  - sensor:
      name: CPU Usage
      command: 'echo $(top -n 1 | sed -n "2p") | sed -e "s/.*CPU: \(.*\)% usr.*/\1/"'
      unit_of_measurement: "%"
      value_template: "{{ value }}"

  - sensor:
      name: RAM Usage
      command: 'echo $(top -n 1 | sed -n "1p") | sed -e "s/.*Mem: \(.*\)K used.*/\1/"'
      unit_of_measurement: "GB"
      value_template: "{{ value | multiply(0.000001) | round(1) }}"


1 Like

Why not just use System Monitor and set it up from the UI?

1 Like

Well that is simple @UngluedChalice… I didn’t realize System Monitor existed! Haha. Well it looks like I re-invented the wheel. At the very least this method has worked for me so if you needed some custom command line integrations this is one way to do it.