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

Valdate string containing blanks


Question

Posted

I have been using the API/Json to retrieve all my light devices. Now I would like to do some additional actions based on the condition of the device name. Eg "Hallway light"

I can't get a simple if statement to be functional when the string contains a blank. Removing the blank and it works perfectly.

How to solve this? If (devicename == 'Hallway Light") then

Thanks

9 answers to this question

Recommended Posts

  • 0
  • Inquirer
  • Posted

    Anyone?

    • 0
    Posted

    Can you debug the devicename like: fibaro:debug("---"..devicename.."---")

     

    If you can share your code then we can debug it.

    • 0
  • Inquirer
  • Posted

    Please login or register to see this code.

    local HC2 = Net.FHttp("10.0.1.30",80);

    HC2:setBasicAuthentication("admin","xxxxxx")

    response ,status, errorCode = HC2:GET("/api/sections")

    sectionsTable = json.decode(response)

    response ,status, errorCode = HC2:GET("/api/rooms")

    roomsTable = json.decode(response)

    response ,status, errorCode = HC2:GET("/api/devices")

    devicesTable = json.decode(response)

    local groundfloor = tostring('Ground Floor')

    fibaro:debug(groundfloor)

    for loop1 = 1, #sectionsTable do

    section = sectionsTable[loop1].name

    fibaro:debug(section)

    if (section == groundfloor) then

    for loop2 = 1, #roomsTable do

    room = roomsTable[loop2].name

    if roomsTable[loop2].sectionID == sectionsTable[loop1].id then

    fibaro:debug(room)

    for loop3 = 1, #devicesTable do

    if (devicesTable[loop3].roomID == roomsTable[loop2].id and devicesTable[loop3].properties.isLight == 'true') then

    device = devicesTable[loop3].name

    deviceid = devicesTable[loop3].id

    fibaro:debug(device)

    -- fibaro:call(deviceid, "turnOff")

    end

    end

    end

    end

    end

    end

    • 0
    Posted

    My result is all the sections in the debug and if I change "Ground Floor" to "Begane grond" (that is how I named the Ground Floor), I see all lights of that section in the debug, so that is ok.

     

    I changed it a liitle bit, you don't need authentication if you running it on the same HC2, secondly (was working also without this change) I removed the tostring when defining the variable groundfloor

     

    What result do you get?

    Please login or register to see this code.

    • 0
  • Inquirer
  • Posted

    Its still not working, i would like to see all devices as lights in this section/room... Its still not passing the first IF statement. Crazy!

    • 0
    Posted

    Can you paste the output of fibaro:debug(section). (just before the first if)

     

    Are you sure you spelled "Ground Floor" correctly, case sensitive?

    • 0
  • Inquirer
  • Posted

    In debug i get the following using above code.

     

    [DEBUG] 17:29:58: Ground Floor

    [DEBUG] 17:29:58: Ground Floor 

     

    [DEBUG] 17:29:58: First Floor

    [DEBUG] 17:29:58: Outdoor

     

    Removing the IF statement i get the following...

     

    [DEBUG] 17:31:38: Ground Floor

    [DEBUG] 17:31:38: Ground Floor 

    [DEBUG] 17:31:38: Kitchen

    [DEBUG] 17:31:38: Kitchen Light

    [DEBUG] 17:31:38: Hallway

    [DEBUG] 17:31:38: Hallway light

    [DEBUG] 17:31:38: Hallway Closet

    [DEBUG] 17:31:38: Chair

    [DEBUG] 17:31:38: Livingroom

    [DEBUG] 17:31:38: Window Line Light

    [DEBUG] 17:31:38: Sofa Table

    [DEBUG] 17:31:38: Dining Table

    [DEBUG] 17:31:38: Stairs

    [DEBUG] 17:31:38: Window Light

    [DEBUG] 17:31:38: Laundry

    [DEBUG] 17:31:38: Laundry

    [DEBUG] 17:31:38: Toilet

    • 0
    Posted

    Is this all what you get (without the if)? I miss First Floor and Outdoor. If I remove the if I get every light returned of my house (section, room, light, light, room, light, light, section, room light, etc)

     

    Something very strange...

    • 0
  • Inquirer
  • Posted

    You are correct, I get more wo the IF, I get all sections, all rooms and all lights. I just wanted to show its passing throw wo the if, despite the text string is the same.

    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...