Page 1 of 1

Raspberry Pi internal status Dzvents script

Posted: Sunday 29 August 2021 13:50
by freijn
Dear members,

Often you find others in troubles for not having the correct powersupply for the Raspberry.
The Raspberry starts complaining but only in the UI of the o.s.
After reading again that somebody was in troubles because of this, I decided to write a little script for monitoring Raspberry Pi sensors
which are not (yet) available in the standard domoticz UI.

Please find below my code.

- paste it in the events under Dzvents-Timer
- Create an Alert sensor and note the IDX
- change the 'Alertidx = 4106' into 'Alertidx = [yourIDX]'

Hopefully your Raspberry Pi is a happy one :-)

Todo :
- I could not get the Lua bitwise AND function to work, hence the workaround,
if somebody know how to implement it, please share it with us.
- Notifications sent if alarm appears.

Greetings from Purmerend Netherlands,

Frank
.
.
rpihappy.JPG
rpihappy.JPG (19.6 KiB) Viewed 3362 times
rpiunhappy.JPG
rpiunhappy.JPG (18.26 KiB) Viewed 3362 times
Version History:
20210829 V1.3
Updated because of logging error's

Code: Select all

---Frank Reijn RpiLocalSensors v1.3--20210829----------------------------------
-- Domoticz Dzvents timer script to read internal status of the Rasperry pi----
-- See FlagBits for details.---------------------------------------------------
-- Create a Domoticz 'Alert sensor' and use the generated IDX to enter in------ 
-- the Alertidx variable herunder.---------------------------------------------

return {
    on      =   { timer = { 'every minute' }},        
    --logging =   {   level     =   domoticz.LOG_INFO ,   -- domoticz.LOG_ERROR
    --              marker    =   "RPI Sensor Value Script"      },
    execute = function(dz)

    --Flag Bits
    local UNDERVOLTED=0x1
    local CAPPED=0x2
    local THROTTLED=0x4
    local SOFT_TEMPLIMIT=0x8
    local HAS_UNDERVOLTED=0x10000   -- 
    local HAS_CAPPED=0x20000
    local HAS_THROTTLED=0x40000
    local HAS_THROTTLED_RB=0x50000
    local UNDERVOLTED_THROTTLED=0x50005
    local HAS_SOFT_TEMPLIMIT=0x80000
    
    --0x50000 means throttled has occurred since the last reboot.

-- 0x50005 means you are currently under-voltage and throttled.

--------------------------------------------------------------------------
    local Alertidx = 4106  -- Change this to your local Alert idx number -
--------------------------------------------------------------------------

    local function GetRpiSensor()
            local command = 'vcgencmd get_throttled'
            --dz.log(command,dz.LOG_INFO)
            local handle = assert(io.popen(command))
            for line in handle:lines() do
                findsensor=line
            end
            handle:close()
        return findsensor
       end
       
    -- Start main script   
    local RpiSensorvalue= GetRpiSensor()
    local splittedResult = dz.utils.stringSplit(RpiSensorvalue,'=')  -- split string into (table) parts with , as separator
    --dz.log(splittedResult[1] .. ',' .. splittedResult[2], dz.LOG_INFO) -- first two parts 
    local RPIhex = tonumber(splittedResult[2])
    
    -- RPIhex =8  -- for testing only
    
    -- define initial alert messages
    local AlertL = dz.ALERTLEVEL_GREEN
    local AlertT = ''
    
    -- As I could not get lua Bitwise to work I have created a workaround :-)
    if ( RPIhex > (HAS_SOFT_TEMPLIMIT-1) ) then
        RPIhex = RPIhex -HAS_SOFT_TEMPLIMIT
        AlertL = dz.ALERTLEVEL_RED
        AlertT = 'Rpi HAS Soft TempLimit'
    end
    if ( RPIhex > (UNDERVOLTED_THROTTLED-1) ) then
        RPIhex = RPIhex -UNDERVOLTED_THROTTLED
        AlertL = dz.ALERTLEVEL_RED
        AlertT = 'Rpi currently under-voltage and throttled'
    end
    
    if ( RPIhex > (HAS_THROTTLED_RB-1) ) then
        RPIhex = RPIhex -HAS_THROTTLED_RB
        AlertL = dz.ALERTLEVEL_RED
        AlertT = 'Rpi throttled occurred since last reboot'
    end
    if ( RPIhex > (HAS_THROTTLED-1) ) then
        RPIhex = RPIhex -HAS_THROTTLED
        AlertL = dz.ALERTLEVEL_RED
        AlertT = 'Rpi HAS Throttled'
    end
    if ( RPIhex > (HAS_CAPPED-1) ) then
        RPIhex = RPIhex -HAS_CAPPED
        AlertL = dz.ALERTLEVEL_RED
        AlertT = 'Rpi HAS Capped'
    end
        if ( RPIhex > (HAS_UNDERVOLTED-1) ) then
        RPIhex = RPIhex -HAS_UNDERVOLTED
        AlertL = dz.ALERTLEVEL_RED
        AlertT = 'Rpi HAS undervolted'
    end
    if ( RPIhex > (SOFT_TEMPLIMIT-1) ) then
        RPIhex = RPIhex -8
        AlertL = dz.ALERTLEVEL_RED
        AlertT = 'Rpi Soft Temp Limit'
    end
    if ( RPIhex > (THROTTLED-1) ) then
        RPIhex = RPIhex -4
        AlertL = dz.ALERTLEVEL_RED
        AlertT = AlertT .. ' Rpi Throttled'
    end
    if ( RPIhex > (CAPPED-1) ) then
        RPIhex = RPIhex -2
        AlertL = dz.ALERTLEVEL_RED
        AlertT = AlertT .. ' Rpi Capped'
    end    
    if ( RPIhex > (UNDERVOLTED-1) ) then
        AlertL = dz.ALERTLEVEL_RED
        AlertT = AlertT .. ' Rpi UnderVolted'
    end
    
    if ( AlertT == '') then
        AlertT = 'Raspberry is feeling Happy'
    end 
    -- Set the Alert Sensor
    dz.devices(Alertidx).updateAlertSensor(AlertL, AlertT)
   
    end
}

Re: Raspberry Pi internal status Dzvents script

Posted: Sunday 29 August 2021 13:59
by multinet
Hello

Thanks for the scripts ;)

i tried it but i get error :

Code: Select all

2021-08-29 13:57:02.913  Error: dzVents: Error: (3.0.2) TIMER-RPI Health: vcgencmd get_throttled
2021-08-29 13:57:03.151  Error: dzVents: Error: (3.0.2) TIMER-RPI Health: throttled,0x50005
2021-08-29 13:58:03.065  Error: dzVents: Error: (3.0.2) TIMER-RPI Health: vcgencmd get_throttled
2021-08-29 13:58:03.232  Error: dzVents: Error: (3.0.2) TIMER-RPI Health: throttled,0x50005
2021-08-29 13:59:03.377  Error: dzVents: Error: (3.0.2) TIMER-RPI Health: vcgencmd get_throttled
2021-08-29 13:59:03.598  Error: dzVents: Error: (3.0.2) TIMER-RPI Health: throttled,0x50005
Can you help me ?

i'm on RPI2

Multinet

Re: Raspberry Pi internal status Dzvents script

Posted: Sunday 29 August 2021 14:06
by freijn
multinet wrote: Sunday 29 August 2021 13:59 Hello

Thanks for the scripts ;)

i tried it but i get error :

Code: Select all

2021-08-29 13:57:02.913  Error: dzVents: Error: (3.0.2) TIMER-RPI Health: vcgencmd get_throttled
2021-08-29 13:57:03.151  Error: dzVents: Error: (3.0.2) TIMER-RPI Health: throttled,0x50005
2021-08-29 13:58:03.065  Error: dzVents: Error: (3.0.2) TIMER-RPI Health: vcgencmd get_throttled
2021-08-29 13:58:03.232  Error: dzVents: Error: (3.0.2) TIMER-RPI Health: throttled,0x50005
2021-08-29 13:59:03.377  Error: dzVents: Error: (3.0.2) TIMER-RPI Health: vcgencmd get_throttled
2021-08-29 13:59:03.598  Error: dzVents: Error: (3.0.2) TIMER-RPI Health: throttled,0x50005
Can you help me ?

i'm on RPI2

Multinet
Ohhhhh I have tested it on a RPI 4. Let me build my RPI 2 and get back to you..

Re: Raspberry Pi internal status Dzvents script

Posted: Sunday 29 August 2021 15:24
by freijn
@Multinet

I think you are in troubles.....

0x50005 means you are currently under-voltage and throttled.

I have updated the script in the first post. Please replace the old one with this and let me know.
Also please change your powersupply!

Cheers,

Frank

Re: Raspberry Pi internal status Dzvents script

Posted: Sunday 29 August 2021 16:10
by multinet
Thanks

I think you have an unnexpected } at end of the script ?

What does it means throttled ?

Multinet

Re: Raspberry Pi internal status Dzvents script

Posted: Sunday 29 August 2021 16:57
by Jan Jansen
Thanks, nice script!!

Re: Raspberry Pi internal status Dzvents script

Posted: Sunday 29 August 2021 19:27
by freijn
multinet wrote: Sunday 29 August 2021 16:10 Thanks

I think you have an unnexpected } at end of the script ?
Very much true! Thanks !! Removed it.
What does it means throttled ?
To my understanding ( in your situation ) while voltage is under required, the speed of the PRI is throttled ( reduced/slowed down)
So if you fix your power , you will have a 'faster' PRI.

Bit late, sorry. But thank you for being so quick anb the first one for testing my script!

Frank

Re: Raspberry Pi internal status Dzvents script

Posted: Sunday 29 August 2021 20:05
by Jan Jansen
@ Frank,

The script causes the following error in the domoticz log:

Code: Select all

2021-08-29 19:59:00.508 Error: dzVents: Error: (3.1.7) RPI Sensor Value Script: vcgencmd get_throttled
2021-08-29 19:59:00.528 Error: dzVents: Error: (3.1.7) RPI Sensor Value Script: throttled,0x0 
As far as I know 0x0 means nothing wrong ( https://forum.libreelec.tv/thread/17860 ... throttled/ ). Despite the error message, the alert sensor remains green and also indicates that "Raspberry is feeling happy"

regards,

Jan

Raspberrypi 3B

Re: Raspberry Pi internal status Dzvents script

Posted: Sunday 29 August 2021 20:28
by solarboy
Just loaded this, it's not throwing any errors on a Raspberry Pi 3b and no faults either. Many thanks for sharing !

Re: Raspberry Pi internal status Dzvents script

Posted: Sunday 29 August 2021 20:31
by solarboy
Ooops, spoke too soon...

2021-08-29 19:30:00.379 Status: dzVents: Error (2.4.19): RPI Sensor Value Script: vcgencmd get_throttled
2021-08-29 19:30:00.401 Status: dzVents: Error (2.4.19): RPI Sensor Value Script: An error occured when calling event handler Rpi Undervoltage
2021-08-29 19:30:00.401 Status: dzVents: Error (2.4.19): RPI Sensor Value Script: ...z/scripts/dzVents/generated_scripts/Rpi Undervoltage.lua:46: attempt to call field 'stringSplit' (a nil value)

Re: Raspberry Pi internal status Dzvents script

Posted: Sunday 29 August 2021 20:42
by freijn
Jan Jansen wrote: Sunday 29 August 2021 20:05

The script causes the following error in the domoticz log:

Code: Select all

2021-08-29 19:59:00.508 Error: dzVents: Error: (3.1.7) RPI Sensor Value Script: vcgencmd get_throttled
2021-08-29 19:59:00.528 Error: dzVents: Error: (3.1.7) RPI Sensor Value Script: throttled,0x0 
Jan , I have removed the logging ( was for developing purpose only)
Please find the new version on the start of post V1.3

Thanks for flagging this!

Frank

Re: Raspberry Pi internal status Dzvents script

Posted: Sunday 29 August 2021 20:55
by freijn
solarboy wrote: Sunday 29 August 2021 20:31 2021-08-29 19:30:00.401 Status: dzVents: Error (2.4.19): RPI Sensor Value Script: ...z/scripts/dzVents/generated_scripts/Rpi Undervoltage.lua:46: attempt to call field 'stringSplit' (a nil value)
@Mr Boy

Can you please goto the command line and issue :

vcgencmd get_throttled

and share the output with me?
Are you running on a Raspberry Pi ? What hardware?

Re: Raspberry Pi internal status Dzvents script

Posted: Sunday 29 August 2021 21:37
by solarboy
Hi Freijn..
The output is "throttled=0x80000"
Hope this helps...Raspberry pi 3b if that helps.

Re: Raspberry Pi internal status Dzvents script

Posted: Sunday 29 August 2021 21:54
by freijn
solarboy wrote: Sunday 29 August 2021 21:37 Hi Freijn..
The output is "throttled=0x80000"
Hope this helps...Raspberry pi 3b if that helps.
If you have made a 1 to 1 copy the only issue I can see is the version of DzVents.

I need more time to investigate. sorry..

Frank

Re: Raspberry Pi internal status Dzvents script

Posted: Sunday 29 August 2021 22:09
by solarboy
Ah, it could well be that as I am still on Domoticz 4.10717. I will be upgrading at some point soon anyway and I can give it another try then. I appreciate your time, thank you.

Re: Raspberry Pi internal status Dzvents script

Posted: Sunday 14 July 2024 13:14
by Vasiliy
Thank U, useful thing, before enabling this script i noticed rpi4 high temperatures during summer, now i get temp limit msg.