Logic Machine Forum
Thresholds - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Thresholds (/showthread.php?tid=5206)



Thresholds - Bergman - 17.01.2024

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


RE: Thresholds - RomansP - 17.01.2024

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



RE: Thresholds - Bergman - 17.01.2024

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


RE: Thresholds - RomansP - 18.01.2024

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.