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

1235725

Comments

  • MarkVanWindenMarkVanWinden Member
    edited March 2016
    DELETED - NM, ill wait untill the release
  • DELETED - NM, ill wait untill the release
    You know how frustrating that is ;)
  • Uranday said:
    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.

    Hell yeah, you request something and a couple of days later it's implemented. Thanks a lot Uranday! I installed the GitHub version and the toggle and authorization on the API is working like a charm. I now have toggle switches on my phone that toggle devices. Great stuff ... :+1: 
  • Uranday said:
    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?
    A HTTP Get action from Eric's app polls an internet API every hour, the value it gets back gets strored in a Better Logic variable, but doesn't always change. This triggers another flow with the Get Step 2 card.

    When you're not aware that the time stamp doesn't change in that scenario, you could conclude that the first step (populate the variable) didn't work, therefore the second trigger also didn't do anything, etc.

    So in summary, the variable was set, but to the same value, so the time stamp was NOT changed. I now know to use a boolean flip for debugging. Those always change :)
  • I'm working on alternative presence detection.
    For this a generic list would come in handy.
    Triggers
    - Item added/removed (is duplicate)
    Conditions
    - list (not) contains
    Actions
    - add/remove (duplicate) item (string, number)

  • edited March 2016
    One small request - how would I handle a flow saying the value of a variable out loud? I can only get the value token from the variable if that variable changed. What if it didn't and I simply want to hear its current value?
  • woeiwoei Member
    edited March 2016
    Not sure if better logic would be the right place for this request...

    Is there any way we can record the time a device has been on (for the last x hours/days) without sensors, but just by keeping state? In the future I would like to be able to make decisions based on this information. Or even with sensors perhaps... Bear in mind that a delay card would not help here, as it might be the device has been on 5x for 2 hours during the past 24 hours. I want to be able to use the fact that a device has been on for 10 hours in the past 24 hours in a decision (and condition).

    For example, of my pool pump hasn't been running for more than 4 hours during the day, I want it to run at night until 4 hours is reached... This could be based on an on/off socket by keeping state, or a flow sensor detecting flow...

    It seems like logic building blocks and therefore i thought it might be a fit.
  • @Uranday is it possibble to make bitflip with a slider ?
  • TarikFaik said:
    @Uranday is it possibble to make bitflip with a slider ?
    I'm not sure if I understand what you mean. 

  • TarikFaikTarikFaik Member
    edited March 2016
    @Uranday ;; I have a arduino attached to my buva ventilation and have 4 switches to control 4 states but if you can make a slider ("Like a volume control") i can control it with 1 switch
    so if slider is <=25% set 1
    if >25 and <=50 set 2
    if >50 and <=75 set 4 enz.
    so that i don't need 4 controllers on my homey or is it possible to make one controller with multiple states?
  • I see what you mean. I am thinking about other devices but have to see if it is feasible. 
  • @Uranday and maybe also a variable value  as card like the bitflip card
  • TarikFaik said:
    @Uranday and maybe also a variable value  as card like the bitflip card

    Can you explain how you envision this? 


  • Version 0.9.0 is pushed to the appstore.
  • edited March 2016
    Change log or it didn't happen  :)

    Also, how can I use a variable token from the When column in the Then part, when the variable hasn't changed?

    Edit: doH! https://github.com/PatrickSannes/BetterLogic
  • Change log or it didn't happen  :)

    Also, how can I use a variable token from the When column in the Then part, when the variable hasn't changed?

    Edit: doH! https://github.com/PatrickSannes/BetterLogic
    You can not. I can see if this is possible to implement. Not sure though.
  • Im going to try to implement http://mathjs.org/docs/expressions/syntax.html

    This will be an advanced card with no syntax checking. Variables can be inserted with $ signs prefixed. The string will be searched for all $ variables and then they will be replaced. What do you think?


  • Would the output be a token? It does look very flexible though, and useful. Especially the unit conversion.
  • Would the output be a token? It does look very flexible though, and useful. Especially the unit conversion.
    It will start with boolean support. Once I know how I could output a token ill implement that too.
  • UrandayUranday Member
    edited March 2016
    Just for the fun of it I added an extra update to 0.9.1. Hope you guys like it!

    V0.9.1
    * Feature: Add Mathjs.org Condition card. Currently only boolean logic is supported. (Be aware, there is no syntax validation)
        * For supported features see http://mathjs.org/docs/expressions/syntax.html ;
        * An example could be $var1$ > 100 and $var1$ < 200 and $bool1$
    * Feature: Add card that triggers on change of one of the specified variables (Be aware, there is no syntax validation)
  • UrandayUranday Member
    edited March 2016
    Uranday said:
    Would the output be a token? It does look very flexible though, and useful. Especially the unit conversion.
    It will start with boolean support. Once I know how I could output a token ill implement that too.
    I was just thinking. What I could do is create an action card. There you specify your function and the variable that you want to assign. Makes more sense then trying to use an condition card. Then you could create a flow based on the trigger of the variable that is set.
  • One small request - how would I handle a flow saying the value of a variable out loud? I can only get the value token from the variable if that variable changed. What if it didn't and I simply want to hear its current value?
    I see two options. 
       - Make all triggers also when the variable is not changed, but when it is set. 
       - Make an extra trigger card that triggers always (even if it is not changed)
  • UrandayUranday Member
    edited March 2016
    woei said:
    Not sure if better logic would be the right place for this request...

    Is there any way we can record the time a device has been on (for the last x hours/days) without sensors, but just by keeping state? In the future I would like to be able to make decisions based on this information. Or even with sensors perhaps... Bear in mind that a delay card would not help here, as it might be the device has been on 5x for 2 hours during the past 24 hours. I want to be able to use the fact that a device has been on for 10 hours in the past 24 hours in a decision (and condition).

    For example, of my pool pump hasn't been running for more than 4 hours during the day, I want it to run at night until 4 hours is reached... This could be based on an on/off socket by keeping state, or a flow sensor detecting flow...

    It seems like logic building blocks and therefore i thought it might be a fit.
    Create a flow that checks every hour if the device is on. If it is on, increment a number with 1. Then make some flows that check that number at a specified time... This should do the trick. And at a specific time reset the counter to 0.
  • TarikFaik said:
    @Uranday ;; I have a arduino attached to my buva ventilation and have 4 switches to control 4 states but if you can make a slider ("Like a volume control") i can control it with 1 switch
    so if slider is <=25% set 1
    if >25 and <=50 set 2
    if >50 and <=75 set 4 enz.
    so that i don't need 4 controllers on my homey or is it possible to make one controller with multiple states?
    I implemented a slider device. It is based on the light dimmer module. But it is very hard to control. It gives no feedback in the app except for a color change. Thus darker is a smaller value and lighter is a higher value. I dont think this is usable. Just for testing purposes I created a branch on github (branch: slider). Maybe @Emile can think with us..?
  • Uranday said:
    One small request - how would I handle a flow saying the value of a variable out loud? I can only get the value token from the variable if that variable changed. What if it didn't and I simply want to hear its current value?
    I see two options. 
       - Make all triggers also when the variable is not changed, but when it is set. 
       - Make an extra trigger card that triggers always (even if it is not changed)
    Is that a hard choice or could they be combined with option 2 as a tick box? If it's a hard choice, I'd like #2 so I can use the value of a variable at any time, not just when it changed or got set. But that's just because I want Homey to say certain variables out loud when I push a button.
  • @Uranday is it possible to define a time variable and create a trigger that initiates a flow if the time is equal or bigger than the defined time variable..

    Idea behind this is that it would simplify the motion sensor flows
    Flow 1: when motion detected and luminance < xx lux then $time_motion = time + $time_offset + switch lights on
    Flow 2: when time >= $time_motion then switch lights off

  • UrandayUranday Member
    edited March 2016
    @Uranday is it possible to define a time variable and create a trigger that initiates a flow if the time is equal or bigger than the defined time variable..

    Idea behind this is that it would simplify the motion sensor flows
    Flow 1: when motion detected and luminance < xx lux then $time_motion = time + $time_offset + switch lights on
    Flow 2: when time >= $time_motion then switch lights off

    I dont like working with a date variable. Dates s*ck a bit in javascript. What would be workable and very easy to implement is to store a timestamp in a number format. (Amount of seconds since epoch) Then you can do everything that you can do with a number card. Would that work? Then create next to that a flow that triggers every X seconds with the timer card that sets a time variable (and this one you can reuuse for many flows). I dont think I can create time based triggers from my app. Flow would be then something like:

    Flow 1: when motion detected and luminance < xx lux then ($time_motion = time + $time_offset )+ switch lights on
    Flow 2: when $time changed and $time > $time_motion and lights on then switch lights off
    Flow 3: Every X seconds then $time = current time

    The advanced setting card will be made with mathjs.org. Ill introduce a special variable to add a time variable to it. So you get a card that has 2 inputs:
    Mathjsfunction: $timenow$ + 1800  (now + half an hour)
    Output variable: time_motion
  • woeiwoei Member
    Uranday said:
    woei said:
    Not sure if better logic would be the right place for this request...

    Is there any way we can record the time a device has been on (for the last x hours/days) without sensors, but just by keeping state? In the future I would like to be able to make decisions based on this information. Or even with sensors perhaps... Bear in mind that a delay card would not help here, as it might be the device has been on 5x for 2 hours during the past 24 hours. I want to be able to use the fact that a device has been on for 10 hours in the past 24 hours in a decision (and condition).

    For example, of my pool pump hasn't been running for more than 4 hours during the day, I want it to run at night until 4 hours is reached... This could be based on an on/off socket by keeping state, or a flow sensor detecting flow...

    It seems like logic building blocks and therefore i thought it might be a fit.
    Create a flow that checks every hour if the device is on. If it is on, increment a number with 1. Then make some flows that check that number at a specified time... This should do the trick. And at a specific time reset the counter to 0.
    Great suggestion... didn't think of that. Thanks
  • UrandayUranday Member
    edited March 2016
    I made one more update. Hope you all like it. I have to say I'm very happy with the results. If anyone has more suggestions, please let me know. Once the 1.0 release is finished I'll write a manual.

    For overview purposes, these are the release notes of the version now pushed.

    V0.9.2
    * Feature: Add Mathjs.org action card. Only number output is supported. (Be aware, there is no syntax validation)
        * For supported features see http://mathjs.org/docs/expressions/syntax.html ;
        * An example could be $var1$ + 100. This is then assigned to the selected number value
    * Feature: Add $timenow$ as a special variable for mathjs. This will retrieve the current time in seconds since epoch This variable is not stored in the overview, but used in expressions.
    * In the condition flow this can be used to test if a certain time is passed. $timenow$ > $storedTime$ + 1800 (half an hour)
        * In the action flow this can be used to create a time in the future by donig $timenow$ + 1800 (half an hour)
    * Feature: Add card that triggers when a variable is set but is or is not changed
        * The last changed date/time in the grid overview is now changed to the last set date/time

    V0.9.1
    * Feature: Add Mathjs.org condition card. Currently only boolean logic is supported. (Be aware, there is no syntax validation)
        * For supported features see http://mathjs.org/docs/expressions/syntax.html ;
        * An example could be $var1$ > 100 and $var1$ < 200 and $bool1$
    * Feature: Add card that triggers on change of one of the specified variables (Be aware, there is no syntax validation)

    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 of boolean (true->false or false->true) 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.
  • Very productive Easter weekend!
Sign In or Register to comment.