Programming function node on Node-red to tell me the Temperature with TTS

With my tasmota set up I get the Temperature as an object from my SI7021 sensor.
I want Rhasspy to tell me the temperature when it recognizes an intent,but I don’t know how to make the function so the TTS engine reads the value of the Temperature.
This is what I have done thus far

If you publish something like this

msg.payload = {siteId: siteid, text: "The temperature is " + payload.SI7021.temperature};

to the mqtt topic

hermes/tts/say
ie. set msg.topic to hermes/tts/say in the function

It should send the message to the your rhasspy device

I am using espeak for TTS in Rhasspy.
You mean I have to change to Hermes MQTT?

No, Rhasspy will create a audible response from the “text” in the payload using the selected TTS engine (eSpeak in your case)

Is it possible to explain to me more simple?
Is my flows correct? What do I change in my function?

We can;t see the whole flow because the function window is covering half of it but if we assume the correct intent goes to the correct function, the function should basically be

msg.payload = {siteId: siteid, text: "The temperature is " + payload.SI7021.temperature};
msg.topic = “hermes/tts/say”;
return msg;

and the output should be sent to an mqtt node publishing to the mqtt broker used by rhasspy

I should add, you need to replace the siteId with the value that would be included with the intent message received from rhasspy

I got confused,why the flow must go to an mqtt out if I want the TTS engine of Rhasspy to read the message?
This is my entire flow

Only because rhasspy communications are generally using the hermes mqtt message protocol and without additional information I gave you an answer to your original question that I use successfully in my configuration and know works, which is to publish it to the MQTT broker that rhasspy is using.

If you want to do it another way feel free and I’ll bow out because I don’t use any other method so can;t help you if you really don;t want this answer.

Thanks for the help so far
I tried what you quoted but I can’t get an output.Rhasspy’s TTS is working just fine so the problem is the nodes.
This is my flow if you can check it out.

[
    {
        "id": "fbc537f0d8d457b3",
        "type": "tab",
        "label": "Flow 3",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "7e2ae4fc57e82f43",
        "type": "websocket in",
        "z": "fbc537f0d8d457b3",
        "name": "rhasspy",
        "server": "63453288.fa038c",
        "client": "",
        "x": 350,
        "y": 180,
        "wires": [
            [
                "9de65e40438b9d0a"
            ]
        ]
    },
    {
        "id": "9de65e40438b9d0a",
        "type": "switch",
        "z": "fbc537f0d8d457b3",
        "name": "intent filter",
        "property": "intent.name",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "GetTemp",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 550,
        "y": 180,
        "wires": [
            [
                "bcf9a779c96497aa"
            ]
        ]
    },
    {
        "id": "bcf9a779c96497aa",
        "type": "function",
        "z": "fbc537f0d8d457b3",
        "name": "temp text",
        "func": "msg.payload = {siteId: \"e357767531799d51\", text: \"The temperature is \" + payload.SI7021.temperature};\n\nmsg.topic = \"hermes/tts/say\";\nmsg.text = msg.payload;\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 760,
        "y": 180,
        "wires": [
            [
                "3468280855aa57c1"
            ]
        ]
    },
    {
        "id": "3468280855aa57c1",
        "type": "mqtt out",
        "z": "fbc537f0d8d457b3",
        "name": "",
        "topic": "tts",
        "qos": "",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "403eda9f.2bcee4",
        "x": 950,
        "y": 180,
        "wires": []
    },
    {
        "id": "8f93cd996d6d2d3f",
        "type": "websocket in",
        "z": "fbc537f0d8d457b3",
        "name": "",
        "server": "",
        "client": "64fe785b.cea468",
        "x": 441,
        "y": 319,
        "wires": [
            [
                "3ead7ff3882bf296"
            ]
        ]
    },
    {
        "id": "3ead7ff3882bf296",
        "type": "debug",
        "z": "fbc537f0d8d457b3",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 670,
        "y": 400,
        "wires": []
    },
    {
        "id": "63453288.fa038c",
        "type": "websocket-listener",
        "path": "ws://192.168.1.12:12101/api/events/intent",
        "wholemsg": "true"
    },
    {
        "id": "403eda9f.2bcee4",
        "type": "mqtt-broker",
        "name": "Home thesis",
        "broker": "192.168.1.12",
        "port": "1883",
        "clientid": "node-red",
        "autoConnect": true,
        "usetls": false,
        "compatmode": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "sessionExpiry": ""
    },
    {
        "id": "64fe785b.cea468",
        "type": "websocket-client",
        "path": "ws://192.168.1.12:12101/api/events/intent",
        "tls": "",
        "wholemsg": "false",
        "hb": "0",
        "subprotocol": ""
    }
]

I suggest reading the Wiki, specifically the Node Red part:

I will also check it I can fix your flow.

Is there a specific reason you use the websocket?

OK, I had a look and in the function there is a reference to payload.SI7021.temperature which I just took from your original example but this is not defined anywhere in the function so when you use it node red should be throwing an exception which would send a message to the error log and the function would just fail out without completing.
You need to initialise this value some how from your sensor.

Also, I have no idea why you added the msg.text = msg.payload line, I don’t thing this will do anything, certainly sending this to the mqtt node will not as that node just publishes the msg.payload message to the msg.topic topic. The text is in one of the fields in the msg.payload object defined on the first line.

msg.payload = {siteId: siteid, text: "The temperature is " + str(payload.SI7021.temperature)};

could help

Greetings, Jens

only if payload is intialised from the sensor, it is not an issue with the type but rather that the value as a whole is undefined and undefined can;t be cast to a string

https://www.oreilly.com/library/view/python-cookbook/0596001673/ch17s02.html

Is this reference in the correct thread?
nodered uses javascript not python.

Also, I’m not sure what this reference is for but I couldn’t see how that reference helps initialise the temperature from the sensor to include in the text that is required for TTS or how referencing a member within an undefined reference rather than an object is anything other than an unhandled exception in a nodered function.

In the example provided the payload object was obviously containing a specific reference to another object SI7021 which seems to refer to a tasmota device and the temperature attribute is then read from that but nowhere in this function is payload initialised, so it would be undefined and cause the function to fail when trying to reference SI7021, it wouldn’t even get as far as the temperature attribute

sorry for the wrong link

Thinking about it I may not be being clear and there may be some incorrect assumptions being made.

The payload.SI7021.temperature value in the example is NOT referring to msg.payload.SI7021.temperature.

In addition msg is the object received from the websocket input from rhasspy so is just the object that identifies the intent as GetTemp.

For this to work the temperature needs to be read from somewhere and put into the text, where this comes from is not made clear anywhere in the information provided by the OP and so I have just been calling out that without it this whole thing will fail.

I mis-spoke when I said undefined can’t be cast, I should have more correctly stated that trying to defererence on object member within undefined cannot be done and will cause an exception and the function to fail.