AutoVoice (Hopefully) Easy Variable Problem (Removing a character)

Discussion in 'AutoApps' started by BenGmuN, Oct 6, 2015.

  1. BenGmuN

    BenGmuN New Member

    Joined:
    Sep 28, 2015
    Messages:
    25
    Likes Received:
    6
    I have a really silly problem with a Tasker variable that I'm struggling with. I'm hoping it's a really easy one to resolve!

    I want to set my variable to a number (using only numbers 0-9) that's either 1, 2 or 3 digits long. It's for a dimmer command for AutoHue. I want to be able to say "Set the lighting to XX%" (where XX will be a number between 1 and 100).

    I have set up my filter (using regex) as follows:

    Set the lighting to (?<value>.+)

    Note that the "%" symbol is not part of my filter and I have not forced it to use [0-9] - if I had, it wouldn't work, because Google Now automatically adds the % symbol to the end of the same variable value, so my variable ends up as XX%. I could just say "Set the lighting to XX", but I don't want to have to leave it out because it doesn't sound right and is harder to remember.

    So all I want to do is remove that last "%" symbol from the variable value. Any idea how? I've tried the split using the "%" symbol as the splitter, but that doesn't seem to work :-S I could use a variable section, but I don't know if my value is going to be 1, 2 or 3 digits long.

    Many thanks in advance!
     
    Last edited: Oct 6, 2015
  2. BenGmuN

    BenGmuN New Member

    Joined:
    Sep 28, 2015
    Messages:
    25
    Likes Received:
    6
    Ok, so, solved this myself (sort of) by adding the following replacement in the advanced settings of the AutoVoice recognised profile: %=

    So, it's replacing the percent symbol with nothing, so 50% becomes just 50, for example. Seems to do the job. If anyone knows of another cool way of achieving this, please do share! Thanks!

    Also, AutoHue needs a value from 0 to 255 (as opposed to between 0-100). Obviously I want 0% to equal 0, 50% to equal 127 and 100% to equal 255, etc., so I've just done a bit of maths with my variables (value * 2.56 - 1), a split to read the digits to the right of the decimal point, another variable set to prefix the second of the split variables with 0. and then add 1 if the value is higher than 0.5, thus rounding up to the nearest whole number. Again, if there's a neater/easier way of doing this, I'm all ears :) Cheers!
     
  3. joaomgcd

    joaomgcd Administrator Staff Member

    Joined:
    Feb 3, 2015
    Messages:
    9,479
    Likes Received:
    806
    Regarding your initial issue why not just use the regex

    Code (Text):
    Set the lighting to (?<value>.+)%
    ? :)
     
  4. BenGmuN

    BenGmuN New Member

    Joined:
    Sep 28, 2015
    Messages:
    25
    Likes Received:
    6
    Haha - that totally worked... I don't know why I didn't just try that - I think because I assumed the variable value would still include the "%" and I'd then have to say "Set the lighting to XX percent percent" in order to get it to trigger.

    Lesson learned! Thank you!
     

Share This Page