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


HC3 QuickApps coding - tips and tricks


jgab

Recommended Posts

Nvm my previous comment.. the problem was on my side :) 

 

Now it crashes when trying to get the json from the Http:

Please login or register to see this code.

 

Edited by Momos
Link to comment
Share on other sites

  • Topic Author
  • 7 minutes ago, Momos said:

    Nvm my previous comment.. the problem was on my side :) 

     

    Now it crashes when trying to get the json from the Http:

    Please login or register to see this code.

     

    Can you post the whole code?

    9 minutes ago, Momos said:

    Nvm my previous comment.. the problem was on my side :) 

     

    Now it crashes when trying to get the json from the Http:

     

     

    Oh, if you used my last example you should use http:request, not self.http:request...

    Link to comment
    Share on other sites

    5 hours ago, jgab said:

     

    Ok, the 3rd method, and a bit more "object oriented" in style,  is to delegate the actions to the children themselves.

    The idea is that you send all the data you collected to all the children, and each child picks out the data relevant for it and uses that to update whatever.

    Here we define a method :updateValue for all children that we call. Then we don't need to know their names - they know what to do with the data...

    I haven't been able to test it but at least it compiles :-)

     

    Thanks @jgab ! I like this method. Without the child devices I thought about creating a separate QuickApp for each reading (temperature, humidity, pm2.5 and pm10). But then I had four the same sources, that didn't make any sense. So the child devices are a great solution! The effect is somewhat similar to for instance my out of the box MCO Home CO2 sensor. 

     

     

    5 hours ago, jgab said:

    I would probably do the loop like below. Then you can keep 'ipaddress' etc as local lua variables and don't need to read them in every time in the loop.

    ...and you are not using the 'otherData' field so I removed that too.

     

    It was kind of a mess, thanks. I think I go further with it for instance the part where the labels get their values. I also have to make the variables a bit more foolproof. If the variables aren't there, then create them. Etc. 

     

     

    This is really great. At first I thought the child devices where a bit too complicated for me, but it ain't that difficult (with some help ?) and they add a lot of new possibilities. ???

     

    And I now can see the values in the mobile app. That is nice for a change ?

     

     

     

     

    Edited by SmartHomeEddy
    Link to comment
    Share on other sites

    47 minutes ago, jgab said:

    Oh, if you used my last example you should use http:request, not self.http:request...

    Hehe i got that from reading the manual :) 

     

    So it looks like i almost got it working for my sensor but for a few minor details.  It crashes with "operation cancelled" and does not seem to want to update witht the set interval... 

     

    Cheers @jgab and @SmartHomeEddy for this QA :) 

     

    Log:

    Please login or register to see this code.

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    14 minutes ago, Momos said:

    It crashes with "operation cancelled" and does not seem to want to update witht the set interval... 

     

    Sometimes I get the same error. I assume that is the case when the sensor doesn't give an answer within the 3 seconds of the http request.  

     

    Please login or register to see this code.

     

    If that is the case. I wouldn't worry. But if you enter a wrong IP address or path, you get the same error. 

     

     

     

    Link to comment
    Share on other sites

    18 minutes ago, SmartHomeEddy said:

    Sometimes I get the same error. I assume that is the case when the sensor doesn't give an answer within the 3 seconds of the http request.  

     

    The IP is correct as the API call has a response.  Typing in Chrome the url always gets an answer.

     

    However the QA log :

     

    Please login or register to see this code.

     

    Modifying something and saving works... and all the sensors are updated... ?

    Edited by Momos
    Link to comment
    Share on other sites

  • Topic Author
  • If it times out it calls the error handler. 

    I would suspect that it calls the success handler but with a code saying that the operation was cancelled - can you check the status code when it crashes?

    Because then you will not have any .data field and the json decode etc will crash,

     

    Link to comment
    Share on other sites

  • Topic Author
  • Define this function

    Please login or register to see this code.

    and then in your http request 

    Please login or register to see this code.

    It will catch errors in the handlers and report them.

    Because it seems like errors are not always reported well when callbacks and setTimeout functions crash.

    Edited by jgab
    Link to comment
    Share on other sites

    either i don't know where exactly to insert those into the Http request, or it does nothing.  I think it is the first ?

     

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

  • Topic Author
  • 4 minutes ago, Momos said:

    either i don't know where exactly to insert those into the Http request, or it does nothing.  I think it is the first ?

     

    Please login or register to see this code.

     

     

    Link to comment
    Share on other sites

    Please login or register to see this code.

     

    It does not like ??

    Link to comment
    Share on other sites

    Ha !  i found out what the heck is going on..

     

    I modified 

    Please login or register to see this code.

    to

     

    Please login or register to see this code.

     

     

    and 

    Please login or register to see this code.

     

    to

    Please login or register to see this code.

     

    All works now and sensors are updated as per Interval.

     

    It seems these last lines of self:debug were introducing the error.  

     

    I confirm it works also with the first version i posted if i change these last few lines.

     

    Cheers again @jgab and @SmartHomeEddy . Happy now to have my Urad sensor in HC3 :)

     

     

     

     

     

       

    Edited by Momos
    • Like 1
    Link to comment
    Share on other sites

  • Topic Author
  • 22 minutes ago, Momos said:

    Ha !  i found out what the heck is going on..

     

    All works now and sensors are updated as per Interval.

     

    IF I comment out these last self:debug lines... i get again the error "operation cancelled"

     

    Weird :) 

     

    Sorry I missed the rest/response thing.

    Yes, the values were put in a table named 'data'.

    The last problem is weird but shouldn't be related to your debug statements....

    Link to comment
    Share on other sites

    I am getting better at this :) 

    I created a QA for my power meter and it works well.

    I left however the childs class as com.fibaro.multilevelSensor as i had no ideea if there is a class like com.fibaro.powerMeter ... Is there one like that ? 

     

    The reason why i ask is that i would like to have the history of these devices in HC3.. somewhere..

     

    Please login or register to see this code.

    image.png.6f169123659abe2e1dbae0584824fc1a.png

    Edited by Momos
    Link to comment
    Share on other sites

    There is a type energy meter. 
     

    I insert the power usage not by my Fibaro devices in a unused device. So I have all power usage in my Homecenter. Now waiting for a fine energy panel on the HC3. 

    Link to comment
    Share on other sites

    Yes 

    Please login or register to see this code.

     

    I measure the power consumption of all devices and deduct it from the total power consumption. I put the difference in a unused device. 
     

    Please login or register to see this code.

     

    Edited by SmartHomeEddy
    Link to comment
    Share on other sites

    cool:)  

    I see that the child devices have a "value" .  Can one child device store 2 values for example: "value" and "power" ?

     

    here is where i need to modify it  please? 

    local initChildData = { -- Just my own local table to be able to make a loop - you may get your initial data elsewhere...
          {className="Phase1", name="Phase1", type="com.fibaro.multilevelSensor", value=0, unit="Watt"},
          {className="Phase2", name="Phase2", type="com.fibaro.multilevelSensor", value=0, unit="Watt"},
          {className="Phase3", name="Phase3", type="com.fibaro.multilevelSensor", value=0, unit="Watt"},
        }

     

    Link to comment
    Share on other sites

    Haven’t done that yet, but I think the property should be “power”

     

    Because I put the power usage in that property with

     

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    hehe i think i learned something... then i want to improve and i break it ??

     

    I deleted the QA to recreate it as energy meter, not multilevel sensor, so it shows in history.

     

    But now the values are gone from the child devices...

    Please login or register to see this image.

    /monthly_2020_07/image.png.148d18b9de51cb562429edef76e874b1.png" />

     

    they are still in the labels of the main device

    image.png.f032899c7c70230ea62d161a9cb8bd0b.png

     

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