Hey everyone, I’m trying to format a message for my Telegram bot reply, but it seems like the .replace() method isn’t working as expected in my rules. Let me walk you through what I’m doing and where I’m stuck.
I have a rule called Report Temp by Telegram. The goal is to send a formatted temperature report to my Telegram bot. Here’s what I’m doing step by step:
- Initializing the variable: I start by initializing a string variable
TempText. - Preparing the Telegram action: I get the Telegram action using
getActions(). - Collecting temperature data: I loop through all thermostat members to build the temperature text. For each item, I try to replace parts of the string to format it correctly.
- Replacing placeholders: I attempt to replace placeholders in the string with actual values, but it doesn’t seem to work.
- Sending the message: Finally, I send the formatted message to the Telegram bot and log it for debugging.
Here’s the code snippet where I’m having trouble:
javascript
allTermostatIst.members.forEach[item | TempText.replace(item.name + “_Label”, item.label) logInfo(“TempTest”, item.name + “_Label”) ]
allTermostatIst.members.forEach[item | TempText.replace(item.name + “_State”, item.state.toString)]
I expected this to replace the generated placeholders like Termostat_SZ_Temp_Ist_Label with the actual item.label, but it’s not working as intended. The output is just the raw string without any replacements.
I’m not sure where I’m going wrong. Is there something I’m missing about how .replace() works in rules? Any help would be greatly appreciated! I really want to get this working to have a clean and informative temperature report.