I have a flow where the IF card triggers when a universal message from one specific app comes on. The AND card is a sort of filter, that only triggers and goes further if the word “SERVICE” is inside the text.
The THEN card is just a whatsapp message to several numbers.
So far so good.
But i truelly want to replace the message text with a own text.
So i want to know if the AND card could transform text between two words in the original message to a general/other message.
Example:
The universal message is “SERVICE failure noted, engineers planned: NAME 1 (ex. DENIS), NAME 2 (ex. HERO), NAME 3 (ex. ECHO), NAME 4 (ex. DELTA).
Engineers not planned: NAME 5 (ex. FOXTROT), NAME 6 (ex. DARK)”
When ECHO is inside the text between ‘planned’ and ‘not planned’; i want to let the flow send a message: ECHO is planned for the service. Other names may deleted. If ECHO is not planned, then send the text “ECHO is NOT planned”.
So in short terms: can i replace a text from a app/device with other text, based on only one name?
If that name is not in the text, then send message with ECHO is not planned for service.
If the name ECHO is inside the text, then send ECHO is planned for service.
Hope this is clear enough, i know its maybe a little bit unclear but im currently very new with homey.Thank you very much
This flow is just for a little service company which works with a beepservice.
This adds the variable data (text/numbers/TrueFalse) to the entered fixed text.
So no matter what the variables data is, at the time of the flow trigger their current value gets “printed”
Thank you, but if the message is:
\“SERVICE failure noted, engineers planned: NAME 1 (ex. DENIS), NAME 2 (ex. HERO), NAME 3 (ex. ECHO), NAME 4 (ex. DELTA).
Engineers not planned: NAME 5 (ex. FOXTROT), NAME 6 (ex. DARK)”
The names above are random, based on the random availability of the workers. But for one worker (ECHO) i want to send always a whatsapp message if he is planned for service turns.
Sometimes he would be planned, sometimes not. How can i prepare this in a card?
So if he is in the PLANNED section i want to send him that he is planned, but if he is in the NOT planned section i want to send him that is not planned and he can stay at home.
The name is alway the same, but within the message SERVICE failure noted, engineers planned - i need to filter; if his name is BEFORE not planned, he will get the PLANNED message - if his name is after not planned than he can get the message not planned stay at home.
I know, maybe a little bit difficult but hope it is clear now
With this logic conditional cards (AND cards), you can direct the advanced flow results to different paths, depending on the text, or names, the variables contain.
Like,
if text in variable (partly) matches, do this; if not, do that:
Hahaha oke, i was hoping there was a simple logic card where it can tell me if a word is before specific text or not. If that should be there, this whole thing is fixed. But im affraid that it will be not there, haha.
It is a notification/message from an external app. It comes in a tag indeed.
I was hoping to filter this text and make a card IF name ECHO is after the text ‘not planned’ then it can send a whatsapp message to the worker with you are not planned in.
Create a homeyscript with ChatGPT;
It takes your textstring as an argument and returns PLANNED or NOTPLANNED.
I use ChatGPT all the time
// Check if arguments are provided
if (args && args.length > 0) {
// Retrieve the first string from the arguments
let inputString = args[0];
// Define the text we’re looking for
let searchText = “not planned”;
let name = “ECHO”;
// Check if ‘not planned’ and ‘ECHO’ exist in the string
let indexSearchText = inputString.indexOf(searchText);
let indexName = inputString.indexOf(name);
if (indexName !== -1 && indexSearchText !== -1) {
// Check if ‘ECHO’ comes before ‘not planned’
if (indexName < indexSearchText) {
return “PLANNED”;
} else {
return “NOT PLANNED”;
}
} else {
return “The text must contain both ‘ECHO’ and ‘not planned’.”;
}
} else {
return “No text string provided.”;
}
Cool, I see. I use a variable in my example, but a tag can be used as well, as argument to a homeyscript THEN card “Run code with argument, and return text-tag”
So I created something as well
So, the code to use in the homeyscript card:
Without comments, it’s only 4 lines (I did not provide for “if argument is empty” stuff yet", to keep it simple to start with):
// Get position the word ECHO in argument
let pos = args[0];
pos = pos.toLowerCase();
var start = pos.indexOf("echo");
return Number(start);
With comments:
// Get position the word ECHO in argument
// argument could be either:
// "One two three ECHO is planned." or
// "One two three not planned: ECHO."
let pos = args[0];
pos = pos.toLowerCase();
// Get position where "echo" starts, regardless of upper/lowercase
var start = pos.indexOf("echo");
// Just a check:
// For 4 letter word: Extract 4 characters starting at that position
var result = pos.substr(start, 4);
console.log(`Start: ${start} - Result: ${result}`);
return Number(start);
Big Thumbs up for the reaction(s). Thank you very much.
Actually, this custom scripting is a station too far for me (yet)… im new with homey and choose it because it looks like easy to use. But this gonna be a bit difficult for me.