Removing part of string

I need to remove a part of a variable.
My Bosch washing machine reports remaining time as «160:0».
I need a flow for removing the «:0»-part and setting this as a number variable.

Any tips? :slight_smile:

This converts the time tag (string), say it is 11:07 AM, into the numeric value 11

Screenshot from 2023-04-26 19-46-34

I’m sure you can do the same with the Bosch variable/tag
{{ 0+("<RemainingTimeTag>".split(":")[1]) }}

You can play with the [1] if the wrong part is omitted before or after the ":" sign, by using [2] etc.


Thanks @Peter_Koolen! :grinning:


Next question @Peter_Kawa, how can I easily convert a numeric value (160) into a text variable in the format “1 hour and 40 minutes”?

Is it a quiz? :stuck_out_tongue_winking_eye:
Oh i’m not mister Koolen :blush: :wink:

Screenshot from 2023-04-26 21-33-14

Use the following THEN card
Screenshot from 2023-04-26 21-22-07

Replace the example code at the [Code] part with:

//Convert number (as argument) to HH:mm

function toHoursAndMinutes(totalMinutes) {
  const hours = Math.floor(totalMinutes / 60);
  const minutes = totalMinutes % 60;

  return `${hours} hour and${minutes > 0 ? ` ${Math.round(minutes)} minutes` : ''}`;

// To check the argument value:
console.log("Argument value:", args[0]);

return toHoursAndMinutes(args[0]);

Then you’ll get something similar like this, use a numeric variable or tag of your choice (I used just a numeric variable) as argument (=input), connect both cards and use local [Result] string tag in further processing:

The minutes get rounded, to avoid f.i. 45.766666666666 as the minutes number

Wrong Peter, typed without my glasses :nerd_face::sweat_smile:
Yet again: thanks a bunch @Peter_Kawa!! :grinning::grinning:

1 Like

Or you can use the Better Logic Library expressioncard:
Place this in the card: time('H" hours and "m" minutes"', 160*60*1000) and replace the 160 with the token/tag.



Endes up using this, @Arie_J_Godschalk. :grinning:
What If I want to add this value to the current time, and calculste at what time the washing machine is done?

At what time (date) in the day you mean?

Here, here you just add your token and multiply it to be milliseconds.
Then you add the current, which is the current time in milliseconds.
The result you put as second parameter to the date() function.
For other formats than datetime, like just time, see the Better Logic Library App Settings, there are a lot of options and you can create your own custom pre-defined format:

date('datetime', + 160*60*1000)

1 Like

I’ve been struggling with the following for a while now.

The ANWB route planner app creates travel times as follows: 00:30.

However, if I have this spoken through the Google Speaker, it makes it half past twelve at night.

I would like to remove 00: somehow.

How can I do this.

Not BLL, but it works:
The travel time is available from a tag I presume.

{{ 0+("[ANWB_tag]".split(":")[2]) }}

With your example of 00:30, it would be this calculation:
{{ 0+("00:30".split(":")[2]) }}

I tested with the [Time] tag:

You see it only uses the minutes part of the time:

Your the best. This works!!!

1 Like