Example: Constant lighting control with Logic Machine

Task

Dimm lights with values received from lighting sensor, only if the binary object ‘gate’ is 1. If ‘gate’ is 0, the program send 0 to output object.
Start dimming also if the object ‘gate’ changes from 0 to 1.
Input: 2/1/1
Gate: 2/1/2
Output: 2/1/3

Add the following function to Scripting–>Tools–>User function library

Source code    
  1. function checkdimmer(event, ctrl, out)
  2. -- get input sensor value from group write event
  3. local value = dpt.decode(event.datahex, dt.scale)
  4.  
  5. -- if gate is disabled, set value to 0
  6. if not grp.getvalue(ctrl) then
  7. value = 0
  8. end
  9.  
  10. -- write to output
  11. grp.write(out, value, dt.scale)
  12. end
  13.  
  14. function checkgate(event, inp, out)
  15. local value = 0
  16.  
  17. -- gate is on, get value from input
  18. if dpt.decode(event.datahex, dt.bool) then
  19. value = grp.getvalue(inp)
  20. end
  21.  
  22. -- write to output
  23. grp.write(out, value, dt.scale)
  24. end

Add Event-based script for the group-address 2/1/1 (Input) with the the following code

Constant Light Logic Machine 2

Source code    
  1. checkdimmer(event, '2/1/2', '2/1/3')

Add Event-based script for the group-address 2/1/2 (Gate) with the the following code

Source code    
  1. checkgate(event, '2/1/1', '2/1/3')