# Exporting temperature reading to alexa

**URL:** <https://discourse.nodered.org/t/exporting-temperature-reading-to-alexa/2412>\
**Category:** General\
**Created:** [20 August 2018 01:04 UTC](https://discourse.nodered.org/t/exporting-temperature-reading-to-alexa/2412 "2018-08-20T01:04:37Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![chris1988](https://avatars.discourse-cdn.com/v4/letter/c/45deac/32.png) [@chris1988](https://discourse.nodered.org/u/chris1988)\
**Post date:** [20 August 2018 01:04 UTC](https://discourse.nodered.org/t/exporting-temperature-reading-to-alexa/2412/1 "2018-08-20T01:04:37Z")

</div>

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

```auto
[{"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}]

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [20 August 2018 07:43 UTC](https://discourse.nodered.org/t/exporting-temperature-reading-to-alexa/2412/2 "2018-08-20T07:43:42Z")

</div>

> [@chris1988](#):
>
> im new hope i have done this right

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.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [20 August 2018 11:09 UTC](https://discourse.nodered.org/t/exporting-temperature-reading-to-alexa/2412/3 "2018-08-20T11:09:38Z")

</div>

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:

```auto
[{"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":""}]

```

---

<div class="post-metadata">

**Author:** ![chris1988](https://avatars.discourse-cdn.com/v4/letter/c/45deac/32.png) [@chris1988](https://discourse.nodered.org/u/chris1988)\
**Post date:** [20 August 2018 19:38 UTC](https://discourse.nodered.org/t/exporting-temperature-reading-to-alexa/2412/4 "2018-08-20T19:38:29Z")

</div>

Jason

```auto
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"

```

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [20 August 2018 21:06 UTC](https://discourse.nodered.org/t/exporting-temperature-reading-to-alexa/2412/5 "2018-08-20T21:06:14Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [20 August 2018 21:15 UTC](https://discourse.nodered.org/t/exporting-temperature-reading-to-alexa/2412/6 "2018-08-20T21:15:33Z")

</div>

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:

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

```

---

<div class="post-metadata">

**Author:** ![chris1988](https://avatars.discourse-cdn.com/v4/letter/c/45deac/32.png) [@chris1988](https://discourse.nodered.org/u/chris1988)\
**Post date:** [26 August 2018 08:53 UTC](https://discourse.nodered.org/t/exporting-temperature-reading-to-alexa/2412/7 "2018-08-26T08:53:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![chris1988](https://avatars.discourse-cdn.com/v4/letter/c/45deac/32.png) [@chris1988](https://discourse.nodered.org/u/chris1988)\
**Post date:** [26 August 2018 08:55 UTC](https://discourse.nodered.org/t/exporting-temperature-reading-to-alexa/2412/8 "2018-08-26T08:55:13Z")

</div>

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

```auto
{"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"}

```

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [26 August 2018 10:13 UTC](https://discourse.nodered.org/t/exporting-temperature-reading-to-alexa/2412/9 "2018-08-26T10:13:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![chris1988](https://avatars.discourse-cdn.com/v4/letter/c/45deac/32.png) [@chris1988](https://discourse.nodered.org/u/chris1988)\
**Post date:** [26 August 2018 19:57 UTC](https://discourse.nodered.org/t/exporting-temperature-reading-to-alexa/2412/10 "2018-08-26T19:57:44Z")

</div>

alexa device input and alexa response

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [26 August 2018 20:08 UTC](https://discourse.nodered.org/t/exporting-temperature-reading-to-alexa/2412/11 "2018-08-26T20:08:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [27 August 2018 13:48 UTC](https://discourse.nodered.org/t/exporting-temperature-reading-to-alexa/2412/12 "2018-08-27T13:48:14Z")

</div>

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

```auto
{
    "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`

---

<div class="post-metadata">

**Author:** ![chris1988](https://avatars.discourse-cdn.com/v4/letter/c/45deac/32.png) [@chris1988](https://discourse.nodered.org/u/chris1988)\
**Post date:** [27 August 2018 15:03 UTC](https://discourse.nodered.org/t/exporting-temperature-reading-to-alexa/2412/13 "2018-08-27T15:03:48Z")

</div>

> [@shrickus](#):
>
> msg.payload['BS12-B20']['Temperature in F']

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

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

```

---

<div class="post-metadata">

**Author:** ![chris1988](https://avatars.discourse-cdn.com/v4/letter/c/45deac/32.png) [@chris1988](https://discourse.nodered.org/u/chris1988)\
**Post date:** [27 August 2018 15:22 UTC](https://discourse.nodered.org/t/exporting-temperature-reading-to-alexa/2412/14 "2018-08-27T15:22:01Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [27 August 2018 15:35 UTC](https://discourse.nodered.org/t/exporting-temperature-reading-to-alexa/2412/15 "2018-08-27T15:35:37Z")

</div>

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/6e891e24b5215bd8da8e686b1fb39802fd324fe2.png)

_here is the flow I used to test it..._

```auto
[{"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"]]}]

```

---

<div class="post-metadata">

**Author:** ![chris1988](https://avatars.discourse-cdn.com/v4/letter/c/45deac/32.png) [@chris1988](https://discourse.nodered.org/u/chris1988)\
**Post date:** [27 August 2018 17:31 UTC](https://discourse.nodered.org/t/exporting-temperature-reading-to-alexa/2412/16 "2018-08-27T17:31:25Z")

</div>

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

```auto
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

```auto
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

```auto
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 😕

---

<div class="post-metadata">

**Author:** ![JoseGodinho](https://avatars.discourse-cdn.com/v4/letter/j/f4b2a3/32.png) [@JoseGodinho](https://discourse.nodered.org/u/JoseGodinho)\
**Post date:** [5 July 2019 09:13 UTC](https://discourse.nodered.org/t/exporting-temperature-reading-to-alexa/2412/17 "2019-07-05T09:13:06Z")

</div>

Hello Chris

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

Thank you  
JLG
