Variable in expression

Post your questions and help other users.

Moderator: Martin

coconutxyz
Posts: 38
Joined: 16 Sep 2019 12:51

Variable in expression

Post by coconutxyz » 30 Dec 2019 13:10

Hi guys I am stuck with trying to assign a variable inside an expression.

My current flow using hotword plugin

Condition: value = "meditate for {meditateduration} minutes"

Action: script : meditateduration = getDurationString(duration*60000)

Action: set timer {meditateduration}

As expected it doesn't work lol since the whole expression looks weird. Any help please..

User avatar
tsolignani
Posts: 187
Joined: 12 Jan 2019 11:53
Location: Vignola, Mo, Italy
Contact:

Re: Variable in expression

Post by tsolignani » 30 Dec 2019 14:06

Post the flow please.

coconutxyz
Posts: 38
Joined: 16 Sep 2019 12:51

Re: Variable in expression

Post by coconutxyz » 30 Dec 2019 23:18

My bad
Attachments
flow_Flow4_20191231_071649.xml
(1.65 KiB) Downloaded 710 times

User avatar
tsolignani
Posts: 187
Joined: 12 Jan 2019 11:53
Location: Vignola, Mo, Italy
Contact:

Re: Variable in expression

Post by tsolignani » 31 Dec 2019 07:01

It seems all wrong to me, what are you trying to do?

coconutxyz
Posts: 38
Joined: 16 Sep 2019 12:51

Re: Variable in expression

Post by coconutxyz » 31 Dec 2019 14:57

lmao is it that bad?

it works if i am using autovoice with the command (?:meditate|meditation) for (?<duration>[0-9]+) (?:minute|minutes) which i believe is regex.

then i will run a script to times the duration with 60000 to convert it to minutes then set a timer for the converted duration.

since i no longer use autovoice and changed to hotword plugin now, i am trying to assign a variable {meditateduration} within the expression using the hotword plugin whose variable is {value}.

User avatar
tsolignani
Posts: 187
Joined: 12 Jan 2019 11:53
Location: Vignola, Mo, Italy
Contact:

Re: Variable in expression

Post by tsolignani » 31 Dec 2019 15:01

I'm not sure I understood what you said, anyway, I guess you cannot assign values to a variable into an expression but just evaluate it with a double equal sign, if you have to populate a variable you have to use a script.

Micky Micky
Posts: 179
Joined: 16 Oct 2019 17:38

Re: Variable in expression

Post by Micky Micky » 31 Dec 2019 17:39

You can assign variables in an expression but you still need something to check at the end.
Crude but it works.

Micky Micky
Posts: 179
Joined: 16 Oct 2019 17:38

Re: Variable in expression

Post by Micky Micky » 31 Dec 2019 17:48

The flow is confusing.

If the variable {value} that you are passed from elsewhere contains the number of minutes e.g. 1 then you can set the timer to:

{value}m

Hope this is of some help to you .
Crude but it works.

Micky Micky
Posts: 179
Joined: 16 Oct 2019 17:38

Re: Variable in expression

Post by Micky Micky » 31 Dec 2019 18:10

If the variable {value} contains the number within a message then regex is the way to extract just the number.

I don't understand regex, but this crude method works.

Code: Select all

value = "I said 12 minutes";
minutes = replace (join (findAll (value, "\\d"), ","), ",", "");
Good luck
Crude but it works.

coconutxyz
Posts: 38
Joined: 16 Sep 2019 12:51

Re: Variable in expression

Post by coconutxyz » 01 Jan 2020 05:28

thanks for everyone's help

still cant find the solution but i have included the full flow
flow_Flow4_20200101_132628.xml
(4.6 KiB) Downloaded 766 times

Post Reply