This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Thresholds
#1
Hi,

I have a humidity sensor with no threshold options, it only sends humidity on change.
I also have a dimmer which controls a fan and I want to control the fan with value depending on humidity level. 
In 2 or 3 steps/thresholds. 

Have been searching the forum but cannot find any similar, perhaps im using the wrong keywords.
Anyone who can give me a tip on what to use?

Regards,
Peter
Reply
#2
HI Bergman

I am not sure that it is exactly what you need, but have a try,
and please give me feedback.

This code is for humidity scale object (event script).

Code:
local humidity = event.getvalue() -- scale object

local fan_addr = '38/1/26' -- scale object

local fan_val_level_1 = 30 -- values for scale object
local fan_val_level_2 = 60
local fan_val_level_3 = 100

if humidity < 33 then -- humidity less than 33%
  grp.write(fan_addr, fan_val_level_1)
elseif humidity > 38 and humidity < 66 then -- 38% < humidity < 66%
  grp.write(fan_addr, fan_val_level_2)
elseif humidity > 71 then -- humidity more than 71%
  grp.write(fan_addr, fan_val_level_3)
end

Regards,
Romans

Here is updated version of the script.

Code:
local humidity = event.getvalue() -- scale object

local fan_addr = '38/1/26' -- scale object

local fan_val_level_1 = 30 -- values for scale object
local fan_val_level_2 = 60
local fan_val_level_3 = 100

local hyst = 5 -- 5% humidity hysteresis

local hum_level_1 = 33 -- 33% humity
local hum_level_2 = 66 -- 66% humidity

if humidity < hum_level_1 then -- humidity less than 33%
  grp.write(fan_addr, fan_val_level_1)
elseif humidity > hum_level_1 + hyst and humidity < hum_level_2 then -- 38% < humidity < 66%
  grp.write(fan_addr, fan_val_level_2)
elseif humidity > hum_level_2 + hyst then -- humidity more than 71%
  grp.write(fan_addr, fan_val_level_3)
end
Reply
#3
Thank you RomansP!

I think I can use alot of that to make my own newbie-script work.

You start off with "Local", what/how does that do/work? I haven't used that or read about it so far.

Regards, 
Peter
Reply
#4
In Lua, variables can be either local or global, and their scope determines where they can be accessed.
If before variable is local - means variable is local, if before variable is nothing it means variable is global.

Here is a pretty good summary about lua.
https://learnxinyminutes.com/docs/lua/

But you also can use chatGPT to improve your coding and ask some questions about code.

Regards,
Romans.
Reply


Forum Jump: