Raspberry Pi Power Sensor (updated: 2018-07-25) / Use Github for reports in the future

lets see if this works for hass.io (note all hass.io needs is a kernel bump to 4.14+ and this will work)

 - platform: command_line
   name: 'System: undervoltage status'
   command: 'cat /sys/devices/platform/soc/soc:firmware/get_throttled'
   scan_interval: 120

 - platform: template
   sensors:
      check_charger:
        friendly_name: "System: Charger"
        value_template: >
          {% if is_state("sensor.system_undervoltage_status", "0") -%}
             No throttling detected
          {% elif regex_match(states("sensor.system_undervoltage_status"), "40005", ignorecase=FALSE) or
              regex_match(states("sensor.system_undervoltage_status"), "50005", ignorecase=FALSE) -%}
              Throttling detected {{ states("sensor.system_number_of_undervoltage_messages") }} {{ state_attr("sensor.system_number_of_undervoltage_messages", "unit_of_measurement") }} 
          {% else -%}
              There is a problem with your power supply or system, state {{ states("sensor.system_undervoltage_status") }} reported
          {%- endif %}

If thatโ€™s a file, the a file sensor or โ€œcat, grep and wcโ€. could make this work.

However, typing

~ ls -la /sys/devices/platform/soc/soc:firmware

shows that there is no get_throttled file.

Does this imply that there is not throttling?

Here is some documentation:

check the path again

/sys/devices/platform/soc/soc:firmware/get_throttled

cat: canโ€™t open โ€˜/sys/devices/platform/soc/soc:firmware/get_throttledโ€™: No such file or directory

Round robin to a GitHub issue

1 Like

seems that HassOS is gonna be the new default os :slight_smile:

Yep. And the README page says

Linux kernel 4.14 (LT)

:tada:

trying this 2 sensors instead of three and just using 4.14 since its gonna be LTS anyways

 - platform: command_line
   name: 'System: Charger'
   command: cat /sys/devices/platform/soc/soc:firmware/get_throttled
   scan_interval: 120
   value_template: >
     {% if value == '0' %}
        No throttling detected
     {% elif value  == '40005' %}
        Throttling detected {{ states("sensor.system_number_of_undervoltage_messages") }} {{ state_attr("sensor.system_number_of_undervoltage_messages", "unit_of_measurement") }}
     {% elif value  == '50005' %}
        Throttling detected {{ states("sensor.system_number_of_undervoltage_messages") }} {{ state_attr("sensor.system_number_of_undervoltage_messages", "unit_of_measurement") }}
     {% else %}
        There is a problem with your power supply or system, state {{ value }} reported
     {% endif %}

 - platform: command_line
   name: 'System: number of undervoltage messages'
   command: "dmesg | grep Under-voltage | wc -l"
   unit_of_measurement: 'times'
   scan_interval: 120

feel free to comment and feedback :slight_smile: and thank you @Tinkerer

2 Likes

You can combine the โ€˜elifโ€™ statements in one โ€˜orโ€™.

yepp i know, planning on adding more statuses

0: under-voltage (0xX0001)
1: arm frequency capped (0xX0002 or 0xX0003 with under-voltage)
2: currently throttled (0xX0004 or 0xX0005 with under-voltage)

16: under-voltage has occurred (0x1000X)
17: arm frequency capped has occurred (0x2000X or 0x3000X also under-voltage occurred)
18: throttling has occurred (0x4000X or 0x5000X also under-voltage occurred)

if regex in jinja2 works the same as regular regexp this will work

 - platform: command_line
   name: 'System: Charger'
   command: cat /sys/devices/platform/soc/soc:firmware/get_throttled
   scan_interval: 120
   value_template: >
     {% if value == '0' %}
        No throttling detected
     {% elif value | regex_match(value, '[01]0001', ignorecase=False ) %}
        A under-voltage has occurred  
     {% elif value | regex_match(value, '[23]000[23]', ignorecase=False ) %}
        ARM frequency capped has with under-voltage 
     {% elif value | regex_match(value, '[45]000[45]', ignorecase=False ) %}
        CPU is throttled due to under-voltage 
     {% else %}
        There is a problem with your power supply or system, state {{ value }} reported
     {% endif %}

does this look correct @metbril and @Tinkerer?

This is getting so enhanced that we should start considering a new component or adding it to the system info component.

1 Like

well i am planning to do a real python component instead but in the meantime this will have todo :slight_smile:

see opening post for link

something like this perhaps gonna check with @ludeeus if this is correct not a python coder at all :slight_smile: will add it to opening post if its stable :stuck_out_tongue:

@Vasiley if you care to try it out there is a python script available you said to ping ya once something was available :slight_smile:

2 Likes

first custom_component added to opening post incase HassOS or Hassbian users wanna test it

1 Like

The 4 value for throttling could be because of thermal issues - worth confirming that. Iโ€™d guess that the 2 value is likely something similar.

I think you posted in the wrong threadโ€ฆ

Totally did! Sorry

version 0.0.4 is up, links in opening post

1 Like

hi,

i am trying to run it but i get the following error in Homeassistant

Error doing job: Task exception was never retrieved
10:56 loader.py (ERROR)

i am on kernel 4.14

4.14.54-v7+

and Running 0.73.1 version of HA on hassbian
i tried both to put rpi_power.py under

/home/homeassitant/.homeassistant/custom_components

and/or

/home/homeassitant/.homeassistant/custom_components/sensor

for sure i am doing something wrong: can someone help?
I am new to custom components: should they be activated somewhere in HA?

its the sensor dir