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.

Blinds Control - Multiple Socket Connections Per Script
#1
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

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;
Reply


Messages In This Thread
Blinds Control - Multiple Socket Connections Per Script - by jamesng - 09.02.2020, 06:04

Forum Jump: