A small thing that doesn’t work as it should is the area of the question + answer from the telegram that I need help.
The telegram says the following:
I get a message saying which lamps are on in the house and then I get 3 options to choose what to do
Then I get a message that all the lights are on
Something in the process is not working well, can you help with this?
type or paste code here
[
{
"id": "e9fd92d9f1bde1a1",
"type": "group",
"z": "b7f8abdd0cbd314c",
"name": "",
"style": {
"stroke": "#ff0000",
"fill": "#bfdbef",
"label": true
},
"nodes": [
"38a4a0e85acfd9d5",
"5d698251de94ed4d",
"c286c5f078ba66f2",
"7803d1bfeeefd12e",
"f73a7cf2208c85db",
"6f35db8e57c8d63e",
"cb8a7612741adedc",
"4b96c9841eb3c882",
"1237fc8849fabc34",
"a44254bde56e1738",
"bb04cb14817cdcab",
"d55c9adb97099e88",
"18dad32d22ef2cdc",
"c7de547abfcdbe2d",
"3a24cecaa8a5e5a4",
"f45fe91a9d48bfbd"
],
"x": 254,
"y": 6779,
"w": 1532,
"h": 402
},
{
"id": "38a4a0e85acfd9d5",
"type": "comment",
"z": "b7f8abdd0cbd314c",
"g": "e9fd92d9f1bde1a1",
"name": "Send a message if lights are on when the last person leaves the house",
"info": "",
"x": 710,
"y": 6820,
"wires": []
},
{
"id": "5d698251de94ed4d",
"type": "function",
"z": "b7f8abdd0cbd314c",
"g": "e9fd92d9f1bde1a1",
"name": "Format Message Lights Status",
"func": "msg.payload = {\n message: msg.payload.replace(/\\n/g, '\\\\n'),\n title: \"⚠️ Lights Status ⚠️\"\n};\nreturn msg;",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1450,
"y": 6920,
"wires": [
[
"d55c9adb97099e88"
]
]
},
{
"id": "c286c5f078ba66f2",
"type": "api-render-template",
"z": "b7f8abdd0cbd314c",
"g": "e9fd92d9f1bde1a1",
"name": "Lights On",
"server": "12655a7fca458001",
"version": 0,
"template": "{%- set sensors = expand(states.light) | selectattr('state', 'eq', 'on') | list %}\n\n{%- if sensors | length > 0 %}\nThe following lights are on:\n {%- for sensor in sensors %}\n - {{ sensor.name }}\n {%- endfor %}\n{%- else %}\nAll lights are off.\n{%- endif %}\n",
"resultsLocation": "payload",
"resultsLocationType": "msg",
"templateLocation": "",
"templateLocationType": "none",
"x": 1240,
"y": 6920,
"wires": [
[
"5d698251de94ed4d"
]
]
},
{
"id": "7803d1bfeeefd12e",
"type": "ha-wait-until",
"z": "b7f8abdd0cbd314c",
"g": "e9fd92d9f1bde1a1",
"name": "wait x secs till lights are off",
"server": "12655a7fca458001",
"version": 2,
"outputs": 2,
"entityId": "light.",
"entityIdFilterType": "regex",
"property": "state",
"comparator": "is",
"value": "off",
"valueType": "str",
"timeout": "15",
"timeoutType": "num",
"timeoutUnits": "minutes",
"checkCurrentState": true,
"blockInputOverrides": true,
"outputProperties": [],
"entityLocation": "data",
"entityLocationType": "none",
"x": 440,
"y": 6920,
"wires": [
[],
[
"6f35db8e57c8d63e"
]
]
},
{
"id": "f73a7cf2208c85db",
"type": "comment",
"z": "b7f8abdd0cbd314c",
"g": "e9fd92d9f1bde1a1",
"name": "If no one is at home ask what to do",
"x": 720,
"y": 6860,
"wires": []
},
{
"id": "6f35db8e57c8d63e",
"type": "function",
"z": "b7f8abdd0cbd314c",
"g": "e9fd92d9f1bde1a1",
"name": "getFinishedText",
"func": "const machine = msg.payload.name\nconst text = `There are lights on in the house, but no one is home. what would you like to do?.`\n\nmsg.payload = text\nmsg.lembitu_text = text\nmsg.telegram = { chat: { id: 1234456789 } }\nreturn msg;",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 440,
"y": 6980,
"wires": [
[
"cb8a7612741adedc"
]
]
},
{
"id": "cb8a7612741adedc",
"type": "telegrambot-switch",
"z": "b7f8abdd0cbd314c",
"g": "e9fd92d9f1bde1a1",
"name": "Decision",
"bot": "",
"chatId": "123456789",
"question": "There are lights on in the house, but no one is home. What would you like to do?",
"answers": [
"Turn Off ALL Lamps",
"Don't do anything",
"Remind 15 min",
"Remind 1 h"
],
"outputs": 5,
"autoAnswerCallback": false,
"verticalAnswers": true,
"timeoutValue": "10",
"timeoutUnits": "min",
"parseMode": "",
"x": 660,
"y": 6980,
"wires": [
[
"1237fc8849fabc34",
"4b96c9841eb3c882"
],
[
"1237fc8849fabc34"
],
[],
[
"18dad32d22ef2cdc"
],
[
"c7de547abfcdbe2d"
]
]
},
{
"id": "4b96c9841eb3c882",
"type": "ha-get-entities",
"z": "b7f8abdd0cbd314c",
"g": "e9fd92d9f1bde1a1",
"name": "Get on Lamps",
"server": "12655a7fca458001",
"version": 1,
"rules": [
{
"property": "entity_id",
"logic": "is",
"value": "light.*",
"valueType": "re"
},
{
"property": "state",
"logic": "is",
"value": "on",
"valueType": "str"
}
],
"outputType": "split",
"outputEmptyResults": false,
"outputLocationType": "msg",
"outputLocation": "payload",
"outputResultsCount": 1,
"x": 880,
"y": 6920,
"wires": [
[
"a44254bde56e1738"
]
]
},
{
"id": "1237fc8849fabc34",
"type": "function",
"z": "b7f8abdd0cbd314c",
"g": "e9fd92d9f1bde1a1",
"name": "4 - Don't do anything",
"func": "const emojis = [\n '👍', '👌', '🙌', '👏', '🎉', '😄', '🤩', '💪', '✅', '🏆',\n '🌟', '🔥', '💯', '😊', '😁', '🙂', '😀', '😆', '😃', '🥳',\n '🤗', '😍', '🥰', '❤️', '💖', '💕', '💓', '💗', '💘', '💝',\n '💟', '💌', '🌈', '🎊', '🎈', '🎆', '🎇', '🍾', '🥂', '🎖️',\n '🥇', '🥈', '🥉', '🏅', '🎯', '🚀', '🌠', '💫', '✨', '🎶'\n ];\n\nfunction getRandomEmoji() {\n const randomIndex = Math.floor(Math.random() * emojis.length);\n return emojis[randomIndex];\n}\n\nmsg.payload = getRandomEmoji();\nreturn msg;",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 900,
"y": 6980,
"wires": [
[
"bb04cb14817cdcab"
]
]
},
{
"id": "a44254bde56e1738",
"type": "api-call-service",
"z": "b7f8abdd0cbd314c",
"g": "e9fd92d9f1bde1a1",
"name": "Turn Off Lamps",
"server": "12655a7fca458001",
"version": 5,
"debugenabled": false,
"domain": "light",
"service": "turn_off",
"areaId": [],
"deviceId": [],
"entityId": [],
"data": "{\"entity_id\":\"{{payload.entity_id}}\"}",
"dataType": "json",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"output_location": "",
"output_location_type": "none",
"mergecontext": "",
"x": 1060,
"y": 6920,
"wires": [
[
"c286c5f078ba66f2"
]
]
},
{
"id": "bb04cb14817cdcab",
"type": "telegrambot-notify",
"z": "b7f8abdd0cbd314c",
"g": "e9fd92d9f1bde1a1",
"name": "notify",
"bot": "",
"chatId": "123456789",
"message": "",
"parseMode": "",
"x": 1070,
"y": 6980,
"wires": []
},
{
"id": "d55c9adb97099e88",
"type": "api-call-service",
"z": "b7f8abdd0cbd314c",
"g": "e9fd92d9f1bde1a1",
"name": "Notify Telegram",
"server": "12655a7fca458001",
"version": 5,
"debugenabled": false,
"domain": "telegram_bot",
"service": "send_message",
"areaId": [],
"deviceId": [],
"entityId": [],
"data": "{\"message\":\"{{payload.message}}\",\"title\":\"{{payload.title}}\"}",
"dataType": "json",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 1680,
"y": 6920,
"wires": [
[]
]
},
{
"id": "18dad32d22ef2cdc",
"type": "delay",
"z": "b7f8abdd0cbd314c",
"g": "e9fd92d9f1bde1a1",
"name": "15 min",
"pauseType": "delay",
"timeout": "15",
"timeoutUnits": "minutes",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"allowrate": false,
"outputs": 1,
"x": 690,
"y": 7080,
"wires": [
[
"3a24cecaa8a5e5a4"
]
]
},
{
"id": "c7de547abfcdbe2d",
"type": "delay",
"z": "b7f8abdd0cbd314c",
"g": "e9fd92d9f1bde1a1",
"name": "",
"pauseType": "delay",
"timeout": "1",
"timeoutUnits": "hours",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"allowrate": false,
"outputs": 1,
"x": 680,
"y": 7140,
"wires": [
[
"3a24cecaa8a5e5a4"
]
]
},
{
"id": "3a24cecaa8a5e5a4",
"type": "link out",
"z": "b7f8abdd0cbd314c",
"g": "e9fd92d9f1bde1a1",
"name": "link out 11",
"mode": "link",
"links": [
"ad2c2a2368e9e066",
"f45fe91a9d48bfbd"
],
"x": 825,
"y": 7120,
"wires": []
},
{
"id": "f45fe91a9d48bfbd",
"type": "link in",
"z": "b7f8abdd0cbd314c",
"g": "e9fd92d9f1bde1a1",
"name": "link in to decision",
"links": [
"3a60872975e5aee4",
"20b5a984b5cf4991",
"3a24cecaa8a5e5a4"
],
"x": 295,
"y": 7020,
"wires": [
[
"6f35db8e57c8d63e"
]
]
},
{
"id": "12655a7fca458001",
"type": "server",
"name": "Home Assistant",
"addon": false,
"rejectUnauthorizedCerts": true,
"ha_boolean": "",
"connectionDelay": false,
"cacheJson": false,
"heartbeat": false,
"heartbeatInterval": "",
"statusSeparator": "",
"enableGlobalContextStore": false
}
```]