# Tesla Location & node-red-node-geofence

**URL:** <https://discourse.nodered.org/t/tesla-location-node-red-node-geofence/45521>\
**Category:** General\
**Created:** [12 May 2021 01:16 UTC](https://discourse.nodered.org/t/tesla-location-node-red-node-geofence/45521 "2021-05-12T01:16:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nowjon](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nowjon/32/41622_2.png) [@nowjon](https://discourse.nodered.org/u/nowjon)\
**Post date:** [12 May 2021 01:16 UTC](https://discourse.nodered.org/t/tesla-location-node-red-node-geofence/45521/1 "2021-05-12T01:16:30Z")

</div>

Heyo, not sure how to get the correct formatting from the node-red-contrib-tesla to node-red-node-geofence.

Here's the output of the node-red-contrib-tesla driveState command:

```auto
{"_msgid":"15f2c9c.3bb0a36","payload":{"gps_as_of":1620781503,"heading":94,"latitude":xxxx,"longitude":-xxxx,"native_latitude":xxxx,"native_location_supported":1,"native_longitude":-xxxx,"native_type":"wgs","power":0,"shift_state":null,"speed":null,"timestamp":1620781574744},"topic":""}

```

I believe the payload.latitude & payload.longitude need to be msg.location.lat & msg.location.lon so I put the below into a change rule but that doesn't seem to have done anything.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/0/b077b14eb40e2ec553dd1b0e0c37120ff9bc660e.png)

Here's the output of the change rule:

```auto
{"_msgid":"15f2c9c.3bb0a36","payload":{"gps_as_of":1620781503,"heading":94,"latitude":xxxx,"longitude":-xxxx,"native_latitude":xxxx,"native_location_supported":1,"native_longitude":-xxxx,"native_type":"wgs","power":0,"shift_state":null,"speed":null,"timestamp":1620781574744},"topic":""}

```

I'm quite new to using Node-RED and not good with any type of JSON so was hoping someone here could help.

Thanks!

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [12 May 2021 05:48 UTC](https://discourse.nodered.org/t/tesla-location-node-red-node-geofence/45521/2 "2021-05-12T05:48:52Z")

</div>

You have the arguments wrong way round in the change node.  
you should read it as set msg.something to _the value of_ something.

You might also need to set `msg.location` to JSON `{}` first (first row of change node) to initialise the location as an object before setting the lat & lon.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [12 May 2021 06:11 UTC](https://discourse.nodered.org/t/tesla-location-node-red-node-geofence/45521/3 "2021-05-12T06:11:05Z")

</div>

Or change the set to move

---

<div class="post-metadata">

**Author:** ![nowjon](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nowjon/32/41622_2.png) [@nowjon](https://discourse.nodered.org/u/nowjon)\
**Post date:** [12 May 2021 14:43 UTC](https://discourse.nodered.org/t/tesla-location-node-red-node-geofence/45521/4 "2021-05-12T14:43:14Z")

</div>

I appreciate the help, I made the below change and it worked!

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/f/5fcdb8be68a49a560cac93565ed2b12c8e2b02fb.png)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [26 May 2021 14:43 UTC](https://discourse.nodered.org/t/tesla-location-node-red-node-geofence/45521/5 "2021-05-26T14:43:19Z")

</div>

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