Raspberry Pi internal status Dzvents script

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Raspberry Pi internal status Dzvents script

Post 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 2726 times
rpiunhappy.JPG
rpiunhappy.JPG (18.26 KiB) Viewed 2726 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
}
Last edited by freijn on Sunday 29 August 2021 20:39, edited 3 times in total.
multinet
Posts: 97
Joined: Friday 05 December 2014 22:52
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Raspberry Pi internal status Dzvents script

Post 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
PI 2 - Domoticz 2021.1
RFXCOM - RFXtrx433 USB 433.92MHz Transceiver (5 DIO 54755 + 2 DIO 54756 + 3 DIO 54798)
Z-Wave.Me ZME_UZB1 USB Stick (6 FGSD002 + 2 FGRM222 + 1 FGS223 + 1 FGMS001-ZW5 + 1 FGRGBWM441 + 1 FGBS001 + 2 FGFS101)
6 sondes DS18B20
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: Raspberry Pi internal status Dzvents script

Post 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..
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: Raspberry Pi internal status Dzvents script

Post 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
multinet
Posts: 97
Joined: Friday 05 December 2014 22:52
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Raspberry Pi internal status Dzvents script

Post by multinet »

Thanks

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

What does it means throttled ?

Multinet
PI 2 - Domoticz 2021.1
RFXCOM - RFXtrx433 USB 433.92MHz Transceiver (5 DIO 54755 + 2 DIO 54756 + 3 DIO 54798)
Z-Wave.Me ZME_UZB1 USB Stick (6 FGSD002 + 2 FGRM222 + 1 FGS223 + 1 FGMS001-ZW5 + 1 FGRGBWM441 + 1 FGBS001 + 2 FGFS101)
6 sondes DS18B20
Jan Jansen
Posts: 229
Joined: Wednesday 30 April 2014 20:27
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

Re: Raspberry Pi internal status Dzvents script

Post by Jan Jansen »

Thanks, nice script!!
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: Raspberry Pi internal status Dzvents script

Post 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
Jan Jansen
Posts: 229
Joined: Wednesday 30 April 2014 20:27
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

Re: Raspberry Pi internal status Dzvents script

Post 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
solarboy
Posts: 300
Joined: Thursday 01 November 2018 19:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.6
Location: Portugal
Contact:

Re: Raspberry Pi internal status Dzvents script

Post by solarboy »

Just loaded this, it's not throwing any errors on a Raspberry Pi 3b and no faults either. Many thanks for sharing !
Intel NUC with Ubuntu Server VM (Proxmox),mosquitto(docker),RFXtrx433E,zwavejsUI (docker),Zigbee2mqtt(docker),SMA Hub (docker),Harmony Hub plugin, Kodi plugin,Homebridge(docker)+Google Home,APC UPS,SMA Modbus,Mitsubishi MQTT, Broadlink,Dombus
solarboy
Posts: 300
Joined: Thursday 01 November 2018 19:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.6
Location: Portugal
Contact:

Re: Raspberry Pi internal status Dzvents script

Post 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)
Intel NUC with Ubuntu Server VM (Proxmox),mosquitto(docker),RFXtrx433E,zwavejsUI (docker),Zigbee2mqtt(docker),SMA Hub (docker),Harmony Hub plugin, Kodi plugin,Homebridge(docker)+Google Home,APC UPS,SMA Modbus,Mitsubishi MQTT, Broadlink,Dombus
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: Raspberry Pi internal status Dzvents script

Post 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
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: Raspberry Pi internal status Dzvents script

Post 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?
solarboy
Posts: 300
Joined: Thursday 01 November 2018 19:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.6
Location: Portugal
Contact:

Re: Raspberry Pi internal status Dzvents script

Post by solarboy »

Hi Freijn..
The output is "throttled=0x80000"
Hope this helps...Raspberry pi 3b if that helps.
Intel NUC with Ubuntu Server VM (Proxmox),mosquitto(docker),RFXtrx433E,zwavejsUI (docker),Zigbee2mqtt(docker),SMA Hub (docker),Harmony Hub plugin, Kodi plugin,Homebridge(docker)+Google Home,APC UPS,SMA Modbus,Mitsubishi MQTT, Broadlink,Dombus
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: Raspberry Pi internal status Dzvents script

Post 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
solarboy
Posts: 300
Joined: Thursday 01 November 2018 19:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.6
Location: Portugal
Contact:

Re: Raspberry Pi internal status Dzvents script

Post 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.
Intel NUC with Ubuntu Server VM (Proxmox),mosquitto(docker),RFXtrx433E,zwavejsUI (docker),Zigbee2mqtt(docker),SMA Hub (docker),Harmony Hub plugin, Kodi plugin,Homebridge(docker)+Google Home,APC UPS,SMA Modbus,Mitsubishi MQTT, Broadlink,Dombus
Vasiliy
Posts: 2
Joined: Saturday 13 July 2024 7:46
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Raspberry Pi internal status Dzvents script

Post by Vasiliy »

Thank U, useful thing, before enabling this script i noticed rpi4 high temperatures during summer, now i get temp limit msg.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest