Jump to content

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

Posted

Hey people, what up?

 

 

 

I need your help. I am trying to program via LUA in my HC2 an scene where the gateway can wake up the dead nodes at certain date, down below you will find the code:

 

--[[
%% properties
 
%% globals
--]]
 
local NB_DEVICES = 20
 
function wakeupDeadNodes()
    fibaro:debug('Wakeup dead nodes.')
 
    -- Check all devices
    for i = 1, NB_DEVICES do
        local status = fibaro:getValue(i, 'dead');
        if status >= "1" then 
            fibaro:debug(i..': DEAD'); 
            fibaro:wakeUpDeadDevice(i) 
            fibaro:sleep(5000) --check again in 5 sec 
            status = fibaro:getValue(i, 'dead'); 
            if status >= "1" then
                fibaro:debug(i..': Really dead') 
            else
                fibaro:debug(i..': Now OK') 
            end 
        end
    end
 
end
 
local sourceTrigger = fibaro:getSourceTrigger();
if (sourceTrigger["type"] == "autostart") then
    while true do
        fibaro:debug('Scene automatically called.')
 
        local currentDate = os.date("*t");
 
        -- Wakeup nodes only Monday-Saturday from 10:00 to 11:00
        if ((currentDate.wday >= 2 and currentDate.wday <= 7) and (currentDate.hour >= 10 and currentDate.hour <= 11 )) then
        
            fibaro:debug('Nodes automatically waked up.')
            wakeupDeadNodes()
        end
 
        fibaro:sleep(30*60000); -- Run every 30 minutes
    end
else
 
    local currentDate = os.date("*t");
    local startSource = fibaro:getSourceTrigger();
    if (startSource["type"] == "other")
    then
        wakeupDeadNodes()
    end
end
 
 
Once i click on "Start" to debug the LUA code it says:
 
[DEBUG] 17:28:40: Wakeup dead nodes.
[DEBUG] 17:28:40: line 15: attempt to compare string with nil
 
 
Please check the code and help me, i don't know what could be wrong with the code, i think is fine.
 
Thanks in advance!!

 

5 answers to this question

Recommended Posts

  • 0
Posted

I trust you resolved this issue way back. I accidentally ran into your post, searching for something else.

Quote

if status >= "1" then 

 

I assume the issue is that '>=' does not work for strings. If 'status' is a string, first make it a number using tonumber():

 

Please login or register to see this code.

 

If it is already a number, it is even easier:

 

Please login or register to see this code.

 

  • 0
Posted

could you kindly explain to me how to correctly perform the scene?
I have the same problem
thanks

  • 0
Posted (edited)

Hello ,

in the code you can find this multiple times : 

Please login or register to see this code.

And you need to change :

 

Please login or register to see this code.

 

in 

Please login or register to see this code.

Please login or register to see this code.

Using  tonumber(status) HC2 will allways know that status is a number and not a string (text);

 

 

Edited by madmann95
  • 0
Posted

tks

i have change but this is the error give me

Please login or register to see this image.

/monthly_2020_06/error.png.2c43992473af73429cb1364bab6f57e9.png" />

 

  • 0
Posted

local status = fibaro:getValue(i, 'dead');

if status ~= nil then

if status >= "1" then

local d_status = "dead"

else

local d_status = "ok"

end

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...