Mysterious behavior of some states?!

I need the help of smart arm chair detectives to solve this creepy problem I got. I simply cannot wrap my head around this.

I have an entity device_tracker.xxx whose state I am trying to set. After I set it, something else overwrites the state within seconds. What could it be?

I tried the following to narrow down the issue:

  • disable AppDaemon just in case,
  • remove most of stuff from configuration.yaml except the bare minimum
  • change the port in http section to make sure that nothing connects to hass from outside.

None of this experiments stopped my state changes from being overwritten by something.

The overwriting state change typically looks like this in the log:

2018-12-30 00:29:50 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.139686313271424] Sending {'id': 2, 'type': 'event', 'event': {'event_type': 'state_changed', 'data': {'entity_id': 'device_tracker.xxx', 'old_state': <state device_tracker.xxx=fdddddddddddddddd @ 2018-12-29T19:29:49.377713-05:00>, 'new_state': <state device_tracker.xxx=home; source_type=router, friendly_name=XXXXX, custom_ui_state_card=state-card-custom-ui, show_last_changed=True @ 2018-12-29T19:29:50.004739-05:00>}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2018, 12, 30, 0, 29, 50, 4787, tzinfo=<UTC>), 'context': {'id': '42b81dd191904550816cbc84825d816d', 'user_id': None}}}

HA 0.84.3 here. Lovelace.

Any guess anyone?

A device_tracker entity (like most entities) is supposed to update itself. Why do you think it wouldn’t? Here’s a clue from the state change event: source_type=router.

Well, this device_tracker does not correspond to any real device, I created it manually. Why? I need to have a complex entity, so I define its behavior in a Python app. It should appear like a device_tracker to HASS. It all used to work beautifully in HA 0.74.

As for “source_type=router” you noticed in my log, it goes away if I disable the router tracker (tomato). The overwriting state then contains only

custom_ui_state_card=state-card-custom-ui, show_last_changed=True

What could be setting these attributes?

This does not happen to all my device_trackers, btw, only to some.

Ahhhhhhhh. This must have something to do with restore_state component of HASS. Cannot find anything about it in the docs. Hmm. How do I configure it to not touch some entities?