Homegate and Logitech squeezebox integration

Discussion in 'General Discussion' started by cooper88, Jun 24, 2014.

  1. cooper88

    cooper88

    Joined:
    Nov 4, 2013
    Messages:
    8
    Likes Received:
    0
    Location:
    Sydney
    Hi all,
    I have been trying to integrate a raspberry pi running the logitech squeezebox software to my c-bus system. I have read through the documentation on the various commands and I was hoping to make a button on a wall plate pause and play the audio. I can send the command to the squeezebox player via a telnet to the squeezebox server (my mac) then typing the required command. I was hoping to use logic eg. lighting state off = paused and lighting state on = playing.

    I cannot get the logic engine to establish a TCP/IP connection to the squeeze box server.

    I started working on the code but it has been unsuccessful. I am very new to all the logic and programming.

    Code:
    OpenClientSocket(1, '192.168.2.18', 9090);
    [INDENT]if GetLightingState ("Laundry") = ON then[/INDENT]
    [INDENT]begin[/INDENT]
    [INDENT]WriteClientSocket(1, 'b8:27:eb:50:14:03 play 1.5<LF>')[/INDENT][INDENT]end;[/INDENT]
    To confirm the command works as I have tested it through a telnet.
    All help would be very much appreciated.

    Thanks in advance,
    Cooper
     
    cooper88, Jun 24, 2014
    #1
  2. cooper88

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,548
    Likes Received:
    178
    Location:
    Adelaide, Australia
    You have several problems as it stands

    The most likely is the <LF> which will send four characters < L F and >, not a linefeed character. You need 'b8:27:eb:50:14:03 play 1.5'#10 in Pascal.

    Also, you need to replace the IF with a ONCE. As it stands, whenever the group is on, the logic will send out the string every scan (i.e. 200mS).

    In addition, you either need to open the client socket once in the Initialization section, or better still test to see if is is open prior to sending a command, and if not, open it then. You also need to wait a bit for the connection to establish


    Code:
    once GetLightingState ("Laundry") = ON then
    begin
      if not clientSocketConnected(1) then
      begin
        openClientSocket(1, '192.168.2.18', 9090);
        waitUntil(clientSocketConnected(1)); 
      end;
      WriteClientSocket(1, 'b8:27:eb:50:14:03 play 1.5'#10)
     end;
     
    Ashley, Jun 24, 2014
    #2
  3. cooper88

    cooper88

    Joined:
    Nov 4, 2013
    Messages:
    8
    Likes Received:
    0
    Location:
    Sydney
    Thanks

    Thank you very much.

    It only seems to work once. Could you suggest how to add when the lighting state is off how to pause the music. It may solve the problem.
    eg. b8:27:eb:50:14:03 pause
     
    cooper88, Jun 24, 2014
    #3
  4. cooper88

    cooper88

    Joined:
    Nov 4, 2013
    Messages:
    8
    Likes Received:
    0
    Location:
    Sydney
    Update: I have managed to get it pausing and playing the music depending on the state of the group but it still stops working after you pause and play it through the group. Any ideas?
     
    cooper88, Jun 24, 2014
    #4
  5. cooper88

    cooper88

    Joined:
    Nov 4, 2013
    Messages:
    8
    Likes Received:
    0
    Location:
    Sydney
    Play works but pause only once?

    Code:
    once GetLightingState ("Laundry") = ON then
    begin
      if not clientSocketConnected(1) then
      begin
        openClientSocket(1, '192.168.2.18', 9090);
        waitUntil(clientSocketConnected(1)); 
      end;
      WriteClientSocket(1, 'b8:27:eb:50:14:03 play 1.5'#10)
     end;
    
     once GetLightingState ("Laundry") = OFF then
     begin
      WriteClientSocket(1, 'b8:27:eb:50:14:03 pause'#10)
     end;
    This is my current code and play works flawlessly but pause refuses to after it has been triggered once.
     
    cooper88, Jun 24, 2014
    #5
  6. cooper88

    cooper88

    Joined:
    Nov 4, 2013
    Messages:
    8
    Likes Received:
    0
    Location:
    Sydney
    Solved pt1

    I fixed this by making a new logic with the code above and changed the required info to pause the music.
     
    cooper88, Jun 24, 2014
    #6
  7. cooper88

    cooper88

    Joined:
    Nov 4, 2013
    Messages:
    8
    Likes Received:
    0
    Location:
    Sydney
    Another question

    I have made a bell press button that raises the volume of the squeeze box by 10 when press and I am hoping to make is so that if it is held down for 3 seconds it lowers the volume by 10. It works but when you press it innitially it raises the volume by 10 then begins to lower it by 10 every 3 seconds. Is there a way to make sure it does not do this?

    Here is my current code
    Code:
     once GetLightingState ("Music Volume") = ON then
    begin
      if not clientSocketConnected(1) then
      begin
        openClientSocket(1, '192.168.2.18', 9090);
        waitUntil(clientSocketConnected(1)); 
      end;
      WriteClientSocket(1, 'b8:27:eb:50:14:03 mixer volume +10'#10)
     end;
    
     nce ConditionStaysTrue(GetLightingState("Music Volume"), 3) then
    begin
      if not clientSocketConnected(1) then
      begin
        openClientSocket(1, '192.168.2.18', 9090);
        waitUntil(clientSocketConnected(1)); 
      end;
      WriteClientSocket(1, 'b8:27:eb:50:14:03 mixer volume -10'#10)
     end;
     
    Thanks.
     
    cooper88, Jun 24, 2014
    #7
  8. cooper88

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,548
    Likes Received:
    178
    Location:
    Adelaide, Australia
    Generally it's not a good idea to use the bell press function with logic for short presses. The problem is that the logic only runs every 200mS and it's easy to press and release a button within this time so the logic will never see it. The way to do it is to get the switch to set a group address and the logic to reset it once processed.

    One option is to set the switch up as follows:
    short press: idle
    short release: recall 1 (set to say 50%)
    long press: on
    long release: off

    In this way a short press and release will set the group to 50% which the logic can test for, send the UP volume command, then reset the group to 0.
    The long press will hold the group to 100% all the while the switch is held.

    I don't really see how you logic can repeat the downvolume every 3 seconds if you hold the switch. Once a conditionStaysTrue function has been actioned, it won't trigger again until the condition first goes false and then back to true for the duration. If you hold the switch down this won't happen.

    Probably the easiest solution is to write a seperate module that delays 3 seconds then lowers the volume. Just enable module when the volume ga goes to 100% and disable it when it goes back to 0%
     
    Ashley, Jun 24, 2014
    #8
  9. cooper88

    Damaxx

    Joined:
    May 12, 2008
    Messages:
    229
    Likes Received:
    47
    Damaxx, Jun 24, 2014
    #9
  10. cooper88

    cooper88

    Joined:
    Nov 4, 2013
    Messages:
    8
    Likes Received:
    0
    Location:
    Sydney
    All working!!

    I have successfully got the cbus switches talking to the squeeze box and playing, pausing, increasing and decreasing the volume.

    To adjust the volume the following was done
    Setting up the switches as above:
    And the two logic modules:

    No1.
    Code:
    //Initialize connection and then increse volume by 10 when "Music Volume" is at 50%
    once GetLightingLevel("Music Volume") = 50% then
    begin
      if not clientSocketConnected(1) then
      begin
        openClientSocket(1, '192.168.2.18', 9090);
        waitUntil(clientSocketConnected(1)); 
      end;
      WriteClientSocket(1, 'b8:27:eb:50:14:03 mixer volume +10'#10)
     end;
    
     //Initialize connection and then decreace volume by 10 when "Music Volume" is at 100%
     once GetLightingLevel("Music Volume") = 100% then
    begin
      if not clientSocketConnected(1) then
      begin
        openClientSocket(1, '192.168.2.18', 9090);
        waitUntil(clientSocketConnected(1)); 
      end;
      WriteClientSocket(1, 'b8:27:eb:50:14:03 mixer volume -10'#10)
     end;
    and module 2:
    Code:
    if GetLightingLevel("Music Volume") = 50% then
    begin
    SetLightingState("Music Volume", OFF);
    end;
    I am sure you could combine these together but this is what I found the easiest.
     
    cooper88, Jun 25, 2014
    #10
  11. cooper88

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,548
    Likes Received:
    178
    Location:
    Adelaide, Australia
    You really need to delete module 2 and set the group address back to zero immediately after the volume up command. As you have it, the second module could execute first just after the switch was pressed and reset the ga before the first module gets to it.
     
    Ashley, Jun 25, 2014
    #11
  12. cooper88

    cooper88

    Joined:
    Nov 4, 2013
    Messages:
    8
    Likes Received:
    0
    Location:
    Sydney
    Thanks

    Okay will do. Didn't think of that.
    Thank you for your help
     
    cooper88, Jun 25, 2014
    #12
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.