svinedyret

Pi hardware monitor on HA

Jan 27th, 2022 (edited)
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 3.36 KB | Software | 0 0
  1. #=============================================
  2. #=== Raspberry Pi CPU Temperature
  3. #=============================================
  4. - platform: command_line
  5.   name: RPi CPU Temperature
  6.   command: "cat /sys/class/thermal/thermal_zone0/temp"
  7.   value_template: "{{ value | multiply(0.001) | round(2) }}"
  8.  
  9. #=============================================
  10. #=== Last boot time, Disk, memory & CPU usage
  11. #=============================================
  12. - platform: systemmonitor
  13.   resources:
  14.     - type: last_boot
  15.     - type: disk_use_percent
  16.       arg: /
  17.     - type: memory_use_percent
  18.     - type: processor_use
  19.  
  20. #====================
  21. #=== CPU Temperature
  22. #====================
  23. - platform: command_line
  24.   name: CPU Temp
  25.   command: "cat /sys/class/thermal/thermal_zone0/temp"
  26.   unit_of_measurement: "°C"
  27.   value_template: "{{ value | multiply(0.001) | round(2) }}"
  28.  
  29. #====================
  30. #=== GPU Temperature
  31. #====================
  32. - platform: command_line
  33.   name: GPU Temp
  34.   command: "/opt/vc/bin/vcgencmd measure_temp"
  35.   unit_of_measurement: "°C"
  36.   value_template: '{{ value | replace("temp=", "") | replace("''C", "") }}'
  37.  
  38. #===================
  39. #=== System Up Time
  40. #===================
  41. - platform: uptime
  42.  
  43. #===================
  44. #=== Templates for RPi boot and uptime
  45. #===================
  46.  
  47. - platform: template
  48.   sensors:
  49.    #=========================================
  50.     #=== Raspberry Pi last boot date and time
  51.     #=========================================
  52.     last_boot_date_time:
  53.       friendly_name: Last Boot
  54.       value_template: >
  55.        {% set date = as_timestamp(states('sensor.last_boot')) | timestamp_custom('%d') %}
  56.         {% set date = '{:01}'.format(date | int) %}
  57.         {% if date in ('1', '21', '31') %}
  58.           {% set date = date ~ 'st' %}
  59.         {% elif date in ('2', '22') %}
  60.           {% set date = date ~ 'nd' %}
  61.         {% elif date in ('3', '23') %}
  62.           {% set date = date ~ 'rd' %}
  63.         {% else %}
  64.           {% set date = date ~ 'th' %}
  65.         {% endif %}
  66.  
  67.         {{ as_timestamp(states('sensor.last_boot')) | timestamp_custom('%H:%M on %a') }} {{ date }} {{ as_timestamp(states('sensor.last_boot')) | timestamp_custom('%b %Y') }}
  68.  
  69.     #=========================
  70.     #=== Raspberry Pi Up Time
  71.     #=========================
  72.     rpi_uptime:
  73.       friendly_name: RPi Uptime
  74.       value_template: >
  75.        {% set up_time = as_timestamp(now()) - as_timestamp(states('sensor.last_boot')) %}
  76.  
  77.         {% set minutes = (up_time // 60) | int %}
  78.         {% set hours = (minutes // 60) %}
  79.         {% set days = (hours // 24) %}
  80.         {% set weeks = (days // 7) %}
  81.  
  82.         {% set minutes = (minutes % 60) %}
  83.         {% set hours =  (hours % 24) %}
  84.         {% set days = (days % 7) %}
  85.  
  86.         {% macro phrase(value, name) %}
  87.                   {%- set value = value %}
  88.                   {%- set end = 's' if value > 1 else '' %}
  89.                   {{- '{} {}{}'.format(value, name, end) if value | int > 0 else '' }}
  90.         {%- endmacro %}
  91.                  
  92.         {% set text = [ phrase(weeks, 'week'), phrase(days, 'day'), phrase(hours, 'hr'), phrase(minutes, 'min') ] |             select('!=','') | list | join(', ') %}
  93.         {% set last_comma = text.rfind(',') %}
  94.         {% if last_comma != -1 %}
  95.           {% set text = text[:last_comma] + ' and' + text[last_comma + 1:] %}
  96.         {% endif %}
  97.  
  98.         {{ text }}
Advertisement
Add Comment
Please, Sign In to add comment