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

1131416181925

Comments

  • Can i have a question: I have Bitflip devices for a http post flow controlling a wifi roller shutter. Wenn i set "on" in Bitflip devices and the variable is already set to "true" from the last time, is this variable set to "true" one more time or is ignoring the changes?
    Tnx
  • viktor said:
    Can i have a question: I have Bitflip devices for a http post flow controlling a wifi roller shutter. Wenn i set "on" in Bitflip devices and the variable is already set to "true" from the last time, is this variable set to "true" one more time or is ignoring the changes?
    Tnx
    It depends. You have 2 type of triggers, the on set and the on change. On change should not trigger, On set should trigger.
  • It would be a really nice option to edit the icon of a bitflip switch!
  • tim1990 said:
    It would be a really nice option to edit the icon of a bitflip switch!
    And the name :)
    It takes the name of the variable, but that's not always what you want to see as device name.
  • Fire69 said:
    tim1990 said:
    It would be a really nice option to edit the icon of a bitflip switch!
    And the name :)
    It takes the name of the variable, but that's not always what you want to see as device name.
    It's a device, you can rename devices?
  • Fire69 said:
    tim1990 said:
    It would be a really nice option to edit the icon of a bitflip switch!
    And the name :)
    It takes the name of the variable, but that's not always what you want to see as device name.
    It's a device, you can rename devices?
    OMG  :D
    Why didn't I think of that! 
  • edited October 2016
    Using @GeurtDijker's excellent PowerShell module, I've hacked together a little script that checks for orphaned variables and variables that exist but are not used. Enjoy!

    #
    #check better logic variable usage against your flows!
    #
    #set user variables
    $cloudID = "your cloud id"
    $bearerToken = "your bearer token"
    $exportPath = "path to homey export files"
    #set other variables
    $headers = @{"Authorization"="Bearer $bearerToken"} 
    $contentType = "application/json"
    $cloudHostname = "$cloudID.homey.athom.com"
    $cloudLocalHostname = "$cloudID.homeylocal.com"
    #get better logic variables
    $bLVariables = Invoke-WebRequest -Uri "http://$cloudLocalHostname/api/app/net.i-dev.betterlogic/ALL" `
        -Headers $headers -ContentType $contentType
    $bLVariables = ($bLVariables.Content | ConvertFrom-Json).Result
    #import HomeyPSCLI module and connect to Homey
    Import-Module HomeyPSCLI
    Connect-Homey -CloudID $cloudID -Bearer $bearerToken -ExportPath $exportPath
    #get all flows
    $allFlows = Get-HomeyFlows
    #find flows with better logic variables in the
    #trigger, conditions or actions
    $betterLogicInTrigger = $allFlows | where {$_.trigger.uri -contains "homey:app:net.i-dev.betterlogic" }
    $betterLogicInActions = $allFlows | where {$_.actions.uri -contains "homey:app:net.i-dev.betterlogic" }
    $betterLogicInConditions = $allFlows | where {$_.conditions.uri -contains "homey:app:net.i-dev.betterlogic" }
    $betterLogicInFlows = $betterLogicInTrigger.trigger.args.variable.name + `
                          $betterLogicInConditions.conditions.args.variable.name + `
                          $betterLogicInActions.actions.args.variable.name | select -Unique
    #compare the list of better logic variables to
    #the list of flows containing better logic variables
    $comparison = Compare-Object -ReferenceObject ($bLVariables).Name `
                  -DifferenceObject $betterLogicInFlows
    #write output on screen
    Write-Host -ForegroundColor Yellow "BetterLogic variables only existing in BetterLogic:"
    $onlyInBl = ($comparison | where {$_.SideIndicator -eq "<="}).InputObject 
    $onlyInBl | foreach {Write-Host $_}
    Write-Host -ForegroundColor Yellow "BetterLogic variables only existing in flows (orphaned):"
    Write-Host -ForegroundColor Yellow "CountDown timers are also listed!"
    $onlyInFlows = ($comparison | where {$_.SideIndicator -eq "=>"}).InputObject 
    $onlyInFlows | foreach {Write-Host $_}
    Write-Host -ForegroundColor Yellow "List of flows containing orphaned variables:"
    foreach ($flow in $onlyInFlows) {
        Write-Host -ForegroundColor Red $flow
        Write-Host -ForegroundColor Yellow "Exists in these flows:"
        $flowsContainingOrphanedVars = @()
        $flowsContainingOrphanedVars += ($allFlows | where {$_.trigger.args.variable.name -contains $flow }).title
        $flowsContainingOrphanedVars += ($allFlows | where {$_.actions.args.variable.name -contains $flow }).title
        $flowsContainingOrphanedVars += ($allFlows | where {$_.conditions.args.variable.name -contains $flow}).title
        $flowsContainingOrphanedVars | select -Unique
        }

    Copy/paste into PowerShell ISE or notepad, fill in your Homey's CloudID, BearerToken and ExportPath (nothing gets written there) and you're good to go.

    Assuming you have Geurt's PowerShell module installed - it's in the app store.

    Known issue: it will list CountDown timers as BetterLogic variables :smile: 

  • I have a suggestion/wish, I don't know if it has been asked before (didn't feel like reading through 16 pages...).

    It would be great if a variable type "enum" (or "list") could be added. For example, I use variables to keep track of the "light state" of each room ("off", "manual", "movement", etc). So if movement is not detected anymore but the state is "manual" (because the wall switch was pressed), the light will not switch off.
    Also I use variables like this to keep track of the "home state" (sleeping, away, at home, vacation).

    At the moment I've configured variables with the string type, but it would be great if I would be limited in the choices i.e. the list values.
  • Using @GeurtDijker's excellent PowerShell module, I've hacked together a little script that checks for orphaned variables and variables that exist but are not used. Enjoy!

    #
    #check better logic variable usage against your flows!
    #
    #set user variables
    [...]
        }

    Copy/paste into PowerShell ISE or notepad, fill in your Homey's CloudID, BearerToken and ExportPath (nothing gets written there) and you're good to go.

    Assuming you have Geurt's PowerShell module installed - it's in the app store.

    Known issue: it will list CountDown timers as BetterLogic variables :smile: 

    Great script! Thanks for the compliments, 
    be carefull, 
    One BL var is listed as living in  BL only, but my HomeAutomation boolean var is a BitFlip Device and in use as a device check in the flows.  I see this as a great Check-HomeyBetterLogicVariableUsage function!
  • SergeR said:
    I have a suggestion/wish, I don't know if it has been asked before (didn't feel like reading through 16 pages...).

    It would be great if a variable type "enum" (or "list") could be added. For example, I use variables to keep track of the "light state" of each room ("off", "manual", "movement", etc). So if movement is not detected anymore but the state is "manual" (because the wall switch was pressed), the light will not switch off.
    Also I use variables like this to keep track of the "home state" (sleeping, away, at home, vacation).

    At the moment I've configured variables with the string type, but it would be great if I would be limited in the choices i.e. the list values.
    I'll put this on my backlog. If this is doable Ill implement it. 
  • Using @GeurtDijker's excellent PowerShell module, I've hacked together a little script that checks for orphaned variables and variables that exist but are not used. Enjoy!

    #
    #check better logic variable usage against your flows!
    #
    #set user variables
    $cloudID = "your cloud id"
    $bearerToken = "your bearer token"
    $exportPath = "path to homey export files"
    #set other variables
    $headers = @{"Authorization"="Bearer $bearerToken"} 
    $contentType = "application/json"
    $cloudHostname = "$cloudID.homey.athom.com"
    $cloudLocalHostname = "$cloudID.homeylocal.com"
    #get better logic variables
    $bLVariables = Invoke-WebRequest -Uri "http://$cloudLocalHostname/api/app/net.i-dev.betterlogic/ALL" `
        -Headers $headers -ContentType $contentType
    $bLVariables = ($bLVariables.Content | ConvertFrom-Json).Result
    #import HomeyPSCLI module and connect to Homey
    Import-Module HomeyPSCLI
    Connect-Homey -CloudID $cloudID -Bearer $bearerToken -ExportPath $exportPath
    #get all flows
    $allFlows = Get-HomeyFlows
    #find flows with better logic variables in the
    #trigger, conditions or actions
    $betterLogicInTrigger = $allFlows | where {$_.trigger.uri -contains "homey:app:net.i-dev.betterlogic" }
    $betterLogicInActions = $allFlows | where {$_.actions.uri -contains "homey:app:net.i-dev.betterlogic" }
    $betterLogicInConditions = $allFlows | where {$_.conditions.uri -contains "homey:app:net.i-dev.betterlogic" }
    $betterLogicInFlows = $betterLogicInTrigger.trigger.args.variable.name + `
                          $betterLogicInConditions.conditions.args.variable.name + `
                          $betterLogicInActions.actions.args.variable.name | select -Unique
    #compare the list of better logic variables to
    #the list of flows containing better logic variables
    $comparison = Compare-Object -ReferenceObject ($bLVariables).Name `
                  -DifferenceObject $betterLogicInFlows
    #write output on screen
    Write-Host -ForegroundColor Yellow "BetterLogic variables only existing in BetterLogic:"
    $onlyInBl = ($comparison | where {$_.SideIndicator -eq "<="}).InputObject 
    $onlyInBl | foreach {Write-Host $_}
    Write-Host -ForegroundColor Yellow "BetterLogic variables only existing in flows (orphaned):"
    Write-Host -ForegroundColor Yellow "CountDown timers are also listed!"
    $onlyInFlows = ($comparison | where {$_.SideIndicator -eq "=>"}).InputObject 
    $onlyInFlows | foreach {Write-Host $_}
    Write-Host -ForegroundColor Yellow "List of flows containing orphaned variables:"
    foreach ($flow in $onlyInFlows) {
        Write-Host -ForegroundColor Red $flow
        Write-Host -ForegroundColor Yellow "Exists in these flows:"
        $flowsContainingOrphanedVars = @()
        $flowsContainingOrphanedVars += ($allFlows | where {$_.trigger.args.variable.name -contains $flow }).title
        $flowsContainingOrphanedVars += ($allFlows | where {$_.actions.args.variable.name -contains $flow }).title
        $flowsContainingOrphanedVars += ($allFlows | where {$_.conditions.args.variable.name -contains $flow}).title
        $flowsContainingOrphanedVars | select -Unique
        }

    Copy/paste into PowerShell ISE or notepad, fill in your Homey's CloudID, BearerToken and ExportPath (nothing gets written there) and you're good to go.

    Assuming you have Geurt's PowerShell module installed - it's in the app store.

    Known issue: it will list CountDown timers as BetterLogic variables :smile: 

    Nice script. If I have a dark sunday afternoon ill see if there is any chance of implementing this in te library. Looks doable.
  • Uranday said:
    SergeR said:
    I have a suggestion/wish, I don't know if it has been asked before (didn't feel like reading through 16 pages...).

    It would be great if a variable type "enum" (or "list") could be added. For example, I use variables to keep track of the "light state" of each room ("off", "manual", "movement", etc). So if movement is not detected anymore but the state is "manual" (because the wall switch was pressed), the light will not switch off.
    Also I use variables like this to keep track of the "home state" (sleeping, away, at home, vacation).

    At the moment I've configured variables with the string type, but it would be great if I would be limited in the choices i.e. the list values.
    I'll put this on my backlog. If this is doable Ill implement it. 
    Great, this would be very usefull for me too.
  • Hm - two BL variables disappeared again, could be to a non-PTP reboot.

    One thing I did notice, if you've selected a few variables with a search query, and press the Delete button, nothing seems to happen, so you hit the button again. And again! And then you realize you've just deleted three variables :smile: 

  • Hi,

    Maybe a stupid question that has been answered before, but I couldn't find it anywhere (believe me I tried, and btw does the search on this forum suck or is it just me?).
    Anyway... The Aeotec multisensor 6 has a light sensor. The value is in lux (number), but betterlogic only seems to accept these values as strings. So I also tried to parseInt the variable but that doesn't seem to work either.
    What am I doing wrong? First time experimenting with the BetterLogic app (love it, by the way! :) ) so forgive me for the newbee question...


    Cheers,

    Rob
  • If you want the value in a variable, user the "set a variable" card, that one will put it correctly into an number variable and change it to a proper integer
  • GeurtDijkerGeurtDijker Member
    edited October 2016
    Hi,

    Maybe a stupid question that has been answered before, but I couldn't find it anywhere (believe me I tried, and btw does the search on this forum suck or is it just me?).
    Anyway... [...]
    Cheers,
    Rob
    Off topic: to answer your first part, 
    Yes it is a known and already discussed  topice the chappy forum search. ... 
    We have found you should search using Google filtered on this site:athom.com 
    But that is a vicious circle if no one told you. 
    http://lmgtfy.com/?q=site:athom.com+forum+search+google&nbsp;
  • Thanks @caseda , Will try that.
    @GeurtDijker, Tried that to, but couldnt find anything that way either, but thanks for the tip...
  • edited October 2016
    Hi,

    Would it be possible to show which vars are in use (and maybe how often) ? I am using this that often that I have created a huge list on vars :)
  • These can be seen on the settings-page?
  • You can see atleast when it was updated for the last time. When having some spare time ill see if I can use the script posted earlier to get usage data.
  • UrandayUranday Member
    edited October 2016
    Just a minor update. After the last firmware update the decimal support works now in the flows! Happy flowing ;) And thanks again for the donations that I got. It makes me happy everytime my paypall app gives me a notification ;)
  • technimantechniman Member
    edited November 2016
    I have a request (several actually),
    - The creation of variables through import  (seems to be there already just not working for me :*
    - Different Icons 
    - "BitFlip" alternative  for String/Number variables

    Why you ask? 
    I'd like to integrate Domoticz with Homey, all the "yes/no, on/off,open/close" switches can be set as a boolean 
    but the temp sensors (number) &  status (string) would be a different challenge  

    I'm working on a php script that would output the devices is the "correct" format
    to be able to import the variables into Homey,  


  • Yesterday I had some problems with BL.  I don't know if it was caused by BL itself or Homey...

    I first noticed because my moodlights didn't turn on at sunset.  Those are triggered by a boolean.  After checking, that variable had disappeared...
    I recreated it, but then it appeared twice!  1 with 'Last set' at that moment, 1 from the night before (when I turned off the lights).
    I tried deleting the old one, but that was not possible!  Delete button did nothing.
    To try and solve this, I did an Export, Delete All, Import.  I checked the export, the variable was only once there.
    But after the import, I still had it twice!!  :o
    So I deleted everything again, removed the variable from the export and imported everything again.
    The variable was not there now, so I created it manually and that appears to have solved the problem.

    Then, an hour later, I was changing some flows and noticed another variable missing in the autocomplete!
    When I checked in BL settings page, 7 variables were gone  :s  (I hope, don't know the entire list by heart, so hopefully no other are missing...)

    So, what I would like to request (to make a long story short :) ):
    Could you add a counter to the settings showing the total number of variables?  So we have a way of checking if the number of variables has changed (unexpectedly)?

    Thanks!
  • It seems there is a bug with the filter when variables are added or deleted when there is a filter on the variables table. Did you use the filter ? 
  • I did at some point during testing, but can't remember when exactly.
    But that wouldn't explain:
    - the 7 missing variables, I was adjusting flows when I noticed those were gone
    - the variable that came back twice after deleting all and importing (where I made sure it was only listed once)
  • Can you send your export file? See if I can reproduce. . 
  • Sure, but as far as i can see there's nothing special in it :)


  • I had the same problems, BL variables gone, reinstalled them al manual, It is possible that I used the filter, but the results are the same as mentioned by @Fire69 . Variables gone, duble variables
  • Uranday said:
    You can see atleast when it was updated for the last time. When having some spare time ill see if I can use the script posted earlier to get usage data.
    Great, thanks!
Sign In or Register to comment.