Kodi AddOn to control Fan Shim on Pi4 - I need to get the CPU %

  • I have been writing a Kodi add on which uses RI Tools to control the Fan Shim.


    I have this working nicely turning the Fan on and off and changing the light based on the temperature.


    I want to get the current CPU percentage to turn on the Fan quickly if the CPU goes to over 90% and stays there.


    I know this can be called easily in a Skin, but I can't work out how to call it in a service addon.


    I should mention this is my first attempt at a Kodi add on so I am probably missing something obvious.

  • jane_t


    I saw this earlier but didn't know the answer. You obviously solved it yourself. The Fanshim addon is a great bonus for fanshim users and really good as a first attempt. Well done.


    I have referenced you in our [How To] Fanshim

  • I have not solved it yet, the add on simply reacts to the temperature hitting the limit set by the user.

  • To get the avg CPU you can use

    top -n 1 | grep "%Cpu"

    or

    mpstat (Available with the LE system-tools addon)


    However, they are the AVG. To do what I think you are after, you'll need to check each of the 4 CPU's in order, as 3 CPU's could be low whilst only one was at 100% and causing an issue. This would give an AVG of ~25%

  • If you still need the information about individual CPU percentages then /proc/stat will give you that. It's a bit confusing, and you'll need to adjust the figures to get an overall value. Personally I wouldn't bother as the temperature is more important than CPU load.

  • jane_t the add-on that you've made is great!
    But when I shutdown my Pi, sometimes your script is still running and the Pi is unable to unmount the /strorrage partition at some shutdowns/reboots.
    Maybe you can build something in the code, that makes the script stop running when the Pi shuts down or reboots?

    Thanks a lot!

    Cheers!

    Dive Mask Strap :cool:

  • I've never had a problem with unmount or shutdown with the addon running - there is nothing in the code to hinder that.


    However, yes the fan will continue to run once the system has shutdown - (Also before LE has booted). Not too sure if the code can be reversed so that this doesn't happen but as this was their first attempt at writing an addon, I think we have to live with the results for the moment.

  • I've never had a problem with unmount or shutdown with the addon running - there is nothing in the code to hinder that.


    However, yes the fan will continue to run once the system has shutdown - (Also before LE has booted). Not too sure if the code can be reversed so that this doesn't happen but as this was their first attempt at writing an addon, I think we have to live with the results for the moment.

    Problem found, I have enable the Hifiberry settings in the config.txt and the problem is gone. So if I shutdown LibreElec only the LibreElec logo/version appears and not wich deamon is closed down. 8)

    Cheers!

    Dive Mask Strap :cool:

  • So, i tried the fanshim addon, installed it, rebooted, etc... all according to the howto, but it doesn't seem to be working? But i think the shim isn't connecting to the headers properly? When i push the shim towards to power/hdmi ports the led goes on (blue or green, super bright) but the fan never stops.


    Rebooted mulitple times, anyone have these issues? and/or know how to fix them?

  • So, i tried the fanshim addon, installed it, rebooted, etc... all according to the howto, but it doesn't seem to be working? But i think the shim isn't connecting to the headers properly? When i push the shim towards to power/hdmi ports the led goes on (blue or green, super bright) but the fan never stops.


    Rebooted mulitple times, anyone have these issues? and/or know how to fix them?

    @jane_t

    I have the same problem. Since i didn't succeed, I tried a completely new installation of libreelec, kodi, raspberry tools and fanshim on another sd. But still no succes, the fan is just running 100% all the time. I eperimented with differnen on/off temperatures, leds on/off seting but the addon seems to do nothing.