Example: Shutter and curtain controller based on LM5

Step-by-step guide standard motors

1. Add to Common Functions:

Source code    
  1. function shutters(event, in_a, in_b, out_a, out_b, mode_alt)
  2. local value = event.getvalue()
  3. local out, out_alt
  4.  
  5. -- a = move up/down; b = stop
  6. if mode_alt then
  7. -- true (up) = output a, false (down) = output b
  8. out = value and out_a or out_b
  9. -- output value for input a (up/down) = true, for input b (stop) = false
  10. value = event.dst == in_a
  11. -- a = move up/stop; b = move down/stop
  12. else
  13. -- event from input a = output a, event for input b = output b
  14. out = event.dst == in_a and out_a or out_b
  15. end
  16.  
  17. -- alternative output, a => b / b => a
  18. out_alt = out == out_a and out_b or out_a
  19.  
  20. -- turn off alternative output
  21. grp.checkwrite(out_alt, false)
  22. grp.checkwrite(out, value)
  23. end

2. Create event scripts for two input objects (same script for each input).

Standard mode: A = move up/stop; B = move down/stop:

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

Alternative mode: A = move up/down; B = stop:

Source code    
  1. shutters(event, '1/1/1', '1/1/2', '1/1/3', '1/1/4', true)

Addresses:
1/1/1 – input A
1/1/2 – input B
1/1/3 – relay A
1/1/4 – relay B

3. (Optional) To turn relays off automatically after a certain time add “auto-off” tag to each relay object.
Create a single resident script with 2-3 seconds of sleep time. Adjust maxdelta variable as needed.

Source code    
  1. maxdelta = 60 -- turn off after 60 seconds
  2.  
  3. objs = grp.tag('auto-off')
  4. for _, obj in ipairs(objs) do
  5. if obj.value then
  6. delta = os.time() - obj.updatetime
  7. if delta >= maxdelta then
  8. obj:write(false)
  9. end
  10. end
  11. end

 

Curtain controller for motor with dry contacts

If you are using for example Somfy Movelite motor (with dry contacts) to control your curtains, you need to have 3 relays to operate – left, right, stop. The following example enables such functionality: long press – move left/right, short press – stop movement. You can use automatic turn-off relays script from the above example aswell.

When you send 1, the script gives impulse to one object. If 0 – to another.

1. Move right event script for grp 1/1/2. 1/1/3 – stop relay

Source code    
  1. value = event.getvalue()
  2. dst = value and '1/1/2' or '1/1/3'
  3.  
  4. grp.write(dst, true)
  5. os.sleep(0.5)
  6. grp.write(dst, false)

2. Move left event script for 1/1/1. 1/1/3 – stop relay

Source code    
  1. value = event.getvalue()
  2. dst = value and '1/1/1' or '1/1/3'
  3.  
  4. grp.write(dst, true)
  5. os.sleep(0.5)
  6. grp.write(dst, false)