Skip to content

Instantly share code, notes, and snippets.

@zachowj
Last active December 3, 2018 02:49
Show Gist options
  • Save zachowj/e538e606939ca36795f41655029de780 to your computer and use it in GitHub Desktop.
Save zachowj/e538e606939ca36795f41655029de780 to your computer and use it in GitHub Desktop.
@thefuzz4Today at 11:04 AM I'm trying to check to see if my not_home time is greater than 5 mins since sometimes google makrs me as away and then right back at home. I wrote this java_script but its my first java_script so I am just curious if someone can take a look at my syntax to make sure it will do what I want it to do. Oh it also basicall…
const old_date = Date(msg.data.new_state.last_updated);
const new_date = Date(msg.data.old_state.last_updated);
const new_state = msg.data.new_state.state;
const old_state = msg.data.old_state.state;
const seconds = (new_date - old_date) / 1000;
if (new_state != old_state) {
if (seconds > 300) {
msg.payload = { data: { 'entity_id': 'device_tracker.google_maps_id', 'state': 'home' } };
return msg;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment