onokje / node-red-contrib-tesla

Node red nodes to control Tesla vehicles and devices
MIT License
21 stars 11 forks source link

Home position #5

Closed denisjoshua closed 3 years ago

denisjoshua commented 4 years ago

Hi there, and first of all thanks a lot for this greate node. I use it a lot for automation of charge batt. from my PV system.

One of think I need is to know when my Tesla M3 is at home, is there possibility to know it please ?

Thanks a lot again

denisjoshua commented 4 years ago

In the mean time, I make a function that retreive the Lat and Lon GPS position using the "vehicleData" node, and I rounded to 3 decimals in order to have about 111 mt radius position.

// func. that retrive if the M3 is at home position or not 
var M3IsHome    = global.get('M3IsHome')    || 'false';
var M3Lat       = global.get('M3Lat')       || 0;
var M3Lon       = global.get('M3Lon')       || 0;

// receive vars from Tesla Api ///////////
M3Lat =  msg.payload.drive_state.latitude.toFixed(3);
M3Lon =  msg.payload.drive_state.longitude.toFixed(3);

// lat and lon is rounded to 3 decimal (3-th decimal in GPS is 111 mt radius)
if (M3Lat==xx.xxx || M3Lon==xx.xxx){
    global.set('M3IsHome','true');
    }
else {
    global.set('M3IsHome','false');
    }

global.set('M3Lat',M3Lat);
global.set('M3Lon',M3Lon);

Maybe can be useful for anyone. Denis

onokje commented 4 years ago

Yep, the gps coords are the way to go. The Tesla api does not have a build-in function to tell you if it's home or not, but the code above should do the trick just fine.

denisjoshua commented 4 years ago

Yes it's work :-) Thanks a lot for confirmation. Denis