Device trackers - conflicting More Info?

Am I misunderstanding something fundamental or do these look wrong?

image

image

The bar shows multiple states. Are you actually home right now?

This is my sonā€™s phone:
image

Here is mine:

image

That does seem weird. If you just left home I suppose the line graph might not be able to show the new state since itā€™s so small. If you click the ā€œtitle barā€ of the ā€œmore infoā€ window (which should cause it to expand horizontally), do you still not see anything on the right end to show the Away state?

@flamingm0e, @pnbruckner

This was my wife who was out, several miles away and had been so for a couple of hours.

Sounds to me like this entity is not getting recorded in the database anymore, or the database has become corrupted, or something along those lines.

I think you might be on the right lines. But itā€™s even strangerā€¦

Firstly, the Google device tracker is doing the same thing, and actually they are doing it for both me and my wife. however both Composite trackers behave as expected.

What is strange is that in my Logbook I only get entries for my Life360 and Google device trackers when they change to ā€˜Homeā€™.

Any ideas what could be going on?

Iā€™d query the database directly to see what state changes are getting recorded. Then go from there.

Iā€™m not sure how to do thatā€¦

What database do you use?

Alternatively, you can enable debug for homeassistant.core, and then each state change will get written to home-assistant.log. Youā€™ll probably not want that on for long, especially if you have a ā€œlargeā€ system, but it can help. I wrote a python script that can extract entity state changes from home-assistant.log if youā€™re interested.

errā€¦ I use the database that comes with hassio.
I have recently installed the Influx and Grafana add-ons but am still finding my way around those.

I am interested in that script but I wonā€™t be enabling debug today as I donā€™t expect any more state changes with the device trackers. Iā€™ll try tomorrow.

FYI: itā€™s SQLITE

1 Like

I use MariaDB, and that allows me to use mysql to query it while HA is running. I had no such luck when I used sqlite. But then Iā€™m not all that familiar with databases.

Their states change all the time when you move just a little (i.e., the GPS coordinates change.) But youā€™re right, the stateā€™s state doesnā€™t change if youā€™re not entering/leaving zones. :wink:

You can get the script here:

The easiest way to use it is to copy it into the same directory as home-assistant.log. (Donā€™t forget to get a ā€œrawā€ copy from github.) Then from the command line:

python3 state_updates.py home-assistant.log device_tracker.xxx

The first parameter is the name of the log file. Then you can list one or more entity_idā€™s (separated by spaces.) For each entity_id you can also follow with attribute name(s). But for this purpose, Iā€™d just enter one device_tracker entity_id per invocation. It will list each ā€œstateā€ change (i.e., the state objectā€™s state) along with the logā€™s timestamp and the stateā€™s last_changed value. (Youā€™ll note it also outputs the homeassistant.start event.)

Thanks. Iā€™m at the edge of my expertise here on several counts. Database amounts to IBM DB2 at least 20 to 25 years ago and MS Access 10 years ago; Linux command line and Python is entirely ā€˜learntā€™ since using HA.

Iā€™m not even sure if I can run a python script on the command line using hassio (in a VM on Proxmox) but Iā€™ll see what I can do.

The frustrating thing is that HA seems to work ok so it is all the more strange that this is happening?

I hear you about hassio. Thatā€™s why Iā€™ve never even considered using it. On the other hand I guess you donā€™t miss what you donā€™t know. :slight_smile:

The script (if you can run it) will tell you when the entities change state and to what. It will confirm what the history should be showing. But it canā€™t really tell you why the history isnā€™t showing what it should. For that you do really need to query the database. Of course, thatā€™s what the history graph in the more info window is supposed to be doing.

Are you sure you havenā€™t excluded these entities from the recorder?

Thatā€™s the first thing I checked because I have recently made changes there because my snapshots were getting huge, but my recorder is as follows:

recorder:
  purge_keep_days: 3
  purge_interval: 1

  exclude:
    domains:
      - camera
      - counter
      - group
      - history_graph
      - proximity
      - updater
      - weather
      - weblink
      - zone

    entities:

Followed by some specific Automations, Binary Sensors, Media Players, Scripts and Sensors

Ok, cool.

Bottom line (for me) is the symptoms seem to indicate there is some history for the device_trackers (itā€™s finding something old), but new state changes arenā€™t getting saved. Until and unless you can find a way to see whatā€™s really in the db, I think itā€™s going to be near impossible, if not impossible, to get to the bottom of this.

I suppose it could also simply be that the database somehow got corrupted. Is there anything in home-assistant.log that might indicate issues with the db? I know itā€™s not optimal, but if you delete the db does it happen again?

Hmm, I was considering that but really donā€™t want to. I will as a last resort though.

What about removing the integrations and re-instating them? Is that an option, by which I mean would HA internally forget it ever knew they existed and recreate them or will it just carry on where it left off?

Actually, re-reading this:

I am not sure if that is right. It is always saving the state when it changes to ā€˜homeā€™ but not when it changes to ā€˜awayā€™.

Tomorrow I will be able to see if it saves the state when it changes to another zone. (By which I mean I will be able to se in the Logbook).

I canā€™t imagine that will help at all.

Um, if it only ā€œsavesā€ when it changes to home, how could you possibly see that? Honestly, Iā€™m not sure where the Logbook gets its data, so I couldnā€™t say how what you see there relates to the database (and ultimately the history shown on the history page, or in an entityā€™s more info window.)

If I were you Iā€™d concentrate on trying to find a way to see whatā€™s in the database. Is there some sort of hassio add-on that provides database querying capability? Or maybe you can stop HA, copy the database file to another system, and view it there with some utility???

Yeah, thatā€™s the only way I know it ā€œsavesā€ the state - because it shows it happening in the Logbook. so, no, I suppose youā€™re right, I donā€™t know if it is saving!

Iā€™ll look into it - I think there are hassio DB add-onsā€¦

I donā€™t know where this leaves us me, but there is a (rather good) SQLLite add-on for hassio and I can confirm that all the Life360 states are being written to the database. That is, home, not_home and zone names.

So why does the more-info display wrongly and the Logbook not show all the data?

Also (and this might be a separate issue, Iā€™m happy to start a new post) Life360 looks to me like it is reporting some strange results.

For example it changes from a zone where it has been for several hours to ā€™not_home for less than two seconds, then back to the zone; before flipping again 3 minutes later for less than a second before returning back to the zone.

The interesting bit (to me) is that these not_home states have a "source_type": null.

I can see this behaviour other times too, including when it is home and has been for several hours but then jumps momentarily to not_home with a "source_type": null

When it really is home it seems to have the correct "source_type": "gps".

I know this is all getting a bit esoteric but Iā€™m grateful for your thoughts. (I can of course provide actual data if it helps or is interesting)