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.

Scripting with two thresholds for changing the status of two Objects
#1
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
Reply
#2
Not sure about event, but should work as resident.


Sent fra min SM-G980F via Tapatalk
Reply
#3
I would use grp.checkwrite as now each incoming event will write to the output also when output conditions are the same..
Reply
#4
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)
Reply


Forum Jump: