Shutter controller based on LM5
Example: Shutter and curtain controller based on LM5
Step-by-step guide standard motors
1. Add to Common Functions:
- function shutters(event, in_a, in_b, out_a, out_b, mode_alt)
- local value = event.getvalue()
- local out, out_alt
-
- -- a = move up/down; b = stop
- if mode_alt then
- -- true (up) = output a, false (down) = output b
- out = value and out_a or out_b
- -- output value for input a (up/down) = true, for input b (stop) = false
- value = event.dst == in_a
- -- a = move up/stop; b = move down/stop
- else
- -- event from input a = output a, event for input b = output b
- out = event.dst == in_a and out_a or out_b
- end
-
- -- alternative output, a => b / b => a
- out_alt = out == out_a and out_b or out_a
-
- -- turn off alternative output
- grp.checkwrite(out_alt, false)
- grp.checkwrite(out, value)
- end
2. Create event scripts for two input objects (same script for each input).
Standard mode: A = move up/stop; B = move down/stop:
- shutters(event, '1/1/1', '1/1/2', '1/1/3', '1/1/4')
Alternative mode: A = move up/down; B = stop:
- 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.
- maxdelta = 60 -- turn off after 60 seconds
-
- objs = grp.tag('auto-off')
- for _, obj in ipairs(objs) do
- if obj.value then
- delta = os.time() - obj.updatetime
- if delta >= maxdelta then
- obj:write(false)
- end
- end
- 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
- value = event.getvalue()
- dst = value and '1/1/2' or '1/1/3'
-
- grp.write(dst, true)
- os.sleep(0.5)
- grp.write(dst, false)
2. Move left event script for 1/1/1. 1/1/3 – stop relay
- value = event.getvalue()
- dst = value and '1/1/1' or '1/1/3'
-
- grp.write(dst, true)
- os.sleep(0.5)
- grp.write(dst, false)