Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

kunalsab

Question

Hi!

I need to create this functionality in LUA Code on Virtual Devices:

Aim: To toggle commands each time that button is pressed.

Description: The Virtual Device button called “Cursor Left” needs to save Two Commands “Global Cache Executable : InfraRed Code 1” and “Global Cache Executable : InfraRed Code 2”.

Working: We need that each time we press the button “Cursor Left”,  “IR Code 1” is sent and the second time we press the button “IR Code 2” is sent, when we press it the third time “IR Code 1” is sent and so on.

At no instance “IR Code 1” and “IR Code 2” should be sent together. It should always execute Code 1 then Code 2 then Code 1 . . . . . only when the virtual device button is pressed. 

The program would be saved on each button of the virtual device, virtual device in this case would be a remote comprising of different buttons and codes.

How RC6 Codes Work : RC6 each codes is used in alternating order. After the first code gets sent, the equipment is looking for the next code.
Best Regards,

Kunal Sabharwal

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

This is like a flip-flop, so you need one global variable that will change with every press of the button and if/then/else should do the trick. Something like this maybe:

 

Please login or register to see this code.

If you need to send IR Code 1 always first with another session then you need other code which will check something to reset global variable "FlipFlop" to 0 after first session is finished, maybe check if device is turned off and then reset?

Edited by Sankotronic
Link to comment
Share on other sites

  • 0
  • Inquirer
  • Hey Thanks for your prompt reply.

    Tried using the code that you have shared, Request you to provide a full code for the Button Named "Left", I couldn't get this to work properly with the hint provided. 

    Code I tried is also mentioned below, request you to send your code for one button, rest of the 30 buttons I could then do myself.

     

    You could also enter the code directly in to the Remote Button in the Attachment "Imported Virtual Device" and share that with me.


    My HC2 Static IP is : 192.168.5.105
    Global Cache IP is: 192.168.5.81

    Port: 4998

    Room: Test Room
    Name: Multi Media Remote

    Device Label : Left

    Device ID: Button 11

     

    What I Tried to do: 

     

    --------------LUA CODE Below--------------

     

    String to send
    tcp = Net.FTcpSocket("192.168.5.105", 8888)
    -- tcp:write("Example body")
    if fibaro:getGlobalValue("FlipFlop") == "0" then
      fibaro:setGlobal("FlipFlop", "sendir,2:1,1,38000,1,69,343,172,21,22,21,22,21,22,21,22,21,22,21,22,21,22,21,65,21,22,21,22,21,22,21,65,21,65,21,22,21,65,21,65,21,22,21,65,21,65,21,65,21,65,21,22,21,22,21,22,21,65,21,22,21,22,21,22,21,22,21,65,21,65,21,65,21,1673,343,86,21,37320x0D0x0A");
      -- here goes code to send IR CODE 1
    else
      fibaro:setGlobal("FlipFlop", "sendir,2:1,1,38000,1,69,343,172,21,22,21,22,21,22,21,22,21,22,21,22,21,22,21,65,21,22,21,22,21,22,21,65,21,65,21,22,21,65,21,65,21,65,21,65,21,65,21,65,21,65,21,22,21,22,21,22,21,22,21,22,21,22,21,22,21,22,21,65,21,65,21,65,21,1673,343,86,21,37320x0D0x0A");
      -- here goes code to send IR CODE 2
    end
    -- pause time long enough that first code is received
    -- before second push of the button is allowed to send
    -- another IR code
    -- fibaro:sleep(time) This I dont think is required.

    Please login or register to see this attachment.

    Link to comment
    Share on other sites

    • 0

    Please login or register to see this code.

    Try above code. I didn't test it but I hope that you know how to use TCP socket. Don't forget to declare global variable "FlipFlop" or what ever name you choose in global variable panel before playing with this code. It won't work without that global variable.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Hi!

    Thanks for sharing the code.
    But this is the result I get upon debugging.

    Predefined Variables in the Global Variables I had declared as FlipFlop with Values 0 and 1.

    IP Address of Virtual Device is 192.168.5.81

    TCP Port : 8888 and 4998 (Same Result Below)

    Button Label : Left

    Button ID : Button11

     

    The IR Emitter have no current in them, they are not sending any Signal.

    Where could the problem be???

     

    for the first function TRANSFER is Capital and for the second function FAILED is Capital "I changed that to understand what was happening".

    [DEBUG] 10:16:41: transfer FAILED

    [DEBUG] 10:28:57: transfer FAILED
    [DEBUG] 10:28:58: TRANSFER failed
    [DEBUG] 10:29:00: transfer FAILED
    [DEBUG] 10:29:01: TRANSFER failed
    [DEBUG] 10:29:02: transfer FAILED
    [DEBUG] 10:29:10: transfer FAILED
    [DEBUG] 10:29:13: TRANSFER failed
    [DEBUG] 10:29:16: transfer FAILED
    [DEBUG] 10:29:26: TRANSFER failed
    [DEBUG] 10:29:50: transfer FAILED
    [DEBUG] 10:29:54: TRANSFER failed
    [DEBUG] 10:29:55: transfer FAILED
    [DEBUG] 10:30:19: transfer FAILED

     

    Coud[DEBUG] 10:16:42: TRANSFER failed
    [DEBUG] 10:17:00: transfer FAILED
    [DEBUG] 10:17:01: TRANSFER failed
    [DEBUG] 10:17:03: transfer FAILED
    [DEBUG] 10:17:04: TRANSFER failed
    [DEBUG] 10:17:05: transfer FAILED
    [DEBUG] 10:17:05: TRANSFER failed
    [DEBUG] 10:21:45: transfer FAILED
    [DEBUG] 10:21:47: TRANSFER failed

    Link to comment
    Share on other sites

    • 0

    Well, I hope you didn't just copy and paste my code. Part with sending string command you have to check and correct! There is no way I can do that for you since I don't have IR Emitter that you mention to test. Hope you have some kind of documentation for it to check and correct string command.

    Link to comment
    Share on other sites

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...