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


Need help coupling FHT equipment into HC2


Recommended Posts

Guest jrkalf
Posted

Hi,

I need some help setting up virtual devices, because I'd like to couple my ELV branded FHT80 equipment for my heating system into the HC2.

I've been at this in Personal messages with Deraaij already but not knowing what I exactly need to do and hat the use for virtual devices is and how to manipulate them with scenes hasn't let me to a solution just yet.

Basically I control my devices via a german software tool named FHEM.

This tool is build on Perl and allows several ways to communicate with it. html and tcpsocket are the two main ways and then there are several ways of getting data exported.

for which I find the getstate the easiest way probably. Example of an export "getstate verw.woonkamer" command:

Please login or register to see this code.

now I want to be able to know how I can break these items down into the single information items I'd like to see.

because if I know what temperature (measured-temp) a room is, I can also send a command like "set verw.woonkamer desired-temp 18" and it would control the heating system in the living room (woonkamer) to go down to 18 degrees.

I've looked at the fibaro polish docs translated in google, but I haven't been able to crack it just yet. I hope I'm on the right path, who can help me?

Please login or register to see this code.

What I think happens here, is it opens up a TcpSocket to my FHEM installation which runs on port 7072, it sends a getstate request for the device I want information about, and after 200ms disconnects the session. In the mean while after the sending of the getstate it reads the feedback via the tcpSocket:read and puts it in the "state" string?

Now how can I extract the data out of that 'state' string?

and how can I manipulate the temperature of a virtual device?

Too many questions probably for one posting, but let's see how far we can get.

[ Added: 2013-03-24, 22:02 ]

Any of the fibaro devs or website admins?

Help out here. I'm close to getting it sorted.. but your box has serious shortcomings in debugging options.

You haven't implemented the Net library into scenes,

you've eliminated the Os.execute,

you've made fibaro:debug unusable in the virtual devices.

Without any support I can't program any scripts. So some samples on how you guys see this whole virtual device so we can make it usable would be dearly appreciated.

It shouldn't be that hard, opening a tcp socket, sending a command, receiving a response.. but without any debugging options, I can't see where it goes wrong

Please login or register to see this image.

/emoticons/default_icon_cry.gif" alt=":cry:" />

[ Added: 2013-03-24, 22:12 ]

bump?

[ Added: 2013-03-24, 22:13 ]

bump? ohh my lord, have they really put in an "added" module? how sad...

-1 fibaro team.. seriously, -100!

[ Added: 2013-03-24, 22:20 ]

bump

Posted

bump

Guest jrkalf
  • Topic Author
  • Posted

    So, now that we know that:

    [*] Scenes don't have access to Net.FTcpSocket

    [*] Scenes don't have acces to Net.FHTTP

    [*] Scenes can't use json?!?

    [*] All of the above are available in Virtual Devices

    [*] Virtual Devices don't have a debug screen which allows for debugging your virtual device code....

    We've entered a whole new dimension of 'blind' coding without debug options...

    Please login or register to see this image.

    /emoticons/default_icon_curve.gif" alt=":-/" />

    ----------------------------------------------------------------

    On advise of Adv.Usr.Deraaij I've also tried using json instead of getstate. because if we have usable information we can read. We can always use a 'set' command without using json to actually manipulate values later on.

    So I fetched myself a fresh sample of json code I would like to read and used that as a base for trying to put together some code.

    Perhaps somebody can help me by pointing out any coding errors I've made, so I can work towards correcting it and getting it working.

    Please login or register to see this code.

    Yes, the writing of the work "quit" is necessary in order to close the connection. Initially I forgot this tricky bit and it kept open many connections.

    Please login or register to see this image.

    /emoticons/default_sad.png" alt=":(" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" />

    If I manually open a tcpSocket to device on socket 7072 and type in the command jsonlist verw.woonkamer, I get the following response:

    Please login or register to see this code.

    Please help.

    Posted

    Think you can do like this.

    Please login or register to see this code.

    If you want time also you can do like this

    Please login or register to see this code.

    Or it could be like this:

    Please login or register to see this code.

    Not tested it so i am not 100% sure.

    [ Added: 2013-03-26, 10:33 ]

    Was not so easy...

    your data is different types so it must be done with some other json commands.

    I will investigate more

    Please login or register to see this image.

    /emoticons/default_icon_wink.gif" alt=";-)" />

    [ Added: 2013-03-26, 14:45 ]

    If i remove the first and second object it works.

    Please login or register to see this code.

    Not sure how-to sort it with the objects in the beginning

    Please login or register to see this attachment.

    Guest jrkalf
  • Topic Author
  • Posted

    Jonny,

    You're a brilliant piece of inspiration and you've truly uncovered some more bugs I hope the fibaro team can solve.

    Fibaro devs, here's a short management summary

    • When using JSON output in a variable strings, it's not allowed to have linebreaks (return key)
    • json fields using a - sign can't be read. (bug?)

    Jonny is a nice pitbull who bites into the code and doesn't let it go until something usefull can be produced with it.

    He had some issues with my first "ResulSet" and "Results" field. Those are valid fields and I've managed to get those working, the issue seems to be in the use of linebreaks in the code in the variables field. This corrupts the field in the lua interpreter and it leaves us with unusable code. (Reminder to self: check this against live lua code fetched from the tcpSocket. Because this also contains linebreaks and it's a feature, not a bug!)

    Currently working code I've been playing with:

    Please login or register to see this code.

    Mostly written by Jompa86 (Jonny!)

    Posted

    Normal for a json object that have - (hypen/dash) in the key, you will get a reference error if you access the object with dot manner. For example

    Please login or register to see this code.

    But i dont get it too work with your data

    Please login or register to see this image.

    /emoticons/default_icon_evil.gif" alt=":evil:" />

    Guest deraaij
  • Topic Author
  • Posted

    I had the same issue with the "-" ...... (still have)

    Guest jrkalf
  • Topic Author
  • Posted

    Based on the code I post last I've tested your suggestion with the following result samples:

    Please login or register to see this code.

    None of the four options seem to work.

    Then I did something bold.....

    Please login or register to see this code.

    VOILA, working code!.... against the "sample code"

    Please login or register to see this image.

    /emoticons/default_icon_curve.gif" alt=":-/" />

    Please login or register to see this image.

    /emoticons/default_icon_curve.gif" alt=":-/" />

    Please login or register to see this image.

    /emoticons/default_icon_curve.gif" alt=":-/" />

    Please login or register to see this image.

    /emoticons/default_icon_curve.gif" alt=":-/" />

    Using it against the "live feed" from the Net.FTcpSocket, it still fails. Probably because of the output containing linebreaks.

    Can I somehow catch the result and remove the linebreaks?

    Guest deraaij
  • Topic Author
  • Posted

    You can use local result = string.gsub(var, "n", "")

    Guest jrkalf
  • Topic Author
  • Posted
    You can use local result = string.gsub(var, "n", "")

    Thanks, that would have been too easy for somebody without coding experience

    Please login or register to see this image.

    /emoticons/default_smile.png" alt=":)" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" />

    I probably would have to target "\n" instead of "n" right?

    I took another bold move, which is kind of "over doing" it.

    After looking at the FHEM filelist, I found a 98_JsonList.pm. I parsed all lines of code and removed the \n from all results which has kind of the same result.

    I can always return to the original code and check your option later on.

    for now I have:

    Please login or register to see this code.

    Sadly that doesn't work.

    When I manually telnet to the socket, write the jsonlist verw.woonkamer (including a linebreak) I get the result we've been testing with the last few hours.

    I did some variations on the "tcpSocket:write" as well:

    Please login or register to see this code.

    None of them worked. Have any tips?

    Posted
    You can use local result = string.gsub(var, "n", "")

    Thanks, that would have been too easy for somebody without coding experience

    Please login or register to see this image.

    /emoticons/default_smile.png" alt=":)" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" />

    I probably would have to target "\n" instead of "n" right?

    I took another bold move, which is kind of "over doing" it.

    After looking at the FHEM filelist, I found a 98_JsonList.pm. I parsed all lines of code and removed the \n from all results which has kind of the same result.

    I can always return to the original code and check your option later on.

    for now I have:

    Please login or register to see this code.

    Sadly that doesn't work.

    When I manually telnet to the socket, write the jsonlist verw.woonkamer (including a linebreak) I get the result we've been testing with the last few hours.

    I did some variations on the "tcpSocket:write" as well:

    Please login or register to see this code.

    None of them worked. Have any tips?

    You can use local result = string.gsub(state, "n", "")

    Put that after state =

    Guest jrkalf
  • Topic Author
  • Posted

    Thanks guys, I've started taken it a step further.. I now understand that I should "debug" through the fibaro:log and I'm doing it as following:

    Please login or register to see this code.

    Now where does the big bunch of code go wrong?

    After:

    Please login or register to see this code.

    That's the last line of logging I get returned, then it goes away.

    So even the fibaro:log("res1 fetched") messages don't return.

    If I uncomment the line just above it. it does show the fetched message and then breaks on the next line of code.

    So I'm at a dead end again

    Please login or register to see this image.

    /emoticons/default_icon_question.gif" alt=":?:" />

    [ Added: 2013-03-26, 23:14 ]

    I'm about to say: don't ask how... but that would be unfair.

    I got it to work.

    I've tossed away the Net.FTcpSocket option, probably the cause of all the darn issues, reading responses etc.

    I've done the following and it works now. After doing a lot of grinding in the FHEM manual, I found a small switch for the http GET named &XHR=1. This strips all the html output from the command you send to fhem..

    So this would allow me to send a json request to the fhem installation and get a proper json response without any html code attached.

    Final testcode that works:

    Please login or register to see this code.

    blood, sweat, tears, frustration, a lot of help from Mark and Jonny..

    Now I can finally read the temperature information from my heating system...

    Now to find a way to use this information in the HC2 system. Ohhh fibaro devs... do we have virtual temperature devices already?

    Please login or register to see this image.

    /emoticons/default_icon_mrgreen.gif" alt=":mrgreen:" />

    Please login or register to see this image.

    /emoticons/default_icon_mrgreen.gif" alt=":mrgreen:" />

    Please login or register to see this image.

    /emoticons/default_icon_mrgreen.gif" alt=":mrgreen:" />

    Please login or register to see this image.

    /emoticons/default_icon_mrgreen.gif" alt=":mrgreen:" />

    [ Added: 2013-03-26, 23:30 ]

    Note addition number 2:

    This above code is specifically for FHT devices.

    below code is for KS300 types of devices:

    Please login or register to see this code.

    Posted

    Good that you made it

    Please login or register to see this image.

    /emoticons/default_icon_biggrin.gif" alt=":-D" />

    Guest deraaij
  • Topic Author
  • Posted

    Congratz!

    Join the conversation

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

    Guest
    Reply to this topic...

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