How to track time since phone disconnected?

Former Member
Former Member

I am displaying temperature on a watch face, and after a while the temperature is inaccurate simply because my watch has not connected with my phone. I want to change the temperature reading to "--" after the watch has been disconnected for more than 8 hrs. I am thinking I can do this by capturing the moment in time it disconnected and then using an if statement or a timer for an 8 hr period. But I do not know how to capture the instance that the phone disconnects. Do I need to implement this in the background as a temporal event? If so, how do I use the phone disconnect as a trigger?

  • Depending on your weather source, the data you receive might have a time stamp.  For example, OWM has it as

    "dt":1545583620

    and for Garmin Weather, it's in currentConditions, and it's observationTime.

    Both are in "unix time" (number of seconds since Jan 1,1970, 00:00 UTC)

    So, Time.now().value() is the current time in "unix time:, and that minus the timestamp, is how old (in seconds) the data is.

    Convert that to hours, and if it's greater than x hours, the data is stale, so display "--" for temperature.

    Much easier than monitoring the phone connection

  • Former Member
    Former Member over 4 years ago in reply to jim_m_58

    Ah, thanks! I did not know about the observationTime feature. That is much easier!

  • It's also something to consider displaying along with the temperature - you can see how old the reading is - a few minutes vs a few hours.