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


  • 0

Virtual thermostat issue


Question

Posted

Hi guys, 

 

I am trying to create a virtual thermostat in HC2 using a fibaro flood sensor for temperature sensor and an everspring wallplug for on/off switching. In practice different devices will be used this is just to see if it works. In virtual devices I create a slider(for setting the temperature) and a label. Once I input all the codes I get an error message saying: "line4: attempt to compare string with nil"

 

These are the codes:

 

For the slider:

function map_range( a1, a2, b1, b2, s )
return math.floor(b1 + (s-a1)*(b2-b1)/(a2-a1))
end
111 = map_range(0, 100, 10, 35, _sliderValue_ )
fibaro:setGlobal("111", 111)
fibaro:call(fibaro:getSelfId(), "setProperty", "ui.label1.value", 111)

 

For the main loop:

roomTemp = fibaro:getValue(14, "value");
roomSetTemp = fibaro:getGlobal("111");
if (roomSetTemp > roomTemp) then
  fibaro:debug("on")
  fibaro:call(16, "turnOn")
elseif
  (roomSetTemp <= roomTemp) then
  fibaro:debug("off")
  fibaro:call(16, "turnOff")
end

 

111 - room number

14 - flood temp sensor id

16 - wallplug id

 

 

I have played around with this and from what I can gather the problem is somewhere in the roomsettemp part of the code. I'd apreciate the help if anybody has any idea whats wrong. I got this process of creating a virtual thermostat somewhere online. 

 

 

5 answers to this question

Recommended Posts

  • 0
Posted

Hi @Iztok88 and welcome to Fibaro forum!

 

You cannot use number as local variable so replace 111 with _111 and then it might work.

 

  • 0
  • Inquirer
  • Posted

    Hi @Sankotronic 

     

    Thanks for the response. Yeah i've tried to change that to _111 and a few other things as well (t_111 was in the original example), unfortunatley it doesn't really change anything.

     

    Given the error(compare string with nil) i'm now trying the tonumber() command with the roomTemp and the roomSetTemp but it just reports a different error(compare number with nil)

     

    Anyway, thanks for the help.  

    • 0
    Posted (edited)

    Hi @Iztok88,

     

    Here, put this code for slider:

    Please login or register to see this code.

    and then put this code to main loop:

    Please login or register to see this code.

    Since you can't use 111 as a name for global variable (I tested and system does not allow that!!!) you can add "TempSet" global variable. 

     

    Then you had typo in "ui.Label1.value" since system gives that name with big L in Label and you put small l. If you make such typo system is not giving you any errors just value is not displayed on label as expected.

     

    When you are using commands for devices like fibaro:call(16, "turnOn") and putting them in some loop, then it is necessary and required practice that you check if device is turned On and send command only if it is not. Otherwise if you make several loops like the one above you will quickly end up with system not responding and with delays because z-wave network will be overwhelmed with so many commands send!

     

    I tested above code on my HC2 and it is working as expected, except I was turning light on/off, and I used temperature sensor from motion sensor.

    Edited by Sankotronic
    • 0
  • Inquirer
  • Posted

    Thanks for the help, but I am getting the same result.

    Line4: attempt to compare string with nil.

     

    I copy pasted your code and then tried some stuff. Tried using different devices and changing some of the variables but just can't get it to work. 

     

     

    • 0
    Posted
    2 hours ago, Iztok88 said:

    Thanks for the help, but I am getting the same result.

    Line4: attempt to compare string with nil.

     

    I copy pasted your code and then tried some stuff. Tried using different devices and changing some of the variables but just can't get it to work. 

     

     

     

    Did you add global variable "TempSet" to variable panel

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