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


Question

Posted

I am currently trying to write a VD that integrates with Autelis Pool Control into the HC2.

 

I have successfully coded the buttons to turn various devices on or off using their http api, however I am struggling to read the xml data that provides the status of the controlled devices back to the VD so the HC2 knows if the devices were succesfully turned on or off.

 

I have managed to import the xml response as a string in the VD but I cannot work out how to search the string for a particular number / character. i.e if the response string was "11010 001 1 0 1" how would I find out if character 9 was a 1 or a 0?

 

I hope this is achievable?

12 answers to this question

Recommended Posts

  • 0
Posted

Hi Robert,

 

How that string looks like? Does it has some repeating pattern that you can use to search through it with Lua standard string functions like string.find, string.match and then extract needed information with string.sub?

  • 0
  • Inquirer
  • Posted

    @Sankotronic,

     

    here is a screen shot of the string:

    Please login or register to see this attachment.

     

    I have circled the character I am trying to capture, it is the binary indication of the status of the pool pump, the "0's" that follow are also the status of various other devices.

     

    Is there a way to search the string for the character that is say 18th from the start?

     

    FYI, I am a bit of a NOOB at coding so I'm learning on my feet :-)

     

    Thanks

    • 0
    Posted
    8 minutes ago, Robert Folbigg said:

    @Sankotronic,

     

    here is a screen shot of the string:

    Please login or register to see this attachment.

     

    I have circled the character I am trying to capture, it is the binary indication of the status of the pool pump, the "0's" that follow are also the status of various other devices.

     

    Is there a way to search the string for the character that is say 18th from the start?

     

    FYI, I am a bit of a NOOB at coding so I'm learning on my feet :-)

     

    Thanks

     

     

    Please login or register to see this code.

    Please login or register to see this code.

    • 0
    Posted

    Hi Robert,

     

    if that digit is always on the same place in the string then you can use this function to get it:

    Please login or register to see this code.

    Where response is variable in which you put that string so you need to replace with name of your variable.

    • 0
  • Inquirer
  • Posted

    Thank you  @Sankotronic & @shaunfrost for your suggestions, the string never changes length so I believe this will solve my problem. I will give it a test later on when I have a chance and update you.

     

    Thanks ;-)

     

    • 0
  • Inquirer
  • Posted

    @Sankotronic,

     

    Thanks for your assistance once again!!

     

    The code you supplied did the trick. There was one catch that has proven a little bit tricky, although the debug shows the string as numbers there is also all of the xml tags hidden within.

     

    After some debugging I still have managed to find the characters I needed.

     

    I'm sure there would probable be an easier and less messy way to remove all the excess xml code however this method does seem to work.

    • 0
    Posted
    27 minutes ago, Robert Folbigg said:

    @Sankotronic,

     

    Thanks for your assistance once again!!

     

    The code you supplied did the trick. There was one catch that has proven a little bit tricky, although the debug shows the string as numbers there is also all of the xml tags hidden within.

     

    After some debugging I still have managed to find the characters I needed.

     

    I'm sure there would probable be an easier and less messy way to remove all the excess xml code however this method does seem to work.

     

    It all depends on the format of the xml response and is it always of the same length or not. If ti changes then you need to find out how and use string.find or string.match functions to get to the part with those bytes that represent status of the device. That is why I asked you if you can provide copy of xml to check.

    • 0
  • Inquirer
  • Posted (edited)

    Sorry @Sankotronic I didn't understand the original request. I am almost certain the response is static except for the device status bytes.

     

    this is the xml:

    <response>
        <system>
            <runstate>8</runstate>
            <model>7217</model>
            <dip>00000110</dip>
            <opmode>0</opmode>
            <vbat>615</vbat>
            <lowbat>0</lowbat>
            <version>1.4.8</version>
            <time>1494497861</time>
        </system>
        <equipment>
            <pump>0</pump>
            <pumplo></pumplo>
            <spa>0</spa>
            <waterfall></waterfall>
            <cleaner></cleaner>
            <poolht2></poolht2>
            <poolht>0</poolht>
            <spaht>0</spaht>
            <solarht></solarht>
            <aux1>0</aux1>
            <aux2>0</aux2>
            <aux3>0</aux3>
            <aux4>0</aux4>
            <aux5>0</aux5>
            <aux6>0</aux6>
            <aux7>0</aux7>
            <aux8>0</aux8>
            <aux9>0</aux9>
            <aux10>0</aux10>
            <aux11>0</aux11>
            <aux12>0</aux12>
            <aux13>0</aux13>
            <aux14>0</aux14>
            <aux15></aux15>
            <aux16></aux16>
            <aux17></aux17>
            <aux18></aux18>
            <aux19></aux19>
            <aux20></aux20>
            <aux21></aux21>
            <aux22></aux22>
            <aux23></aux23>
        </equipment>
        <temp>
            <poolsp>33</poolsp>
            <poolsp2>15</poolsp2>
            <spasp>39</spasp>
            <pooltemp>15</pooltemp>
            <spatemp>0</spatemp>
            <airtemp>0</airtemp>
            <solartemp>7</solartemp>
            <tempunits>C</tempunits>
        </temp>
    </response>

     

    Edited by Robert Folbigg
    • 0
    Posted

    That is nice! So, here it is how you can extract pool temperature or any other data regardless of position and length of the string or data:

    Please login or register to see this code.

    So, first you get position of the opening tag "<pooltemp>" in the string and b will contain position of the ">" so character just before number for temperature.

    Then you get position of the closing tag "</pooltemp>" where c will contain position of "<" character just after the number that represents temperature.

    And then you get number with s:sub (b + 1, cl - 1)

     

    Same goes for all other data that is contained in that xml!

     

    Enjoy coding! :-) 

    • Thanks 1
    • 0
  • Inquirer
  • Posted
    7 minutes ago, Sankotronic said:

    That is nice! So, here it is how you can extract pool temperature or any other data regardless of position and length of the string or data:

    Please login or register to see this code.

    So, first you get position of the opening tag "<pooltemp>" in the string and b will contain position of the ">" so character just before number for temperature.

    Then you get position of the closing tag "</pooltemp>" where c will contain position of "<" character just after the number that represents temperature.

    And then you get number with s:sub (b + 1, cl - 1)

     

    Same goes for all other data that is contained in that xml!

     

    Enjoy coding! :-) 

     

    Thanks @Sankotronic,

     

    Im gong to try this right away!

    • 0
  • Inquirer
  • Posted

    @Sankotronic,

     

    Thanks again for your help, I was able to make a nice pool control VD for my client.

    Please login or register to see this attachment.

    Please login or register to see this attachment.

     

     

    • 0
    Posted

    Good job Robert! Always happy to help!

     

    Enjoy coding! :-) 

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