Control Daikin Splits using NAC via Global Cache IP2IR

Discussion in 'C-Bus Automation Controllers' started by philthedill, Nov 23, 2020.

  1. philthedill

    philthedill

    Joined:
    Mar 21, 2010
    Messages:
    142
    Likes Received:
    4
    Location:
    Melbourne
    Help please, I plan to control my Daikin Splits using SHAC via Global Cache IP2IR devices. The challenge is how to send the message from (S)NAC to the Global Cache device which is described in the attached doc. I have extracted the following relevant bit....
    "Communication with the iTach is accomplished by opening a TCP socket on Port 4998. All commands
    and data, with the exception of serial (RS232) data, are communicated through Port 4998. Port 4998 is
    used for such things as iTach status, IR data, relay operation, and reading digital input states. All
    information, with the exception of serial data, is communicated by comma delimited ASCII text strings
    terminated by a carriage return (↵)." ​
    In summary, I need to be able to send something like this (capture from the AC remote) to IP 192.168.86.93 on port 4998 from a shac event script
    <sendir,1:1,1,36764,1,1,16,15,16,16,16,16,16,16,15,16,16,935,128,64,16,48,16,15,16,16,16,16,16,48,16,16,15,16,16,16,16,16,16,48,16,15,16,48,16,48,16,16,16,48,16,48,16,48,16,48,16,48,16,16,16,16,15,49,15,16,16,16,16,16,15,16,16,16,16,16,16,15,16,16,16,16,16,16,15,49,15,16,16,48,16,16,16,16,16,15,16,48,16,48,16,16,16,16,16,16,15,16,16,16,16,16,15,16,16,16,16,16,16,15,16,16,16,16,16,16,15,16,16,16,16,16,16,48,16,48,16,48,16,15,16,48,16,16,16,48,16,48,16,1285,128,64,16,48,16,16,16,15,16,16,16,48,16,16,16,16,15,16,16,16,16,48,16,16,16,48,16,48,16,15,16,48,16,48,16,48,16,48,16,48,16,16,16,16,16,48,16,16,15,16,16,16,16,16,16,15,16,16,16,16,16,15,16,16,16,16,16,16,15,49,15,16,16,16,16,16,16,15,16,48,16,16,16,48,16,48,16,16,16,16,15,49,15,16,16,48,16,16,16,48,16,16,16,15,16,16,16,48,16,48,16,16,16,16,15,16,16,16,16,16,15,49,15,49,15,16,16,48,16,48,16,1285,128,64,16,48,16,16,16,16,16,15,16,48,16,16,16,16,16,16,15,16,16,48,16,16,16,48,16,48,16,16,16,48,16,48,16,48,16,48,16,48,16,15,16,16,16,48,16,16,16,15,16,16,16,16,16,16,15,16,16,16,16,16,16,15,16,16,16,16,16,16,15,16,16,16,16,16,16,15,16,16,16,16,16,48,16,15,16,16,16,48,16,16,16,16,15,49,15,16,16,16,16,16,16,15,16,48,16,16,16,48,16,16,16,16,15,16,16,16,16,16,16,15,16,16,16,16,16,15,16,16,16,16,16,16,15,16,16,16,16,48,16,16,16,48,16,15,16,16,16,16,16,16,15,16,16,16,16,16,16,15,16,16,16,16,16,16,15,16,16,16,16,16,15,16,16,16,16,16,16,15,16,48,16,48,16,16,16,16,16,16,15,16,16,16,16,16,16,15,16,16,16,16,16,16,15,49,15,49,15,16,16,16,16,16,15,16,16,16,16,16,16,15,16,3600>
    with thanks
     

    Attached Files:

    philthedill, Nov 23, 2020
    #1
  2. philthedill

    philthedill

    Joined:
    Mar 21, 2010
    Messages:
    142
    Likes Received:
    4
    Location:
    Melbourne
    Hi there, this has had 56 views but no suggestions yet! I'd really appreciate a hand with this as it is the last piece in a lengthy puzzle and should be easy for someone with the right knowledge.... Please
     
    philthedill, Nov 27, 2020
    #2
  3. philthedill

    Pie Boy

    Joined:
    Nov 21, 2012
    Messages:
    249
    Likes Received:
    31
    Location:
    New Zealand
    For a start, i think a resident script would be needed here to manage the tcp connection, i expect the global cache only allows one tcp connection at a time, if you were to open the tcp connection from an event script/s you may end up with issues.
    Then you would probably need an internal udp server to pass messages from the event script/s to the resident script which would then send the command to the tcp socket.

    the protocol looks pretty straight forward you would need to format your string with /r (CR) on the end
    eg -- sendir,1:1,1,36764,1,1.............,3600/r

    i don't have any global cache to test on so cant test or confirm any code will work properly etc. but to open a tcp connection try the below in resident script
    Code:
    
    host, port = "192.168.1.20", 4998
    
    sock = require("socket")
    
    if not TCP_Client then
    TCP_Client = assert(sock.tcp())
    TCP_Client:connect(host, port);
    TCP_Client:settimeout(1);
    end
    
    if not udp_server then
      -- local UDP server on port 9876
      udp_server = require('socket').udp()
      udp_server:settimeout(1)
      udp_server:setsockname('127.0.0.1', 9876)
        log("Udp Server: Received message")
    end
    
    cmd = udp_server:receive()
    if cmd then
    TCP_Client:send(cmd)
    end
    
    -- if you want to receive reply from connection
    rx = TCP_Client:receive()
    
    if rx then
    log(rx)
    end
    
    
    and to send from event script
    Code:
    cmd = 'sendir,1:1,1,36764,1,1.............,3600/r '
      require('socket').udp():sendto(cmd, '127.0.0.1', 9876)
    
     
    Pie Boy, Nov 27, 2020
    #3
  4. philthedill

    philthedill

    Joined:
    Mar 21, 2010
    Messages:
    142
    Likes Received:
    4
    Location:
    Melbourne
    thank you very much Pie Boy.... I have not got it to work yet but will keep fiddling. However, I did not mention that I will be using 3 Global Cache units. Does this mean 3 resident scripts or would you recommend a different approach?
     
    philthedill, Nov 27, 2020
    #4
  5. philthedill

    philthedill

    Joined:
    Mar 21, 2010
    Messages:
    142
    Likes Received:
    4
    Location:
    Melbourne
    separately, might there be something missing from this line? (ie IP and port?)
    TCP_Client:send(cmd)
     
    philthedill, Nov 28, 2020
    #5
  6. philthedill

    Pie Boy

    Joined:
    Nov 21, 2012
    Messages:
    249
    Likes Received:
    31
    Location:
    New Zealand
    It will send it to the ip address bound to the tcp object, I didn’t mention but you will need to change the ip address and port args to match your global cache in the first line.
     
    Pie Boy, Nov 28, 2020
    #6
  7. philthedill

    philthedill

    Joined:
    Mar 21, 2010
    Messages:
    142
    Likes Received:
    4
    Location:
    Melbourne
    philthedill, Nov 28, 2020
    #7
  8. philthedill

    Pie Boy

    Joined:
    Nov 21, 2012
    Messages:
    249
    Likes Received:
    31
    Location:
    New Zealand
    Yes, basically each time an event script runs it creates a new instance of the script
    so you can have many scripts running in parallel if the event script were to happen to be triggered sequentially.
    eg send ir vol up a few times etc

    if this situation were to happen the first instance of event script would happily open the tcp connection and send the command but the next instance/s may not be able to open the tcp connection etc, it may also cause the tcp connection on the global cache side to become un-responsive/flooded with messages.

    if you could stick your working code in a resident script with the udp server passing the messages from the event script to the resident script that would be best in my opinion, change ip and port to suit and use the
    Code:
    cmd = 'sendir,1:1,1,36764,1,1.............,3600/r '
      require('socket').udp():sendto(cmd, '127.0.0.1', 9876)
    to send the command from event script, test you have output to the log, then un comment the tcp bits below bit etc,

    you may need to start and stop the resident script for it to take effect.

    Code:
    -- resident script 
    local socket = require("socket")
    local tcp = assert(socket.tcp())
    
    if not udp_server then
      -- local UDP server on port 9876
      udp_server = require('socket').udp()
      udp_server:settimeout(1)
      udp_server:setsockname('127.0.0.1', 9876)
        log("Udp Server: Created and ready")
    end
    
    cmd = udp_server:receive()
    if cmd then
      log(cmd)
     
     -- tcp:connect("192.168.0.181", 4998);
    
    --sony tv power toggle
     -- tcp:send(cmd)
    
    os.sleep(.1)
    
    --tcp:close()
     
    end
     
    Pie Boy, Nov 28, 2020
    #8
  9. philthedill

    Krondor

    Joined:
    Feb 29, 2008
    Messages:
    10
    Likes Received:
    0

    But why using IR and not exploring full 2 way control, with real time feedback? there are working solutions for that, with driver ready in SHAC....
     
    Krondor, Apr 23, 2021
    #9
  10. philthedill

    philthedill

    Joined:
    Mar 21, 2010
    Messages:
    142
    Likes Received:
    4
    Location:
    Melbourne
    I could not find anything in the SHAC + I had a figure 8 to each of my 8 indoor units from a central position. Using IR via Global cache IP2IR was the best solution I could find and it is working well.
     
    philthedill, Apr 24, 2021
    #10
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.