This is an example on how to use AutoSheets for Tasker variables that are stored in the cloud.
This means that no matter which device you're on, you can get a consistent value for a certain variable.
Import the project above and run the Test Cloud Variables task to see how it works.
Breakdown of the actions in the Update Cloud Variable Task
- Multiple Variable Set is used to simply save some default values for %par1 and %par2 for testing. Not needed in a real situation and can be deleted if not needed. %par1 will contain the variable name you want to store in the cloud and %par2 will contain the variable value.
- If to check if no error is yet set. An error can be set if the actions below generate an error and a second attempt of writing the variable is done
- Variable Set %secondtime to 1 to mark that this is the second try. Below, if we get another error again, we'll stop the task instead of trying again if it's the second time we're trying.
- Variable Clear %errmsg so that we can try again fresh without the existing error.
- End If to close the If above
- AutoSheets Get Spreadsheet: Gets the ID for the spreadsheet named Cloud Variables (will error out if the spreadsheet doesn't exist yet)
- If no error in previous action (this means that the spreadsheet already exists) then get the existing variable names from the sheet by getting all the fields in the first column with AutoSheets Get Data and setting Output Array Names to varnames. This will create a %varnames() array in Tasker with all the contents of the first column of the sheet
- Flash (disabled): show the existing varnames and other info if needed. Disabled so it doesn't display normally, but you can enable it for testing
- If to check if the variable name you want to write already exists on the spreadsheet. If it does than the %varnames(#?%par1) expression should return a number different than 0. More info here.
- If the variable doesn't exist yet lets add it at the end of the variable list with the AutoSheets Add Rows action
- Let's update the value for the existing variable using the AutoSheets Update Cells action
- End If above
- If the error we got in A6 while getting the Spreadheet ID includes the words no spreadsheet this means that the sheet doesn't exist yet. We need to create the sheet and then try again
- Stop the task if we already tried before and still got the same error... This shouldn't happen...
- Use AutoSheets Create Spreadsheet to create a new spreadsheet with the name Cloud Variables
- Goto the A2 action again and try it again all over again
- End If above
Cloud Variables 2021-03-23
Store/Read variables from the cloud with the help of a Google Spreadsheet with AutoSheets