Trying to get Alexa to read out a temperature

Hi Sean
That flow you posted back very nearly works. In its raw state, when I run your flow Alexa says "the temperature is undefined". If I replace the + flow.temperature in the function node with a string "22" for example, Alexa reads the message ok. So it seem like Alexa need a string and not a numerical value to report back. I've just been trying (unsuccessfully) to change the stored flow.temperature variable into a string by using ghayne's suggestion of $string(payload) but I must be putting it in the wrong place or not getting the format quite right. Any pointers?

Here's an example of converting a numeric to a string.
let text_string = some_numeric_variable.toString();

Then use text_string as part of the message that goes to Alexa.

You could try...
msg.payload.toString()
... to convert a number to a string.

Can you post your latest flow?

Here's my flow Dave, it's basically what Sean posted with a few debug node to try to see whats happening:

[{"id":"d72fe351b906a44a","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"bb2203207cd8d41c","type":"alexa-remote-event","z":"d72fe351b906a44a","name":"","account":"f5c58b4876dbd6b3","event":"ws-device-activity","x":150,"y":180,"wires":[["512be1dd0973b722"]]},{"id":"beb19f6fdbe0b9c2","type":"mqtt in","z":"d72fe351b906a44a","name":"Room temp","topic":"tele/garage/SENSOR","qos":"2","datatype":"json","broker":"22f544be.780a3c","nl":false,"rap":false,"inputs":0,"x":150,"y":120,"wires":[["af849fa78b1684d6"]]},{"id":"512be1dd0973b722","type":"switch","z":"d72fe351b906a44a","name":"Filter","property":"payload.alexaResponse","propertyType":"msg","rules":[{"t":"cont","v":"temperature is","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":350,"y":180,"wires":[["5dd120da56d3b69b","53acd8558beb7b80"]]},{"id":"5932608ff00cdf22","type":"alexa-remote-routine","z":"d72fe351b906a44a","name":"","account":"f5c58b4876dbd6b3","routineNode":{"type":"speak","payload":{"type":"announcement","text":{"type":"msg","value":"payload"},"devices":["G090LF1173660KCR"]}},"x":860,"y":180,"wires":[[]]},{"id":"af849fa78b1684d6","type":"change","z":"d72fe351b906a44a","name":"store value","rules":[{"t":"set","p":"Temperature","pt":"flow","to":"payload.SI7021.Temperature","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":120,"wires":[["41b615e8d1091d31"]]},{"id":"53acd8558beb7b80","type":"function","z":"d72fe351b906a44a","name":"","func":"msg.payload = \"The temperature is\" + flow.temperature\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":180,"wires":[["3272c44211778873","5932608ff00cdf22","f655a95a1eed2b4e"]]},{"id":"3272c44211778873","type":"debug","z":"d72fe351b906a44a","name":"6","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":750,"y":120,"wires":[]},{"id":"5dd120da56d3b69b","type":"debug","z":"d72fe351b906a44a","name":"7","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":470,"y":260,"wires":[]},{"id":"41b615e8d1091d31","type":"debug","z":"d72fe351b906a44a","name":"9","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":510,"y":60,"wires":[]},{"id":"f655a95a1eed2b4e","type":"debug","z":"d72fe351b906a44a","name":"11","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":840,"y":260,"wires":[]},{"id":"f5c58b4876dbd6b3","type":"alexa-remote-account","name":"opt","authMethod":"proxy","proxyOwnIp":"192.168.1.147","proxyPort":"3456","cookieFile":"authFile","refreshInterval":"3","alexaServiceHost":"alexa.amazon.co.uk","amazonPage":"amazon.co.uk","acceptLanguage":"en-UK","onKeywordInLanguage":"on","userAgent":"","useWsMqtt":"on","autoInit":"on"},{"id":"22f544be.780a3c","type":"mqtt-broker","name":"Mosquitto","broker":"192.168.1.147","port":"1883","clientid":"","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":""}]

And here's a screen grab with the debug node information:

Your flow variables aren't the same. One has a capital the other hasn't.
I'm not near my computer so can't check if this is the issue/problem.
Could you try making them the same 'case' ?
Screen Shot 01-27-22 at 01.05 PM 001
Screen Shot 01-27-22 at 01.05 PM

[quote="

You could try...
msg.payload.toString()
... to convert a number to a string.

[/quote]

Would that go in the function node or the change node called "store value" Dave, and if so how could I incorporate it?

Yes Dave I did notice that earlier and corrected it but the flow I posted had different capitalisation for some reason. Anyway I just changed them all to capitals and it's still the same unfortunately. It has caught me out in the past the old capitalisation error.

Here's the flow with caps the same:

[{"id":"d72fe351b906a44a","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"bb2203207cd8d41c","type":"alexa-remote-event","z":"d72fe351b906a44a","name":"","account":"f5c58b4876dbd6b3","event":"ws-device-activity","x":150,"y":180,"wires":[["512be1dd0973b722"]]},{"id":"beb19f6fdbe0b9c2","type":"mqtt in","z":"d72fe351b906a44a","name":"Room temp","topic":"tele/garage/SENSOR","qos":"2","datatype":"json","broker":"22f544be.780a3c","nl":false,"rap":false,"inputs":0,"x":150,"y":120,"wires":[["af849fa78b1684d6","3272c44211778873"]]},{"id":"512be1dd0973b722","type":"switch","z":"d72fe351b906a44a","name":"Filter","property":"payload.alexaResponse","propertyType":"msg","rules":[{"t":"cont","v":"temperature is","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":350,"y":180,"wires":[["5dd120da56d3b69b","53acd8558beb7b80"]]},{"id":"5932608ff00cdf22","type":"alexa-remote-routine","z":"d72fe351b906a44a","name":"","account":"f5c58b4876dbd6b3","routineNode":{"type":"speak","payload":{"type":"announcement","text":{"type":"msg","value":"payload"},"devices":["G090LF1173660KCR"]}},"x":860,"y":180,"wires":[[]]},{"id":"af849fa78b1684d6","type":"change","z":"d72fe351b906a44a","name":"store value","rules":[{"t":"set","p":"Temperature","pt":"flow","to":"payload.SI7021.Temperature","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":120,"wires":[["41b615e8d1091d31"]]},{"id":"53acd8558beb7b80","type":"function","z":"d72fe351b906a44a","name":"","func":"msg.payload = \"The temperature is\" + flow.Temperature\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":180,"wires":[["5932608ff00cdf22","f655a95a1eed2b4e"]]},{"id":"3272c44211778873","type":"debug","z":"d72fe351b906a44a","name":"6","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":310,"y":40,"wires":[]},{"id":"5dd120da56d3b69b","type":"debug","z":"d72fe351b906a44a","name":"7","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":470,"y":260,"wires":[]},{"id":"41b615e8d1091d31","type":"debug","z":"d72fe351b906a44a","name":"9","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":510,"y":60,"wires":[]},{"id":"f655a95a1eed2b4e","type":"debug","z":"d72fe351b906a44a","name":"11","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":840,"y":260,"wires":[]},{"id":"f5c58b4876dbd6b3","type":"alexa-remote-account","name":"opt","authMethod":"proxy","proxyOwnIp":"192.168.1.147","proxyPort":"3456","cookieFile":"authFile","refreshInterval":"3","alexaServiceHost":"alexa.amazon.co.uk","amazonPage":"amazon.co.uk","acceptLanguage":"en-UK","onKeywordInLanguage":"on","userAgent":"","useWsMqtt":"on","autoInit":"on"},{"id":"22f544be.780a3c","type":"mqtt-broker","name":"Mosquitto","broker":"192.168.1.147","port":"1883","clientid":"","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":""}]

I've re-written part of the flow. Try this and see if it works...

[{"id":"fdedac607f20a384","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"d9cef3911a340322","type":"alexa-remote-event","z":"fdedac607f20a384","name":"","account":"f5c58b4876dbd6b3","event":"ws-device-activity","x":170,"y":280,"wires":[["d9dd3578e3584bfa"]]},{"id":"c596f864e8ddf6d2","type":"mqtt in","z":"fdedac607f20a384","name":"Room temp","topic":"tele/garage/SENSOR","qos":"2","datatype":"json","broker":"22f544be.780a3c","nl":false,"rap":false,"inputs":0,"x":150,"y":120,"wires":[["23949a4c8a9421e3","48d81bc5f11542c5"]]},{"id":"d9dd3578e3584bfa","type":"switch","z":"fdedac607f20a384","name":"Filter","property":"payload.alexaResponse","propertyType":"msg","rules":[{"t":"cont","v":"temperature is","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":370,"y":280,"wires":[["fa4ad52f77a3a689","138e818ddc1d6dd3"]]},{"id":"64da3017d499a99a","type":"alexa-remote-routine","z":"fdedac607f20a384","name":"","account":"f5c58b4876dbd6b3","routineNode":{"type":"speak","payload":{"type":"announcement","text":{"type":"msg","value":"payload"},"devices":["G090LF1173660KCR"]}},"x":760,"y":280,"wires":[[]]},{"id":"138e818ddc1d6dd3","type":"function","z":"fdedac607f20a384","name":"","func":"let temperature = flow.get(\"temperature\") || 0;\ntemperature = temperature.toString();\n\nmsg.payload = \"The temperature is \" +temperature;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":540,"y":280,"wires":[["64da3017d499a99a","92381d845bdd0256"]]},{"id":"23949a4c8a9421e3","type":"debug","z":"fdedac607f20a384","name":"6","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":310,"y":40,"wires":[]},{"id":"fa4ad52f77a3a689","type":"debug","z":"fdedac607f20a384","name":"7","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":490,"y":360,"wires":[]},{"id":"bdf074cfd2a75ec3","type":"debug","z":"fdedac607f20a384","name":"9","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":630,"y":80,"wires":[]},{"id":"92381d845bdd0256","type":"debug","z":"fdedac607f20a384","name":"11","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":730,"y":360,"wires":[]},{"id":"48d81bc5f11542c5","type":"function","z":"fdedac607f20a384","name":"","func":"flow.set(\"temperature\",payload.SI7021.Temperature);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":340,"y":120,"wires":[[]]},{"id":"dd868057aab722b3","type":"function","z":"fdedac607f20a384","name":"Test setting temperature to 21","func":"flow.set(\"temperature\",msg.payload);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":410,"y":180,"wires":[[]]},{"id":"fcb0cd6fa3135761","type":"inject","z":"fdedac607f20a384","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"21","payloadType":"num","x":130,"y":180,"wires":[["dd868057aab722b3"]]},{"id":"0335514a2b601c42","type":"inject","z":"fdedac607f20a384","name":"Click to test the text sent to Alexa","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":410,"y":220,"wires":[["138e818ddc1d6dd3"]]},{"id":"f5c58b4876dbd6b3","type":"alexa-remote-account","name":"opt","authMethod":"proxy","proxyOwnIp":"192.168.1.147","proxyPort":"3456","cookieFile":"authFile","refreshInterval":"3","alexaServiceHost":"alexa.amazon.co.uk","amazonPage":"amazon.co.uk","acceptLanguage":"en-UK","userAgent":"","useWsMqtt":"on","autoInit":"on"},{"id":"22f544be.780a3c","type":"mqtt-broker","name":"Mosquitto","broker":"192.168.1.147","port":"1883","clientid":"","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":""}]

As I haven't got your MQTT input I'm using the top inject node to set the flow variable to numeric 21.
Clicking the lower inject node should send the text "The temperature is 21" to Alexa.

This does indeed work Dave when using the inject nodes. Alexa announces the values perfectly. However there is a reference error: payload is not defined associated with the top function node as can be seen here:

Your flow doesn't look the same as the one I posted.

Can you also expand the debug message for node 6 so I can see what the object looks like.
Screen Shot 01-27-22 at 01.56 PM

EDIT: Have a look at this thread by Steve as it explains how to find the path.

Let me double check

I've just imported your last posted flow again and expanded the debug node 6 as you asked.

Oops - sorry, typo in the top function node.
I missed msg. off of the first part of the path.
This is what it should look like...
Screen Shot 01-27-22 at 02.15 PM

That's got it Dave, brilliant mate, love you to bits, go get a nice cup of tea. Seriously though thanks for sticking with me on this. Now you've laid the ground work I can do the same for all of the temperature sensors I have around the house and garden.

I may come back soon with the next part of my project when I need to ask Alexa to change the set temperature for a given space, but that will be a while yet. I'll have a good go at it myself first though.

Thanks everyone for your input.

Glad to hear it is working for you.
You should be able to "crib" some of this to make your own dedicated message.
Have fun.

var hostname = flow.get("hostname");
var ip_address = flow.get("ip_address");
var cpu_temperature = flow.get("cpu_temperature");

var message = "<break time='0.25s'/> Here's your report on your raspberry pie<break time='0.5s'/>";
    
message += "hostname is <break time='0.1s'/>"+hostname+ "<break time='0.25s'/>";
message += "IP address is <break time='0.1s'/>"+ip_address+ "<break time='0.25s'/>";
message += "CPU core temperature is <break time='0.1s'/>"+cpu_temperature+ "degrees sea <break time='0.25s'/>";

// This the footer for the message
message += "<break time='0.75s'/> that's the end of the report";

msg.payload = message;
return msg;
1 Like

Ha Ha thats a whole other can of worms then :wink:

1 Like

Hi Des,
Just had a few spare minutes to extend your flow to include a personalised message for your Alexa device.
Hope this works for you? Please let me know how you get on with it.

[{"id":"fdedac607f20a384","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"d9cef3911a340322","type":"alexa-remote-event","z":"fdedac607f20a384","name":"","account":"f5c58b4876dbd6b3","event":"ws-device-activity","x":170,"y":280,"wires":[["d9dd3578e3584bfa"]]},{"id":"c596f864e8ddf6d2","type":"mqtt in","z":"fdedac607f20a384","name":"Room temp","topic":"tele/garage/SENSOR","qos":"2","datatype":"json","broker":"22f544be.780a3c","nl":false,"rap":false,"inputs":0,"x":150,"y":120,"wires":[["23949a4c8a9421e3","48d81bc5f11542c5"]]},{"id":"d9dd3578e3584bfa","type":"switch","z":"fdedac607f20a384","name":"Filter","property":"payload.alexaResponse","propertyType":"msg","rules":[{"t":"cont","v":"temperature is","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":370,"y":280,"wires":[["fa4ad52f77a3a689","138e818ddc1d6dd3"]]},{"id":"64da3017d499a99a","type":"alexa-remote-routine","z":"fdedac607f20a384","name":"","account":"f5c58b4876dbd6b3","routineNode":{"type":"speak","payload":{"type":"announcement","text":{"type":"msg","value":"payload"},"devices":["G090LF1173660KCR"]}},"x":980,"y":280,"wires":[[]]},{"id":"138e818ddc1d6dd3","type":"function","z":"fdedac607f20a384","name":"Read variable(s) and format message for Alexa","func":"// Get the flow variable(s) to be used in the message\nvar temperature = flow.get(\"temperature\") || 0;\n\n// Convert them to a string\ntemperature = temperature.toString();\n\n// Start building the message\nvar message = \"<break time='0.25s'/> Hi Des here's your report on your tasmota device<break time='0.5s'/>\";\n\nmessage += \"temperature of the unit is <break time='0.1s'/>\"+temperature+ \"degrees sea <break time='0.25s'/>\";\n\n// This the footer for the message\nmessage += \"<break time='0.75s'/> that's the end of the report\";\n\nmsg.payload = message;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":660,"y":280,"wires":[["64da3017d499a99a","92381d845bdd0256"]]},{"id":"23949a4c8a9421e3","type":"debug","z":"fdedac607f20a384","name":"6","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":130,"y":80,"wires":[]},{"id":"fa4ad52f77a3a689","type":"debug","z":"fdedac607f20a384","name":"7","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":370,"y":340,"wires":[]},{"id":"92381d845bdd0256","type":"debug","z":"fdedac607f20a384","name":"11","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":530,"y":340,"wires":[]},{"id":"48d81bc5f11542c5","type":"function","z":"fdedac607f20a384","name":"","func":"// Save the reading(s) in a flow variable\n\nflow.set(\"temperature\",msg.payload.SI7021.Temperature);\n\nreturn null;\n","outputs":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":340,"y":120,"wires":[]},{"id":"dd868057aab722b3","type":"function","z":"fdedac607f20a384","name":"Test setting temperature to 21","func":"flow.set(\"temperature\",msg.payload);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":410,"y":180,"wires":[[]]},{"id":"fcb0cd6fa3135761","type":"inject","z":"fdedac607f20a384","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"21","payloadType":"num","x":150,"y":180,"wires":[["dd868057aab722b3"]]},{"id":"0335514a2b601c42","type":"inject","z":"fdedac607f20a384","name":"Click to test the text sent to Alexa","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":230,"y":240,"wires":[["138e818ddc1d6dd3"]]},{"id":"f5c58b4876dbd6b3","type":"alexa-remote-account","name":"opt","authMethod":"proxy","proxyOwnIp":"192.168.1.147","proxyPort":"3456","cookieFile":"authFile","refreshInterval":"3","alexaServiceHost":"alexa.amazon.co.uk","amazonPage":"amazon.co.uk","acceptLanguage":"en-UK","userAgent":"","useWsMqtt":"on","autoInit":"on"},{"id":"22f544be.780a3c","type":"mqtt-broker","name":"Mosquitto","broker":"192.168.1.147","port":"1883","clientid":"","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":""}]
1 Like

I like that Dave, will have a play with it today. Thanks.

Slightly off topic, but during my experimentation with this whole topic of getting Alexa to announce my sensor temperatures, I have been using my raspberry Pi 4. My heating system runs on a Pi zero W2. My attempts at transferring everything from Pi4 to Pi zero have been unsuccessful so far. I'm sure it's something to do with blueprints accounts and MQTT and IP addresses. Also my pi 4 is on version V2.1.4 but my Pi zero is on V1.3.4. I had a bad experience upgrading my Pi 4 to V2.1.4 and it took me a while to get it working satisfactorily again. I'm a bit reluctant to upgrade the Pi zero just yet as it's doing a good job of running my heating system and the little lady will not be best pleased if the heating is off for too long. I may continue prototyping on the Pi 4 until the better weather arrives and it's not so critical to have the heating running. Thanks again for your help and everyone else who contributed.

2 posts were merged into an existing topic: How can I split a MQTT string

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.