Somfy RS232 transmitter

Discussion in 'C-Bus Automation Controllers' started by Ishir92, Mar 15, 2023.

  1. Ishir92

    Ishir92

    Joined:
    Aug 21, 2013
    Messages:
    10
    Likes Received:
    0
    Location:
    Victoria
    I am trying to control three Somfy RTS blinds using eDLT switches.
    I am able to control each of the blinds through the 5500SHAC with the Somfy RS232 transmitter.
    I am also able to control the blinds using my smart phone.
    However, I would like to control each blind in each room using the eDLT switch.
    I have set the switch to a shutter relay. It is my understanding that this works with a shutter relay. Somehow I need the switch to send RS232 commands (I think)
    Any help would be greatly appreciated.
     
    Ishir92, Mar 15, 2023
    #1
  2. Ishir92

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,521
    Likes Received:
    173
    Location:
    Adelaide, Australia
    When you set the eDLT to shutter control it sets up a number of presets for each operation. All the possible ones are:

    0%: Close
    1%: Close/Stop toggle
    2%: Stop
    98%: Toggle (open/stop/close/stop)
    99%: Open/Stop toggle
    100%: Open

    All you need to do is set an event in the SHAC and check these value of the ga. Any other value is a percentage open.
     
    Ashley, Mar 15, 2023
    #2
  3. Ishir92

    Ishir92

    Joined:
    Aug 21, 2013
    Messages:
    10
    Likes Received:
    0
    Location:
    Victoria
    Hi Ashely,

    Many thanks for your reponse. I am still confused. Do I set an event script for each blind on the objects page.
    I can see OPEN, CLOSE and STOP on the tag map for each blind. Please see attached event I have created for one of my blinds.
     

    Attached Files:

    Ishir92, Mar 15, 2023
    #3
  4. Ishir92

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,521
    Likes Received:
    173
    Location:
    Adelaide, Australia
    Unfortunately the eDLT doesn't make this easy. It assumes you are using a shutter relay. When you set it to 2 button shutter it sets the left button to close/stop (1%), and the right button to open/stop (99%). When you press a button it just sends out that value and the shutter relay looks at its current state and if it's currently moving it stops it, and if currently stopped sets it's direction to close or open as appropriate.

    This mean that the event script is going to have to do the toggling and hence keep track of what the blind was doing. This is made complex by the fact that event scripts don't support lua global variables so the only way to save context between events is to use the storage.set and storage.get to remember what you did on the last event to convert the toggle command to open/close/stop that the somfy blinds understand. Whether you are up to the challenge is entirely up to you :)

    It is possible to write a single event script for all blinds. If you give them all the same keyword, then when the event occurs you can get the last state and appropriate somy command out of a (predefined) dictionary (i.e. storage) using the group name as a base for the key. If you get this to work consider yourself a lua guru.

    Interestingly, I am doing a similar thing with DLT's and a Wiser logic engine and it's so much simpler than with eDLT's and the SHAC. But that's progress for you :(

    If you have a go I'm happy to help, but not really in a position to write it for you.
     
    Ashley, Mar 15, 2023
    #4
  5. Ishir92

    Ishir92

    Joined:
    Aug 21, 2013
    Messages:
    10
    Likes Received:
    0
    Location:
    Victoria
    Hi Ashley many thanks for the reply. WOW, I think my head just exploded. What you have proposed is way above my capabilities. I dont even know where to start. I am assuming that storage.get and storage.set are LUA commands? This will be an interesting project. I will give it a try and see what happens. Once again your advise is greatly appreciated.
     
    Ishir92, Mar 16, 2023
    #5
  6. Ishir92

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,521
    Likes Received:
    173
    Location:
    Adelaide, Australia
    So I had a go at this as I thought it would be useful for others to see how you can use a single script to control multiple devices.

    The first thing to do is define all your blinds in the startup script as follwos:

    Code:
    --
    -- Somfy blind control from shutter commands
    --
    -- 2 Lines for each blind
    -- 1st line is group address and somfy address (without operation code at end)
    -- 2nd line is shutter timeout value. Can be ommitted if same as DEFAULT_SHUTTER_TIMEOUT value in event script
    --
    storage.set('0/56/20', '0101') -- Blind 1 e.g. local lighting ga 20 etc
    storage.set('0/250/20 Timeout', 20)
    storage.set('0/56/13', '0102')  -- Blind 2
    storage.set('0/250/13 Timeout', 30) -- Could be omitted as default is 30 seconds
    -- etc etc
    
    You then need to add a keyword to each of the objects to trigger the event script (I just used 'somfy'

    Then create a new event script with your chosen keyword:

    Code:
    --
    -- Convert shutter commands to somfy serial commands.
    -- See startup script for setup instructions
    -- Called via common keyword applied to all objects defined in startup script
    --
    -- Assumes only close, close/stop, open/stop, open value are used
    -- 2 button shutter (i.e.eDLT) should only give close/stop, open/stop
    --
    DEFAULT_SHUTTER_TIMEOUT = 30 -- Default shutter timeout if not in initialisation
    
    ga = event.dst -- Get event group address (e.g. 0/56/nn). This is the main storage key
    timeKey = ga..' Time'  -- Create the key to get time when blind last stopped (or still moving if in future)
    stopTime = storage.get(timeKey, 0) -- And fetch the time till blind stops
    isMoving = os.time() < stopTime -- True if still moving
    -- Calculate operation required
    value = event.getvalue() -- Current value of ga
    if isMoving then op = 'S' -- Moving, so stop it
    elseif value < 3 then op = 'D' -- 0=close, 2=close/stop
    elseif value > 252 then op = 'O' -- 255=open, 253=open/stop
    else op = 'S' -- Any other value
    end
    -- If now moving set new timeout
    if isMoving then -- Was moving, so now will be stopped
      timeout = 0
    else
      timeout = storage.get(ga..' Timeout', DEFAULT_SHUTTER_TIMEOUT) -- Shutter timeout value (i.e. time till stopped)
    end
    storage.set(timeKey, os.time() + timeout) -- New time when blind will have stopped, or now if we are stopping it
    -- Now we can send command
    command = storage.get(ga) -- Get the somfy command for this ga (or nil if not there)
    if command then -- Valid group address so output command
      command = command..op -- Somy command address plus operation
      require('serial')
      port = serial.open('/dev/RS232', {
          baudrate = 9600
          })  -- All other defaults are ok
      if port then port:write(command) end
      log(ga, command)
    end
    
    I can't test the serial comms as I don't have any somfy blinds, but it logs the correct values.
    (Hopefully the forum doesn't screw up the lua code too much as it is wont to do :)

    Hopefully this helps

    Let me know if you don't understand anything
     
    Ashley, Mar 16, 2023
    #6
  7. Ishir92

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,521
    Likes Received:
    173
    Location:
    Adelaide, Australia
    Naturally the forums screwed this up. I wish someone would fix this for Lua code.

    The startup code should be :

    storage.set('0/250/20', '0101') -- Blind 1
    storage.set('0/250/20 Timeout', 60) -- etc

    And the serial open command should be

    port = serial.open('/dev/RS232', {
    baudrate = 9600
    }) -- All other defaults are ok
     
    Ashley, Mar 17, 2023
    #7
  8. Ishir92

    Ishir92

    Joined:
    Aug 21, 2013
    Messages:
    10
    Likes Received:
    0
    Location:
    Victoria
    Hi Ashley,

    Many, many thanks for posting your code.
    I made a couple of changes to suit my setup and it works perfectly.
    I have attached a copy of your code including my amendments.

    Screenshot 2023-03-18 at 9.14.23 pm.png

    Once again many thanks for posting, I would never have been able to do it without your help.

    Cheers,
     
    Ishir92, Mar 18, 2023
    #8
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.