Hi,
Now, i am able to define a command for my bot and then when chosing an option, temperature for now, in telegram i would like to get the current.state of my sensor temperature.
I can see that the value is correct in debug 12, but function 3 doesn't execute to format the answer to be sent to the telegram sender.
The tuto i was following was using a request to influxdb_in instead of current.state to get the last value of my entity, but i wasn't able to make it working so i supposed that i can get the last value also with current.state....
If any advices....
27/12/2024 22:35:43noeud: debug 12
msg : Object
object
payload: "20.72"
originalMessage: object
id: "6031484955416982446"
from: object
id: 5699281820
is_bot: false
first_name: "Bernard"
language_code: "fr"
message: object
message_id: 50
from: object
id: 7451665920
is_bot: true
first_name: "Alerte"
username: "Alerte47bot"
chat: object
id: 5699281820
first_name: "Bernard"
type: "private"
date: 1735322010
text: "Selection?"
reply_markup: object
inline_keyboard: array[1]
0: array[2]
0: object
text: "Temperature"
callback_data: "1"
1: object
text: "Humidity"
callback_data: "2"
chat_instance: "6729422385743329509"
data: "1"
_msgid: "c627bcf6d38bbe28"
callback: object
chatId: 5699281820
messageId: 50
inlineMessageId: undefined
type: "callback_query"
content: "1"
callbackQueryId: "6031484955416982446"
from: object
id: 5699281820
is_bot: false
first_name: "Bernard"
language_code: "fr"
data: object
entity_id: "sensor.sonoff_salon_temperature"
state: "20.72"
attributes: object
state_class: "measurement"
unit_of_measurement: "°C"
device_class: "temperature"
friendly_name: "Sonoff Salon Température"
last_changed: "2024-12-27T21:31:09.287Z"
last_reported: "2024-12-27T21:31:09.287628+00:00"
last_updated: "2024-12-27T21:31:09.287Z"
context: object
id: "01JG50FHK7K1HH0RVPRZX4PSJB"
parent_id: null
user_id: null
timeSinceChangedMs: 273790
27/12/2024 22:35:43noeud: function 3
function : (error)
"TypeError: Cannot read properties of undefined (reading '0')"
[
{
"id": "5a5a89b553a3d32a",
"type": "tab",
"label": "Flux 5",
"disabled": false,
"info": "",
"env": []
},
{
"id": "c23f3dd1f48cdd9b",
"type": "telegram command",
"z": "5a5a89b553a3d32a",
"name": "",
"command": "/data",
"description": "",
"registercommand": false,
"language": "",
"scope": "default",
"bot": "f9e88713e8567cb0",
"strict": false,
"hasresponse": true,
"useregex": false,
"removeregexcommand": false,
"outputs": 2,
"x": 90,
"y": 100,
"wires": [
[
"92285107c7108b2d",
"a75b5ef5793b9b88"
],
[
"a75b5ef5793b9b88"
]
]
},
{
"id": "92285107c7108b2d",
"type": "function",
"z": "5a5a89b553a3d32a",
"name": "function 1",
"func": "var opts = {\n reply_markup: JSON.stringify({\n \"inline_keyboard\": [[\n {\n \"text\": \"Temperature\",\n \"callback_data\": \"1\"\n },\n {\n \"text\": \"Humidity\",\n \"callback_data\": \"2\" \n }]\n ]\n })\n};\n\nmsg.error = false;\n\nmsg.payload.content = 'Selection?';\nmsg.payload.options = opts;\n\nmsg.payload.chatId = 5699281820;\nmsg.payload.type = \"message\";\n\nreturn [msg];",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 300,
"y": 100,
"wires": [
[
"9f51b54ca5a55a95",
"dadfb1f107a8a154"
]
]
},
{
"id": "9f51b54ca5a55a95",
"type": "telegram sender",
"z": "5a5a89b553a3d32a",
"name": "",
"bot": "f9e88713e8567cb0",
"haserroroutput": false,
"outputs": 1,
"x": 550,
"y": 100,
"wires": [
[]
]
},
{
"id": "dadfb1f107a8a154",
"type": "debug",
"z": "5a5a89b553a3d32a",
"name": "debug 9",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 470,
"y": 200,
"wires": []
},
{
"id": "1fa16ed011242e3b",
"type": "telegram event",
"z": "5a5a89b553a3d32a",
"name": "",
"bot": "f9e88713e8567cb0",
"event": "callback_query",
"autoanswer": false,
"x": 100,
"y": 320,
"wires": [
[
"09c95e6087d856db"
]
]
},
{
"id": "09c95e6087d856db",
"type": "function",
"z": "5a5a89b553a3d32a",
"name": "function 2",
"func": "msg.callback = msg.payload;\n\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 330,
"y": 340,
"wires": [
[
"3a3f73ec1d478c96"
]
]
},
{
"id": "c46b25fbd6946d20",
"type": "function",
"z": "5a5a89b553a3d32a",
"name": "function 3",
"func": "if(msg.callback.content == 1){\n msg.payload.content = msg.payload.result[0].series[0].values[0][4] + \" °C\";\n}\nif(msg.callback.content == 2){\n msg.payload.content = msg.payload.result[0].series[0].values[0][4] + \" %\";\n}\n\nmsg.payload.type = \"message\";\nmsg.payload.chatId = 5699281820;\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 820,
"y": 420,
"wires": [
[
"f8ad4dda89077e04",
"b985f2a46240be1b"
]
]
},
{
"id": "f8ad4dda89077e04",
"type": "telegram sender",
"z": "5a5a89b553a3d32a",
"name": "",
"bot": "f9e88713e8567cb0",
"haserroroutput": false,
"outputs": 1,
"x": 870,
"y": 540,
"wires": [
[]
]
},
{
"id": "a75b5ef5793b9b88",
"type": "debug",
"z": "5a5a89b553a3d32a",
"name": "debug 11",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 190,
"y": 200,
"wires": []
},
{
"id": "3a3f73ec1d478c96",
"type": "api-current-state",
"z": "5a5a89b553a3d32a",
"name": "",
"server": "59781b09.703574",
"version": 3,
"outputs": 1,
"halt_if": "",
"halt_if_type": "str",
"halt_if_compare": "is",
"entity_id": "sensor.sonoff_salon_temperature",
"state_type": "str",
"blockInputOverrides": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
},
{
"property": "data",
"propertyType": "msg",
"value": "",
"valueType": "entity"
}
],
"for": "0",
"forType": "num",
"forUnits": "minutes",
"override_topic": false,
"state_location": "payload",
"override_payload": "msg",
"entity_location": "data",
"override_data": "msg",
"x": 660,
"y": 300,
"wires": [
[
"c773343a607756f7",
"c46b25fbd6946d20"
]
]
},
{
"id": "c773343a607756f7",
"type": "debug",
"z": "5a5a89b553a3d32a",
"name": "debug 12",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 790,
"y": 200,
"wires": []
},
{
"id": "b985f2a46240be1b",
"type": "debug",
"z": "5a5a89b553a3d32a",
"name": "debug 13",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 670,
"y": 480,
"wires": []
},
{
"id": "f9e88713e8567cb0",
"type": "telegram bot",
"botname": "Alerte",
"usernames": "Alerte47bot",
"chatids": "56xxxxxx20",
"baseapiurl": "",
"testenvironment": false,
"updatemode": "polling",
"addressfamily": "",
"pollinterval": "300",
"usesocks": false,
"sockshost": "",
"socksprotocol": "socks5",
"socksport": "6667",
"socksusername": "anonymous",
"sockspassword": "",
"bothost": "",
"botpath": "",
"localbotport": "8443",
"publicbotport": "8443",
"privatekey": "",
"certificate": "",
"useselfsignedcertificate": false,
"sslterminated": false,
"verboselogging": false
},
{
"id": "59781b09.703574",
"type": "server",
"name": "Home Assistant",
"addon": true
}
]