Hi
I'm trying to control Somfy blinds by issuing an UP or DOWN command followed by a STOP command a few seconds later to achieve a partially open blind. ie: to automatically open the blind 30%.
I'm making a socket connection to the Somfy controller - this works fine - however I don't seem be able to send two separate commands over two socket connections from the one event-based script. The second sendCommand never gets sent. The controller is able to receive multiple commands ok when triggered from separate buttons / scripts within the same timeframe.
Is there a different way to code this so that the LUA sends the second command?
Thanks in advance
Kind Regards
James
FUNCTION
SCRIPT
I'm trying to control Somfy blinds by issuing an UP or DOWN command followed by a STOP command a few seconds later to achieve a partially open blind. ie: to automatically open the blind 30%.
I'm making a socket connection to the Somfy controller - this works fine - however I don't seem be able to send two separate commands over two socket connections from the one event-based script. The second sendCommand never gets sent. The controller is able to receive multiple commands ok when triggered from separate buttons / scripts within the same timeframe.
Is there a different way to code this so that the LUA sends the second command?
Thanks in advance
Kind Regards
James
FUNCTION
Code:
function sendCommand(command)
local socket = require("socket").tcp()
data, err = socket:connect('192.168.1.200', 4999)
data, err = socket:send(command .. '\x0D\x0A')
end
SCRIPT
Code:
BlindsTravel = 22; -- Time in seconds to fully open/close
BlindsStep = math.round(100/BlindsTravel); -- Number of percentage steps to move per second
BlindsNewPosition = GetUserParam('Wired', 'BlindsNewPosition');
BlindsCurrentPosition = GetUserParam('Wired', 'BlindsCurrentPosition');
-- Move Blind Down / Open
if (BlindsNewPosition > BlindsCurrentPosition) then
sendCommand('0113D\x0D\x0A'); -- Send down command
while (BlindsNewPosition >= BlindsCurrentPosition) do
-- Update current position of blind during movement
os.sleep(1)
BlindsCurrentPosition = BlindsCurrentPosition + BlindsStep;
SetUserParam('Wired', 'BlindsCurrentPosition-Study', BlindsCurrentPosition);
-- Stop blind when blind has moved to new position
if (BlindsCurrentPosition >= BlindsNewPosition) then
sendCommand('0113S\x0D\x0A'); -- Send stop command (never gets sent)
end;
end;
end;