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

Hi folks :slight_smile:

Noticed that alot of people are running with bad power supplies so i decided in a preemptive measurement to post a little sensor that checks if you got a bad power supply or not

Whats the bad deal with any old power supply

Well a raspberry pi cant run of a any mobile power supply that causes system instability and SD corruption so its very important to have a proper power supply

Raspberry Pi Model A Raspberry Pi Model B+ Raspberry Pi 2 Model B Raspberry Pi 3 Model B Raspberry Pi 3 Model B+
700mA 1.8A 1.8A 2.5A 2.5A

This works for Hassbian or manually installed environments not hass.io is currently missing the 4.14 kernel to be able to use this simple sensor. This will work for HassOS thats currently in Release Candidate so look out for a release coming soon :slight_smile:

Changelog:

  • v0.0.1 initial version
  • v0.0.2 tweaks and bugfixes (tnx @ludeeus)
  • v0.0.3 additonal tweaks
  • v0.0.4 bugfixes introduced in earlier revisions
  • v0.0.5 Changes version format so its trackable by the updater card
  • v0.0.6 Grammatical fixes (tnx tjorim)
  • v0.0.7 Add the option to set the desctiption as the state (tnx @ludeeus)

Here is my work in progress a standalone python script with help from other devs such as Robban and @ludeeus huge tnx for all the pointers and help

or you use the following standard sensor to check if your power supply is throttling your cpu (don’t use both)

  • Kernel version: 4.14+

To update your kernel on Raspbian/Hassbian just run rpi-update to verify that you have 4.14 run uname -r

just add this to your sensor configuration and if you get a message about throttling you seriously need to check your power supply so its up to standards.

If there is evidence of throttling you need to replace your power supply because its not good enough and it will cause issues down the line if its powering your Raspberry Pi.

sensor:
  - platform: rpi_power

28 Likes

I actually like this but I guess it will never work with hassio since the β€˜vcgencmd’ command is not available.

Or is it?

It’s not, but there was a discussion in the #hassio Discord channel about the possibility of creating an add-on.

I just set up the sensors but did not receive any kind of status message for the check_charger sensor.

When I check the sensor history one of my Pis, it comes up with either throttled=0x50000 or with throttled=0x50005, but never with 0x5 or 0x4.

Any hints?

That discussion was initiated by me. :wink:

2 Likes

yeah get a new charger

After doing some quick research I understand that now - I guess the value template needs expanding :wink:

if the sensor says no throtteling detect everything is fine else = new charger :slight_smile: simple all chargers degrade over time so they need to be replaced over time

Well, the template needs tweaked as @chairstacker said - to allow it to test only the first 3 characters

Probably regex_match(string, find, ignorecase=FALSE):

        value_template: >
          {% if is_state("sensor.system_undervoltage_status", "throttled=0x0") -%}
             No throttling detected
          {% elif regex_match(states("sensor.system_undervoltage_status"), "throttled=0x4", ignorecase=FALSE) -%}
             Throttling detected {{ states("sensor.system_number_of_undervoltage_messages") }} times 
          {% elif regex_match(states("sensor.system_undervoltage_status"), "throttled=0x5", ignorecase=FALSE) -%}
             Throttling detected {{ states("sensor.system_number_of_undervoltage_messages") }} times 
          {% else %}
             There is a problem with your power supply or system, state {{ states("sensor.system_undervoltage_status") }} reported
          {%- endif %}
2 Likes

updated example above tnx @Tinkerer

1 Like

While doing some additional reading I found that there is a way to directly use Python.

https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=82373&start=75#p739517

And perhaps there is file to read?

And lastly some more info

https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=147781&start=50#p972790

@metbril Think i can do something with this for hass.io users will take a look at it and do reasearch

if the system has apt we should be able to install it using by adding this line to your dockerfile.

RUN apt-get update && apt-get install -y libraspberrypi-bin

You should read the whole rpi forum thread since gpio 35 is not always used.

@metbril check out my edited comment above

I run hassio for a reason. No need to do Docker stuff. :wink:

But if the devs come up with something I will be happy to use it.

My hope is that it will be possible to add the vcgencmd command to the hassio container.

ok well if someone with hass.io was to try it out so i know it works i would be grateful that way i know if its worth investing in doing a addon for hass.io in general

Try what, exactly?

the docker stuff

Some more suggestions:

  • combine the 2 elif’s
  • use unit_of_measurement attribute
 - platform: template
   sensors:
      check_charger:
        friendly_name: "System: Charger"
        value_template: >
          {% if is_state("sensor.system_undervoltage_status", "throttled=0x0") -%}
             No throttling detected
          {% elif regex_match(states("sensor.system_undervoltage_status"), "throttled=0x4", ignorecase=FALSE) or
                  regex_match(states("sensor.system_undervoltage_status"), "throttled=0x5", 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 %}
1 Like

since popcornmix added /sys/devices/platform/soc/soc:firmware/get_throttled to kernel i might be able to use it instead of having bins etc into hass.io