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
.
.
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
}