slashback100 / presence_simulation

Home Assistant Presence Simulation
423 stars 22 forks source link

Presence Simulation automatically starts on startup of HA #77

Closed christianglodt closed 1 year ago

christianglodt commented 1 year ago

I've noticed in the last week or so that the presence simulation starts automatically when Home Assistant is started/restarted.

I'm on Home Assistant 2023.2.2.

This definitely didn't use to happen anymore (since #58 was fixed). And I don't have any automation that starts it.

I see the following error in the log that seems related to the presence_simulation_scene, maybe that's related:

2023-02-05 11:07:39.141 ERROR (MainThread) [homeassistant.core] Error executing service: <ServiceCall scene.turn_on (c:01GRGGQBKW2AWFFEFZQSE52GBF): entity_id=['scene.presence_simulation_scene']>
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/core.py", line 1805, in catch_exceptions
await coro_or_task
File "/usr/src/homeassistant/homeassistant/core.py", line 1824, in _execute_service
await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 213, in handle_service
await service.entity_service_call(
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 680, in entity_service_call
future.result() # pop exception if have
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 968, in async_request_call
await coro
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 720, in _handle_entity_call
await result
File "/usr/src/homeassistant/homeassistant/components/scene/__init__.py", line 114, in _async_activate
await self.async_activate(**kwargs)
File "/usr/src/homeassistant/homeassistant/components/homeassistant/scene.py", line 334, in async_activate
await async_reproduce_state(
File "/usr/src/homeassistant/homeassistant/helpers/state.py", line 115, in async_reproduce_state
await asyncio.gather(
File "/usr/src/homeassistant/homeassistant/helpers/state.py", line 109, in worker
await platform.async_reproduce_states(
File "/usr/src/homeassistant/homeassistant/components/cover/reproduce_state.py", line 125, in async_reproduce_states
await asyncio.gather(
File "/usr/src/homeassistant/homeassistant/components/cover/reproduce_state.py", line 107, in _async_reproduce_state
await hass.services.async_call(
File "/usr/src/homeassistant/homeassistant/core.py", line 1787, in async_call
task.result()
File "/usr/src/homeassistant/homeassistant/core.py", line 1824, in _execute_service
await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 213, in handle_service
await service.entity_service_call(
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 657, in entity_service_call
raise HomeAssistantError(
homeassistant.exceptions.HomeAssistantError: Entity cover.dressing_room_blinds does not support this service.
JurajNyiri commented 1 year ago

I noticed the same since updating to 2023.02.x release. Checked all my automations, nothing is turning it on. The only log I have related to this integration is below.

Logger: homeassistant.components.switch
Source: helpers/entity_platform.py:822
Integration: Switch (documentation, issues)
First occurred: 11:20:13 AM (1 occurrences)
Last logged: 11:20:13 AM

Updating presence_simulation switch took longer than the scheduled update interval 0:00:05

In logbook it simply shows up as

Turned on
11:19:48 AM - 39 minutes ago
twodrops commented 1 year ago

I can confirm the problem with 2023.2.2 as well

JurajNyiri commented 1 year ago

Issue stopped for me randomly now just like it started after updating to 2023.2.2.

slashback100 commented 1 year ago

I'm in 2023.2.1 but I don't have the issue. Could maybe someone try to turn the simulation off, restart with the logger in debug and send me the log file? Thanks

gabichan commented 1 year ago

home_assistant.log.tar.gz

As far as I've seen, it resolves that presence simulation was on before the shutdown. But I'me sure it wasn't. I can't try it again if you need it.

slashback100 commented 1 year ago

Would it be possible for you to run this query on the DB (assuming you have MySql ?):

select * from states, state_attributes where states.attributes_id = state_attributes.attributes_id and states.entity_id = 'switch.presence_simulation' order by states.last_updated desc limit 10;
christianglodt commented 1 year ago

I use sqlite instead of MySql, but the query runs on sqlite as well. Here's the resulting output: sqlite.txt

slashback100 commented 1 year ago

Ok I may have something. In your DB, the states.last_update are all null. On mysql, apparently the result appear in the expected order, i.e. the earliest at the beginning, but in your sqlite result, that's the opposite, and the oldest is the first one. So it will always the oldest record, which has a 'on' state. I see a new column in the State table, which is last_updated_ts, I need to use that one instead of last_updated. This has been changed by this PR. I'll try to adapt this asap.

slashback100 commented 1 year ago

Fixed in v2.3 Thanks all for your help

twodrops commented 1 year ago

Tested v2.3 with 2023.2.2 and 2023.2.3 and the fix works with both. Thanks a lot for the quick fix @slashback100

sanvalerius commented 1 year ago

Hello, I just installed and setup this integration (v2.4) , and noticed that after a restart of HA it turn's ON the presence_simulation switch, wondering if this bug been re-introduced ?

slashback100 commented 1 year ago

Please open a new issue and provide logs during the restart. Thanks