Welcome to Smart Home Forum by FIBARO
Dear Guest,
as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.
As a member you can:
- Start new topics and reply to others
- Follow topics and users to get email updates
- Get your own profile page and make new friends
- Send personal messages
- ... and learn a lot about our system!
Regards,
Smart Home Forum by FIBARO Team
Question
natrimed 1
Hi all
Trying to set an auto reboot if the Fibaro free memory gets too low. I am using the following script but get an error. Please let me know how to correct the error.
Lua code:
--[[
%% properties
%% time
%% events
%% globals
--]]
-- Function to check free memory percentage
local function checkFreeMemory()
-- Get current free memory percentage
local totalMemory = fibaro:getGlobalValue("memoryTotal")
local freeMemory = fibaro:getGlobalValue("memoryFree")
local totalMemoryNum = tonumber(totalMemory)
local freeMemoryNum = tonumber(freeMemory)
local freeMemoryPercentage = (freeMemoryNum / totalMemoryNum) * 100
fibaro:debug("Free memory percentage: " .. freeMemoryPercentage .. "%")
-- Check if free memory is below the threshold (15%)
if freeMemoryPercentage and freeMemoryPercentage < 70 then
fibaro:debug("Free memory is below 15%. Pressing button 1 on virtual device 533...")
fibaro:call(533, "pressButton", "1")
else
fibaro:debug("Free memory is within acceptable limits.")
end
end
-- Function to schedule memory check at 3 AM every day
local function scheduleMemoryCheck()
-- Schedule memory check at 3 AM
local currentDate = os.date("*t")
local checkTime = os.time({year=currentDate.year, month=currentDate.month, day=currentDate.day, hour=3, min=0, sec=0})
local currentTime = os.time()
-- Calculate time until next scheduled check
local timeUntilCheck = checkTime - currentTime
-- Schedule memory check
if timeUntilCheck > 0 then
fibaro:debug("Next memory check scheduled for 3 AM.")
setTimeout(function()
checkFreeMemory()
end, timeUntilCheck * 1000)
else
fibaro:debug("Invalid check time. Please set a valid time.")
end
end
-- Call the function to schedule memory check
scheduleMemoryCheck()
ERROR is:
[DEBUG] 18:15:01: 2024-05-11 18:15:01.004377 [ error] timer handler failed with error: /opt/fibaro/scenes/196.lua:18: attempt to perform arithmetic on local 'freeMemory' (a nil value)
Link to comment
Share on other sites
6 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.