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.

Somfy RS-485 Protocol
#14
(14.09.2023, 13:41)Joep Wrote: With the script below i now can control one motor. But that motor was already programmed by a remote control. Now my question is if someone can tell me if and how it's possible to program a new motor from scratch on please as i totaly don't understand the protocol and all of its functions. There is no manuel explaining the RTS protocol so i'm really confused..

value = event.getvalue()

require('serial')
port = serial.open('/dev/RS485', {
  baudrate = 4800,
  databits = 8,
  stopbits = 1,
  parity = 'odd',
  duplex = 'half'
})

if value == false then
res, err = port:write(string.char(0x7F,0xF2,0xFA,0xC9,0x7B,0xFA,0x00,0x00,0x00,0xFE,0xFE,0x06,0xA5))
else
  res, err = port:write(string.char(0x7F,0xF2,0xFA,0xC9,0x7B,0xFA,0x00,0x00,0x00,0xFE,0xFD,0x06,0xA4))
end

log(res, err)

You should know address of motors and implement your sendRS485 function with your connection parameters. 
Check code below it would be great if it works you, but I can't be responsible for it. 
It work with my motors.
Code:
-- 1/0 up/down
function rs485windowControl(value, address)
  msg = bit.bxor(0x80, 0xFF)
    len = bit.bxor(0x0D, 0xFF)
    con = bit.bxor(0x05, 0xFF)
    sr1 = bit.bxor(0xFE, 0xFF)
    sr2 = bit.bxor(0xFF, 0xFF)
    sr3 = bit.bxor(0xFF, 0xFF)
    de1 = bit.bxor(0x72, 0xFF)
    de2 = bit.bxor(0xBB, 0xFF)
    de3 = bit.bxor(0x05, 0xFF)
    da1 = bit.bxor(address, 0xFF) -- address

    local da2
    if value then
      da2 = bit.bxor(0x01, 0xFF)
    else
        da2 = bit.bxor(0x02, 0xFF)
    end

    sum = msg + len + con + sr1 + sr2 + sr3 + de1 + de2 + de3 + da1 + da2
    sum1, sum2 = Int16ToBytes(sum, 'little')

    sendRS485(string.char(msg, len, con, sr1, sr2, sr3, de1, de2, de3, da1,da2, sum2, sum1))
end


function rs485windowStop(address)
  msg = bit.bxor(0x80, 0xFF)
    len = bit.bxor(0x0D, 0xFF)
    con = bit.bxor(0x05, 0xFF)
    sr1 = bit.bxor(0xFE, 0xFF)
    sr2 = bit.bxor(0xFF, 0xFF)
    sr3 = bit.bxor(0xFF, 0xFF)
    de1 = bit.bxor(0x72, 0xFF)
    de2 = bit.bxor(0xBB, 0xFF)
    de3 = bit.bxor(0x05, 0xFF)
    da1 = bit.bxor(address, 0xFF) -- address

    da2 = bit.bxor(0x03, 0xFF)
    sum = msg + len + con + sr1 + sr2 + sr3 + de1 + de2 + de3 + da1 + da2
    sum1, sum2 = Int16ToBytes(sum, 'little')

    sendRS485(string.char(msg, len, con, sr1, sr2, sr3, de1, de2, de3, da1,da2, sum2, sum1))
end

function rs485windowSetChannel(address)
  msg = bit.bxor(0x97, 0xFF)
    len = bit.bxor(0x0C, 0xFF)
    con = bit.bxor(0x05, 0xFF)
    sr1 = bit.bxor(0xFE, 0xFF)
    sr2 = bit.bxor(0xFF, 0xFF)
    sr3 = bit.bxor(0xFF, 0xFF)
    de1 = bit.bxor(0x72, 0xFF)
    de2 = bit.bxor(0xBB, 0xFF)
    de3 = bit.bxor(0x05, 0xFF)
    da1 = bit.bxor(address, 0xFF) -- address



    sum = msg + len + con + sr1 + sr2 + sr3 + de1 + de2 + de3 + da1
    sum1, sum2 = Int16ToBytes(sum, 'little')

    sendRS485(string.char(msg, len, con, sr1, sr2, sr3, de1, de2, de3, da1, sum2, sum1))
end

function rs485windowMy(address)
  msg = bit.bxor(0x80, 0xFF)
    len = bit.bxor(0x0D, 0xFF)
    con = bit.bxor(0x05, 0xFF)
    sr1 = bit.bxor(0xFE, 0xFF)
    sr2 = bit.bxor(0xFF, 0xFF)
    sr3 = bit.bxor(0xFF, 0xFF)
    de1 = bit.bxor(0x72, 0xFF)
    de2 = bit.bxor(0xBB, 0xFF)
    de3 = bit.bxor(0x05, 0xFF)
    da1 = bit.bxor(address, 0xFF) -- address

    da2 = bit.bxor(0x04, 0xFF)
    sum = msg + len + con + sr1 + sr2 + sr3 + de1 + de2 + de3 + da1 + da2
    sum1, sum2 = Int16ToBytes(sum, 'little')

    sendRS485(string.char(msg, len, con, sr1, sr2, sr3, de1, de2, de3, da1,da2, sum2, sum1))
end

function rs485windowHeight(value, address)
  local tilt = 1
  if value <= 127 then
    value = 128 - value
  else
    tilt = 0
    value = 256 - value + 127
  end
  msg = bit.bxor(0x81, 0xFF)
    len = bit.bxor(0x0D, 0xFF)
    con = bit.bxor(0x05, 0xFF)
    sr1 = bit.bxor(0xFE, 0xFF)
    sr2 = bit.bxor(0xFF, 0xFF)
    sr3 = bit.bxor(0xFF, 0xFF)
    de1 = bit.bxor(0x72, 0xFF)
    de2 = bit.bxor(0xBB, 0xFF)
    de3 = bit.bxor(0x05, 0xFF)
    da1 = bit.bxor(address, 0xFF) -- address
  da2 = value

    sum = msg + len + con + sr1 + sr2 + sr3 + de1 + de2 + de3 + da1 + da2
    sum1, sum2 = Int16ToBytes(sum, 'little')

    sendRS485(string.char(msg, len, con, sr1, sr2, sr3, de1, de2, de3, da1,da2, sum2, sum1))
end

function Int16ToBytes(num, endian)
  if num < 0 then
      num = bit.band(num, 0xFFFF)
  end

  highByte = bit.rshift(bit.band(num, 0xFF00), 8)
  lowByte  = bit.band(num, 0xFF)

  if endian == "little" then
      lowByte, highByte = highByte, lowByte
  end

  return highByte,lowByte
end
Reply


Messages In This Thread
Somfy RS-485 Protocol - by ceyhanc - 16.01.2017, 11:34
RE: Somfy RS-485 Protocol - by buuuudzik - 16.01.2017, 15:48
RE: Somfy RS-485 Protocol - by ceyhanc - 18.01.2017, 07:50
RE: Somfy RS-485 Protocol - by buuuudzik - 18.01.2017, 08:43
RE: Somfy RS-485 Protocol - by ceyhanc - 18.01.2017, 12:53
RE: Somfy RS-485 Protocol - by buuuudzik - 18.01.2017, 20:03
RE: Somfy RS-485 Protocol - by Ravi Kiran S - 17.09.2020, 16:21
RE: Somfy RS-485 Protocol - by buuuudzik - 17.09.2020, 18:17
RE: Somfy RS-485 Protocol - by Ravi Kiran S - 18.09.2020, 06:54
RE: Somfy RS-485 Protocol - by BrentW - 17.07.2022, 07:53
RE: Somfy RS-485 Protocol - by buuuudzik - 18.09.2020, 08:18
RE: Somfy RS-485 Protocol - by myg - 23.09.2020, 16:19
RE: Somfy RS-485 Protocol - by Joep - 14.09.2023, 13:41
RE: Somfy RS-485 Protocol - by Bitver - 14.09.2023, 20:37
RE: Somfy RS-485 Protocol - by Joep - 15.09.2023, 12:04
RE: Somfy RS-485 Protocol - by Bitver - 15.09.2023, 19:47
RE: Somfy RS-485 Protocol - by Joep - 18.09.2023, 11:01

Forum Jump: