Exporting temperature reading to alexa

hello
im new hope i have done this right
i have managed to setup all my sonoff devices and have alexa working switching though mqtt
i can get the reading of the function template (alexa get temp) through alexa but i need to have my water temp reading in the (alexa get temp) which is just an decimal number spent days now trying to figure this out

please help

thanks chris

updated full flow

[{"id":"925223d0.4e5d","type":"alexa-home","z":"4306a747.448678","conf":"447d833e.732eec","device":"29580","acknoledge":true,"name":"Hot Tub Heater","topic":"","x":140,"y":200,"wires":[["fe975c72.3828","7e4680da.39bb48"]]},{"id":"2815a67a.e8ecca","type":"ui_switch","z":"4306a747.448678","name":"","label":"Hot Tub Heater","group":"a34fc89.b38da38","order":1,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"ON","onvalueType":"str","onicon":"","oncolor":"","offvalue":"OFF","offvalueType":"str","officon":"","offcolor":"","x":700,"y":200,"wires":[["df93b7e6.5f4ac8"]],"inputLabels":["1"],"outputLabels":["1"]},{"id":"df93b7e6.5f4ac8","type":"mqtt out","z":"4306a747.448678","name":"","topic":"cmnd/myhome/garden/hottub/heater/POWER","qos":"1","retain":"","broker":"d6784aa7.f43c48","x":1090,"y":200,"wires":[]},{"id":"fe975c72.3828","type":"change","z":"4306a747.448678","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"true","fromt":"bool","to":"ON","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"false","fromt":"bool","to":"OFF","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":200,"wires":[["2815a67a.e8ecca"]],"inputLabels":["1"],"outputLabels":["1"]},{"id":"7c05d14b.ba88d","type":"debug","z":"4306a747.448678","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":630,"y":460,"wires":[]},{"id":"711db560.299ffc","type":"alexa-home-resp","z":"4306a747.448678","x":1000,"y":300,"wires":[]},{"id":"dd0661b5.d8f4c","type":"mqtt in","z":"4306a747.448678","name":"hot tub heater","topic":"tele/myhome/garden/hottub/heater/SENSOR","qos":"1","broker":"d6784aa7.f43c48","x":190,"y":300,"wires":[["ccd0a96c.69c018"]]},{"id":"85fdaa36.b79188","type":"function","z":"4306a747.448678","name":"Water temp","func":"var temp=msg.payload.DS18B20.Temperature;\n\nvar msg = {\n payload:temp\n};\n\nreturn msg;","outputs":1,"noerr":0,"x":530,"y":300,"wires":[["630d7ac4.bd9cdc"]]},{"id":"ccd0a96c.69c018","type":"json","z":"4306a747.448678","name":"","pretty":false,"x":370,"y":300,"wires":[["85fdaa36.b79188"]]},{"id":"7e4680da.39bb48","type":"function","z":"4306a747.448678","name":"Alexa Get temp","func":"msg.extra = {\"temperatureReading\": { \"value\": 21.1 }, \"applianceResponseTimestamp\":new Date().toISOString()};\nmsg.payload = true;\nreturn msg; ","outputs":1,"noerr":0,"x":520,"y":380,"wires":[["630d7ac4.bd9cdc"]]},{"id":"630d7ac4.bd9cdc","type":"change","z":"4306a747.448678","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"21.1","fromt":"msg","to":"payload:temp","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":340,"wires":[["711db560.299ffc","7c05d14b.ba88d"]],"inputLabels":["2"],"outputLabels":["1"]},{"id":"447d833e.732eec","type":"alexa-home-conf","z":"","username":"homemedia20"},{"id":"a34fc89.b38da38","type":"ui_group","z":"","name":"Hot Tub","tab":"1cff5057.d9bf6","order":1,"disp":true,"width":"6","collapse":false},{"id":"d6784aa7.f43c48","type":"mqtt-broker","z":"","name":"Local","broker":"127.0.0.1","port":"1883","tls":"","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"1cff5057.d9bf6","type":"ui_tab","z":"","name":"Hot Tub","icon":"dashboard","order":1}]

Not quite. In order that your flow is importable please edit your post (click on the pen icon at the bottom) and insert a line containing three backtick characters before the flow and another line containing three backtick characters after the flow. That will tell the forum software not to do any reformatting of it.
Post a reply when you have done that so we know to have another look.

Attach a debug node to the output of the JSON node and set it to display the complete msg object. Then run it and show us the output.

I had to do some tweeking to the flow to get it to import and I notice the input to the 'Alexa Get temp' functon node has nothing attached to it. This means it will never run.

Here is the version I tweeked to get it to import:

[{"id":"1200fbb4.d25714","type":"mqtt in","z":"e2c5a9d1.10881","name":"hot tub heater","topic":"tele/myhome/garden/hottub/heater/SENSOR","qos":"1","broker":"954b508b.c998f8","x":130,"y":160,"wires":[["6bafd509.ae6f14"]]},{"id":"e5a207aa.30a93","type":"function","z":"e2c5a9d1.10881","name":"Water temp","func":"var temp=msg.payload.DS18B20.Temperature;\n\nvar msg = {\n payload:temp\n};\n\nreturn msg;","outputs":1,"noerr":0,"x":470,"y":100,"wires":[["a030a522.f39b28"]]},{"id":"6bafd509.ae6f14","type":"json","z":"e2c5a9d1.10881","name":"","pretty":false,"x":310,"y":100,"wires":[["e5a207aa.30a93"]]},{"id":"221d5257.46c94e","type":"function","z":"e2c5a9d1.10881","name":"Alexa Get temp","func":"msg.extra = {\"temperatureReading\": { \"value\": 21.1 }, \"applianceResponseTimestamp\":new Date().toISOString()};\nmsg.payload = true;\nreturn msg; ","outputs":1,"noerr":0,"x":460,"y":180,"wires":[["a030a522.f39b28"]]},{"id":"a030a522.f39b28","type":"change","z":"e2c5a9d1.10881","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"21.1","fromt":"msg","to":"payload:temp","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":140,"wires":[[]],"inputLabels":["2"]},{"id":"954b508b.c998f8","type":"mqtt-broker","z":"","name":"Local","broker":"127.0.0.1","port":"1883","tls":"","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

Jason

20/08/2018, 19:24:52node: 8a900942.7d16f8
tele/myhome/garden/hottub/heater/SENSOR : msg : Object
object
topic: "tele/myhome/garden/hottub/heater/SENSOR"
payload: object
Time: "2018-08-20T19:24:52"
DS18B20: object
Temperature: 24.9
TempUnit: "C"
qos: 0
retain: false
_topic: "tele/myhome/garden/hottub/heater/SENSOR"
_msgid: "6c36888.7251e78"

As I said above, I notice the input to the 'Alexa Get temp' functon node has nothing attached to it.

How do you expect it to run?

Copying the html shown in the debug sidebar loses the JSON structure, and so can be misleading. Instead, use the little "Copy Value" button that shows up to the right of the msg object to put the actual JSON string onto the clipboard.

Then, in your post here, paste the clipboard between two lines that contain only 3 backtics (e.g. ```) so that the data is formatted properly, like so:

{"_msgid":"5c539a85.5da864","topic":"","payload":"2018-06-01T18:13:03.909192+00:00","datetime":"2018-06-19T18:13:03.909Z"}

i have updated the full flow including the run trigger from alexa

here you go thankyou sorry i have been working late an was unable to get on site to reply

{"topic":"tele/myhome/garden/hottub/heater/SENSOR","payload":{"Time":"2018-08-26T09:52:36","DS18B20":{"Temperature":20.1},"TempUnit":"C"},"qos":0,"retain":false,"_topic":"tele/myhome/garden/hottub/heater/SENSOR","_msgid":"c2ee1a1.3a983e8"}

Are you using two different ALEXA nodes?
If so, what are they?

alexa device input and alexa response

Let me ask it another way, what are the full names of the alexa nodes you have installed
i.e. node-red-contrib-?????

Thanks for the JSON -- when it's formatted with newlines and indentation, the structure becomes much clearer:

{
    "topic": "tele/myhome/garden/hottub/heater/SENSOR",
    "payload": {
        "Time": "2018-08-26T09:52:36",
        "DS18B20": {
            "Temperature": 20.1
        },
        "TempUnit": "C"
    },
    "qos": 0,
    "retain": false,
    "_topic": "tele/myhome/garden/hottub/heater/SENSOR",
    "_msgid": "c2ee1a1.3a983e8"
}

So the "payload" object contains 3 properties -- "Time" and "TempUnit" (which are strings) and "DS12B20" (which is an object). This object contains a single property "Temperature" which holds the numeric value 20.1

If this is the value you want to use in your dashboard, the syntax would be:
msg.payload.DS12B20.Temperature

Whenever a property name contains punctuation or white space, this "dotted" notation would have to be written as:
msg.payload['BS12-B20']['Temperature in F'] for instance.

In case you did not see it, next to the "Copy Value" button in the debug sidebar, there is a "Copy Value" button (looks like >) -- that puts the "path" to the value you want onto the clipboard, relative to last component of whatever object is defined in the debug node. So if your debug node was setup to show msg.payload, the copied path would be payload.BS12B20.Temperature

ok now i have
"ReferenceError: payload is not defined (line 3, col 18)"

msg.extra = {
    "temperatureReading": {
        "value": payload.DS18B20.Temperature
        },
    "applianceResponseTimestamp": new Date().toISOString()
};
msg.payload = true;
return msg; 

saw my mistake msg. ok ha have that working and the reading is in the debug window but now when i ask alexa it shows
TypeError: Cannot read property 'DS18B20' of undefined
and alexa says sorry i dont know that one but before it would reply the 21.1 what was in the value does this need to be saved for it to read or?

You forgot the msg. prefix ;*)

FYI, is you simply need to restructure one msg payload to another object, you can use a change node, set to use the JSONata expression shown here:

image

here is the flow I used to test it...

[{"id":"4bf06108.69d2e","type":"inject","z":"9cd675b0.a84be8","name":"","topic":"tele/myhome/garden/hottub/heater/SENSOR","payload":"{\"Time\":\"2018-08-26T09:52:36\",\"DS18B20\":{\"Temperature\":20.1},\"TempUnit\":\"C\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":1080,"wires":[["bad14c5e.5fd6e"]]},{"id":"baf4b2fd.a4603","type":"debug","z":"9cd675b0.a84be8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":510,"y":1080,"wires":[]},{"id":"bad14c5e.5fd6e","type":"change","z":"9cd675b0.a84be8","name":"","rules":[{"t":"set","p":"extra","pt":"msg","to":"{\t   \"temperatureReading\": {\t       \"value\": $$.payload.DS18B20.Temperature         \t   },\t   \"applianceResponseTimestamp\": $now()     \t}","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":1080,"wires":[["baf4b2fd.a4603"]]}]

thankyou for you time but it didnt work i have just realised the alexa sends this out

object
topic: ""
name: "Hot Tub Heater"
_messageId: "55c35f17-62cb-4e4e-b82f-42b4405b2877"
_applianceId: "29580"
_confId: "447d833e.732eec"
command: "GetTemperatureReadingRequest"
extraInfo: object
empty
_msgid: "d27f72c9.dfefd"
extra: object
temperatureReading: object
value: 21.1
applianceResponseTimestamp: "2018-08-27T17:09:03.329Z"
payload: true

what we have done is insert the value but alexa doesnt recognise it still our debug msg is after the input from alexa

27/08/2018, 18:09:04node: b311dbbf.ac73f8
msg : Object
object
topic: ""
name: "Hot Tub Heater"
_messageId: "55c35f17-62cb-4e4e-b82f-42b4405b2877"
_applianceId: "29580"
_confId: "447d833e.732eec"
command: "GetTemperatureReadingRequest"
extraInfo: object
empty
_msgid: "d27f72c9.dfefd"
extra: object
temperatureReading: object
empty
applianceResponseTimestamp: "2018-08-27T17:09:03.334Z"
payload: true

but our message after the mqtt input is

27/08/2018, 18:28:17node: b311dbbf.ac73f8
tele/myhome/garden/hottub/heater/SENSOR : msg : Object
object
topic: "tele/myhome/garden/hottub/heater/SENSOR"
payload: true
qos: 0
retain: false
_topic: "tele/myhome/garden/hottub/heater/SENSOR"
_msgid: "8c5acf6f.0c912"
extra: object
temperatureReading: object
value: 21.1
applianceResponseTimestamp: "2018-08-27T17:28:16.410Z"

how would u do this sorry i have wasted you time :confused:

Hello Chris

Would you please share you flow, I would like to make a similar question to alexa

Thank you
JLG

1 Like