home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
69.82k stars 28.95k forks source link

Device_tracker switches state by rebooting HA #107725

Open danielBreitlauch opened 6 months ago

danielBreitlauch commented 6 months ago

The problem

The picture says it all. The device_trackers last log entry says home/Anwesend but the state is not_home/Abwesend. It does not make sense to change the state of an entity through reboot. The entity is create through 'device_tracker.see' service calls. At bare minimum put the state change in the log but I would rather like a solution that reboots don't change state.

image

I know this topic came up already here, here and here but it was never really solved.

If it is a problem that multiple platforms need different defaults then at least the state should go to "unknown" and not a certain "not_home".

What version of Home Assistant Core has the issue?

core-2024.1.2

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

No response

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 5 months ago

Hey there @home-assistant/core, mind taking a look at this issue as it has been labeled with an integration (device_tracker) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `device_tracker` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign device_tracker` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


device_tracker documentation device_tracker source (message by IssueLinks)

TimoVerbrugghe commented 3 months ago

Chiming in as well that I'm experiencing the same issue.

I only have 1 device_tracker linked to me as a person in home assistant, which is updated through a webhook that I send from my iPhone (and homekit). It's the most accurate way I've found to track whether I'm home or not. This works perfectly.

I also have an automation that when I arrive home (so my state goes from away to home) and the sun has set, that the lights on my front porch and income hall go on.

However, when HA gets restarted in the middle of the night (f.e. because watchtower updates the container), my device_tracker entity gets the state of not_home, so I'm put at away, which messes up this automation.

I tried just creating an automation that sets the state of device_tracker to home at home assistant startup (I stored the state in some boolean helper), but at home assistant startup, it starts up as away and then immediately gets set to home due to my automation, which triggers a bunch of other automations I made that trigger when I go from state "away" to "home" 🙅🏻 ....

TimoVerbrugghe commented 3 months ago

Allright following up on this if anybody comes to the same problem. I applied a temporary fix using the uptime sensor.

If you would now restart home assistant, that would mean that your device_tracker first goes to away and then immediately switches to home due to your automation. This will trigger any automation where you define if a person is coming home, that something has to happen (not desirable behaviour).

So for every automation that you have where the trigger is " if person arrives home", add an additional condition that checks if the uptime is less than 30 seconds:

{{ (as_timestamp(now()) - as_timestamp(states('sensor.uptime'))) >= 30 }}

That way, the automation won't trigger if home assistant has just restarted.

smart7324 commented 3 months ago

Same issue for me. I think this is a serious problem that should be fixed...

issue-triage-workflows[bot] commented 5 days ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.