This is the forum archive of Homey. For more information about Homey, visit the Official Homey website.

The Homey Community has been moved to https://community.athom.com.

This forum is now read-only for archive purposes.

[APP] Better logic / Variable management

1246725

Comments

  • Make a number variable, create flow that assigns the output of the card to the variable. Use the special assign card that I thought is called set a variable (sry, not behind my pc.  But you can recognise because the dropdowns shows all variables) . This converts the variable (while others enforce the type). Then create a second flow that uses the variable in the condition. 
  • What would be the easiest way to use a Better Logic variable from within another app?

    I can get them from a command line at http://homey/api/app/net.i-dev.betterlogic/variable, but how do I do that using JavaScript?

    Does Homey.manager allow this? I can get app settings with that just fine :)
  • What would be the easiest way to use a Better Logic variable from within another app?

    I can get them from a command line at http://homey/api/app/net.i-dev.betterlogic/variable, but how do I do that using JavaScript?

    Does Homey.manager allow this? I can get app settings with that just fine :)
    No, that is not possible. The only option is to use the http interface.
  • Do you have an example somewhere of how to do that? The development documentation is a little too cryptic for me (I've had a look at API section, I've created the api.js in the root of the app, but how do I execute the GET?)
  • app 2 app is possible using api. see https://developers.athom.com/library/permissions/

    Homey.manager('api').get('/app/net.i-dev.betterlogic/variable', function(err, result) {
      Homey.log(result)
    })
  • Thanks! That works! I totally missed the part where it said GET is a method, I used it as a function. Good for when you need errors!
  • Homey.manager('api').get('/app/net.i-dev.betterlogic/variable', function(err, result) {
      Homey.log(result)
    })

    How would I get the above 'result' in a variable though? Somehow all my attempts end up being null.

    I'm missing something here :)

    var test = Homey.manager('api').get('/app/net.i-dev.betterlogic/variable', function(err, result) {
      Homey.log(result)
    })

    Test ends up being null, whereas result contains what it should. As you can see, I'm not an expert at JS :)
  • You should assign result to a variable in a higher scope. 
  • Can you give me an example of how to do that?
  • var test;

     Homey.manager('api').get('/app/net.i-dev.betterlogic/variable', function(err, result) {
      test =result;
    })
  • var test;
    Homey.manager('api').get('/app/net.i-dev.betterlogic/weather', function (err, result) {
       test = result;
    })

        Homey.log('Test var contains', test)


    If I run that, test still contains null. What gives? :)
  • But the homey.log before gave an output? 
  • Yes it did! And still does, but as soon as I try and capture that in a variable to use elsewhere, it gets nulled.

    If I assign a value to the test variable before, that value gets replaced by null. I'm at a loss here :)

    I can only get output inside the get method, I can't get it out.
  • aloftaloft Member
    Uranday said:
    Make a number variable, create flow that assigns the output of the card to the variable. Use the special assign card that I thought is called set a variable (sry, not behind my pc.  But you can recognise because the dropdowns shows all variables) . This converts the variable (while others enforce the type). Then create a second flow that uses the variable in the condition. 
    Indeed, that works, thanks! 
  • Yes it did! And still does, but as soon as I try and capture that in a variable to use elsewhere, it gets nulled.

    If I assign a value to the test variable before, that value gets replaced by null. I'm at a loss here :)

    I can only get output inside the get method, I can't get it out.
    Think synchronous! At the time your code is at Homey.log, the function with result is not yet run.

    Try this:

    var test

    function callback() {
       Homey.log('Test var contains', test)
    }

    Homey.manager('api').get('/app/net.i-dev.betterlogic/weather', function (err, result) {
       test = result
       callback() 
    })

     
  • Ha! I only sort of half know what that means, but the code works!

    Thank you thank you thank you - I'll go play with this tomorrow and think synchronous until it makes sense :)
  • Uranday said:
    Submitted version 0.1.0 with the following features:

    * Feature: Added API support to GET, GET all variables and SET (post) a value.
        * PUT: HTTP://HOMEYADDRES/api/app/net.i-dev.betterlogic/VARIABLENAME/VALUE  //Please ensure that the value matches the type, otherwise it will not be set.


    Would it be possible to create API support for toggling a boolean where doing a PUT to the URL switches the boolean to it's other value, something like HTTP://HOMEYADDRES/api/app/net.i-dev.betterlogic/VARIABLENAME/toggle . Having that it would for instance allow to create toggle widget buttons in Tasker for Android.
  • I'll put it on my todo list! 
  • And another thing, would it be possible to add autorization headers with the bearer token to these API requests for better safety (similar as how the Homey api manager works)?
  • If an action card updates a variable using a token, and the token value is the same as the current value of the variable - does the time stamp change on the settings page?
  • I'm not sure. But I dont think so. What I do know is that it does not trigger an event. 
  • It would explain why it looks like some of my action cards didn't run, whereas they did (I use(d) the variable update time stamp as a simple debugging tool).
  • In my mind it only make sense to trigger if it changes. If there is a need for other behavior I can make a card for that.
  • No it's fine, you may want to put it in a FAQ or something - I blamed Erik's HTTP flows because I only looked at the timestamp on your settings page.

    And if the flow gets something that doesn't change, it looks like it didn't run.

    ErikVanDongen; it's not your app's fault! :)
  • No it's fine, you may want to put it in a FAQ or something - I blamed Erik's HTTP flows because I only looked at the timestamp on your settings page.

    And if the flow gets something that doesn't change, it looks like it didn't run.

    ErikVanDongen; it's not your app's fault! :)
    Thanks. I just started an investigation :)
  • Question is, do we want a trigger if the variable is set but not changed?
  • Uranday said:
    Question is, do we want a trigger if the variable is set but not changed?
    In HomeSeer I can choose between 'set to' or 'changed to'. And I use them in various scenarios.
  • Thing is, I could add a Variable Set card, but if you have a variable set and variable changed card both will trigger..
  • It would explain why it looks like some of my action cards didn't run, whereas they did (I use(d) the variable update time stamp as a simple debugging tool).
    Just one question. Did you mean that when you set the variable but it was the same variable as before that still the date changed was changed?
  • For the upcomming release. If anyone has any great sugestions for this release, please let me know!

    V0.9.0
    * After testing it is very stable, so almost at version 1.
    * Removed: Insights is removed for now until Athom stabalized the API for bool, int and string
    * Feature: Add toggle to API support
        * PUT: HTTP://HOMEYADDRES/api/app/net.i-dev.betterlogic/VARIABLENAME/toggle This will force to flip the boolean value
    * Feature: Enable authorization on the API.   
    * Feature: Add 'text starts with' condition
    * Bugfix: Dont change last changed timestamp when value is edited manually but not changed.



Sign In or Register to comment.