Logic Machine Forum
Scripting with two thresholds for changing the status of two Objects - 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: Scripting with two thresholds for changing the status of two Objects (/showthread.php?tid=3078)



Scripting with two thresholds for changing the status of two Objects - andeug - 25.12.2020

Hi,


I am having a humidity sensor which I need to set it to write the status on an Object if the humidity goes below 30%, or write the status on other Object if the humidity goes over 50%. The below example is an Event-based script associated to an Object and I am not sure if I have done it correctly, or if it should exist as Resident script. 


Code:
value = event.getvalue()

if value < 30 then
  grp.write('1/4/11', 1)
else
  grp.write('1/4/11', 0)

end

if value > 50 then
  grp.write('1/4/14', 1)
else
  grp.write('1/4/14', 0) 
   
end

I see no errors while saving this script. Based on how is it coded, the Objects 1/4/11 and 1/4/14 will always be written with 0 if the read value is between 30 and 50?


Thank you,
Andreas


Scripting with two thresholds for changing the status of two Objects - tomnord - 25.12.2020

Not sure about event, but should work as resident.


Sent fra min SM-G980F via Tapatalk


RE: Scripting with two thresholds for changing the status of two Objects - Erwin van der Zwart - 25.12.2020

I would use grp.checkwrite as now each incoming event will write to the output also when output conditions are the same..


RE: Scripting with two thresholds for changing the status of two Objects - admin - 28.12.2020

No need for a resident script and as Erwin said you should use checkwrite. The script can be simplified this way:
Code:
value = event.getvalue()
grp.checkwrite('1/4/11', value < 30)
grp.checkwrite('1/4/14', value > 50)