slashback100 / presence_simulation

Home Assistant Presence Simulation
654 stars 26 forks source link

Setting Switch Off or Calling Service to Stop Simulation Turns off Lights #130

Closed PablaV closed 5 months ago

PablaV commented 5 months ago

Recently I have been having lights randomly turning off when the presence simulation wasn't active. I couldn't quite figure out why because the presence simulation's switch history stated that's its been off but somehow I was seeing lights being turned on/off by scene activate. Turns out that when my automation that turns off the presence simulation switch runs, the lights are returned to their original state as if the simulation was running prior. Basically even though the presence simulation switch is off, if you call a service that turns the switch off or to stop the simulation, it acts as if the simulation was running and then turns everything to its original state.

Steps to reproduce:

  1. Manually turn on the simulation via the switch or service call
  2. Take note of the lights that turned on and pick one
  3. Manually turn off the simulation via switch or service call
  4. Check to see if all the lights that turned on in step 2 turned off
  5. Manually turn one of those aforementioned lights on
  6. Manually turn off the simulation via switch or service call.
  7. You will see the light that you turned on in step 5 turned off even though no simulation was running prior and all that happened was we manually stopped the simulation even though it was already off

I know this can be mitigated by tweaking my automation to only turn off the switch if it's on, but I think this a bug. I have attached some debug logs.

2024-04-28 20:43:59.889 DEBUG (MainThread) [custom_components.presence_simulation] Switch of light.master_bedroom_light foreseen at 2024-04-29 04:42:34.660273+00:00
2024-04-28 20:43:59.889 DEBUG (MainThread) [custom_components.presence_simulation] Randomize the event within a range of +/- 0 sec
2024-04-28 20:43:59.889 DEBUG (MainThread) [custom_components.presence_simulation] Randomize the event of 0.0 seconds
2024-04-28 20:43:59.889 DEBUG (MainThread) [custom_components.presence_simulation] initial_secs_left 3514.770507, target_time 2024-04-29 04:42:34.660273+00:00
2024-04-28 20:43:59.890 DEBUG (DbWorker_2) [custom_components.presence_simulation] Entity light.ratgdov25i_18fe51_light
2024-04-28 20:43:59.890 DEBUG (DbWorker_2) [custom_components.presence_simulation] Entity light.ratgdov25i_18fe5e_light
2024-04-28 20:43:59.891 DEBUG (DbWorker_2) [custom_components.presence_simulation] Entity light.s2_dimmer_switch
2024-04-28 20:43:59.892 DEBUG (DbWorker_2) [custom_components.presence_simulation] Entity light.s2_dimmer_switch_2
2024-04-28 20:43:59.892 DEBUG (DbWorker_2) [custom_components.presence_simulation] Entity light.s2_dimmer_switch_3
2024-04-28 20:43:59.893 DEBUG (DbWorker_2) [custom_components.presence_simulation] Entity remote.harmony_hub
2024-04-28 20:43:59.894 DEBUG (DbWorker_2) [custom_components.presence_simulation] All async tasks launched
2024-04-28 20:43:59.906 DEBUG (MainThread) [custom_components.presence_simulation] Simulate one entity: light.front_pedant_lights
2024-04-28 20:43:59.906 DEBUG (MainThread) [custom_components.presence_simulation] State {'entity_id': 'light.front_pedant_lights', 'state': 'on', 'attributes': {'color_mode': 'onoff', 'friendly_name': 'Front Pedant Lights '}, 'last_changed': '2024-04-26T03:43:59.807097+00:00', 'last_updated': '2024-04-26T03:43:59.807097+00:00'}
2024-04-28 20:43:59.907 DEBUG (MainThread) [custom_components.presence_simulation] Switch of light.front_pedant_lights foreseen at 2024-04-29 03:43:59.807097+00:00
2024-04-28 20:43:59.907 DEBUG (MainThread) [custom_components.presence_simulation] Switching light light.front_pedant_lights to on
2024-04-28 20:43:59.908 DEBUG (MainThread) [custom_components.presence_simulation] Got attribute color_mode: onoff
2024-04-28 20:43:59.914 DEBUG (MainThread) [custom_components.presence_simulation] State {'entity_id': 'light.front_pedant_lights', 'state': 'off', 'attributes': {'color_mode': None, 'friendly_name': 'Front Pedant Lights '}, 'last_changed': '2024-04-26T04:42:34.716415+00:00', 'last_updated': '2024-04-26T04:42:34.716415+00:00'}
2024-04-28 20:43:59.914 DEBUG (MainThread) [custom_components.presence_simulation] Switch of light.front_pedant_lights foreseen at 2024-04-29 04:42:34.716415+00:00
2024-04-28 20:43:59.914 DEBUG (MainThread) [custom_components.presence_simulation] Randomize the event within a range of +/- 0 sec
2024-04-28 20:43:59.914 DEBUG (MainThread) [custom_components.presence_simulation] Randomize the event of 0.0 seconds
2024-04-28 20:43:59.915 DEBUG (MainThread) [custom_components.presence_simulation] initial_secs_left 3514.801407, target_time 2024-04-29 04:42:34.716415+00:00
2024-04-28 20:43:59.915 DEBUG (MainThread) [custom_components.presence_simulation] Simulate one entity: light.ratgdov25i_18fe51_light
2024-04-28 20:43:59.915 DEBUG (MainThread) [custom_components.presence_simulation] State {'entity_id': 'light.ratgdov25i_18fe51_light', 'state': 'off', 'attributes': {'color_mode': None, 'friendly_name': 'Ram Garage Light'}, 'last_changed': '2024-04-26T03:43:59.807097+00:00', 'last_updated': '2024-04-26T03:43:59.807097+00:00'}
2024-04-28 20:43:59.915 DEBUG (MainThread) [custom_components.presence_simulation] Switch of light.ratgdov25i_18fe51_light foreseen at 2024-04-29 03:43:59.807097+00:00
2024-04-28 20:43:59.915 DEBUG (MainThread) [custom_components.presence_simulation] Switching light light.ratgdov25i_18fe51_light to off
2024-04-28 20:43:59.918 DEBUG (MainThread) [custom_components.presence_simulation] State {'entity_id': 'light.ratgdov25i_18fe51_light', 'state': 'on', 'attributes': {'color_mode': 'onoff', 'friendly_name': 'Ram Garage Light'}, 'last_changed': '2024-04-26T14:24:11.552436+00:00', 'last_updated': '2024-04-26T14:24:11.552436+00:00'}
2024-04-28 20:43:59.919 DEBUG (MainThread) [custom_components.presence_simulation] Switch of light.ratgdov25i_18fe51_light foreseen at 2024-04-29 14:24:11.552436+00:00
2024-04-28 20:43:59.919 DEBUG (MainThread) [custom_components.presence_simulation] Randomize the event within a range of +/- 0 sec
2024-04-28 20:43:59.919 DEBUG (MainThread) [custom_components.presence_simulation] Randomize the event of 0.0 seconds
2024-04-28 20:43:59.919 DEBUG (MainThread) [custom_components.presence_simulation] initial_secs_left 38411.633038, target_time 2024-04-29 14:24:11.552436+00:00
2024-04-28 20:43:59.919 DEBUG (MainThread) [custom_components.presence_simulation] Simulate one entity: light.ratgdov25i_18fe5e_light
2024-04-28 20:43:59.924 DEBUG (MainThread) [custom_components.presence_simulation] State {'entity_id': 'light.ratgdov25i_18fe5e_light', 'state': 'off', 'attributes': {'color_mode': None, 'friendly_name': 'Golf Garage Light'}, 'last_changed': '2024-04-26T03:43:59.807097+00:00', 'last_updated': '2024-04-26T03:43:59.807097+00:00'}
2024-04-28 20:43:59.924 DEBUG (MainThread) [custom_components.presence_simulation] Switch of light.ratgdov25i_18fe5e_light foreseen at 2024-04-29 03:43:59.807097+00:00
2024-04-28 20:43:59.924 DEBUG (MainThread) [custom_components.presence_simulation] Switching light light.ratgdov25i_18fe5e_light to off
2024-04-28 20:43:59.928 DEBUG (MainThread) [custom_components.presence_simulation] State {'entity_id': 'light.ratgdov25i_18fe5e_light', 'state': 'on', 'attributes': {'color_mode': 'onoff', 'friendly_name': 'Golf Garage Light'}, 'last_changed': '2024-04-26T04:34:21.176836+00:00', 'last_updated': '2024-04-26T04:34:21.176836+00:00'}
2024-04-28 20:43:59.928 DEBUG (MainThread) [custom_components.presence_simulation] Switch of light.ratgdov25i_18fe5e_light foreseen at 2024-04-29 04:34:21.176836+00:00
2024-04-28 20:43:59.928 DEBUG (MainThread) [custom_components.presence_simulation] Randomize the event within a range of +/- 0 sec
2024-04-28 20:43:59.928 DEBUG (MainThread) [custom_components.presence_simulation] Randomize the event of 0.0 seconds
2024-04-28 20:43:59.928 DEBUG (MainThread) [custom_components.presence_simulation] initial_secs_left 3021.247941, target_time 2024-04-29 04:34:21.176836+00:00
2024-04-28 20:43:59.929 DEBUG (MainThread) [custom_components.presence_simulation] Simulate one entity: light.s2_dimmer_switch
2024-04-28 20:43:59.929 DEBUG (MainThread) [custom_components.presence_simulation] State {'entity_id': 'light.s2_dimmer_switch', 'state': 'off', 'attributes': {'color_mode': None, 'brightness': None, 'friendly_name': 'Chandelier '}, 'last_changed': '2024-04-26T03:43:59.807097+00:00', 'last_updated': '2024-04-26T03:43:59.807097+00:00'}
2024-04-28 20:43:59.929 DEBUG (MainThread) [custom_components.presence_simulation] Switch of light.s2_dimmer_switch foreseen at 2024-04-29 03:43:59.807097+00:00
2024-04-28 20:43:59.929 DEBUG (MainThread) [custom_components.presence_simulation] Switching light light.s2_dimmer_switch to off
2024-04-28 20:43:59.933 DEBUG (MainThread) [custom_components.presence_simulation] State {'entity_id': 'light.s2_dimmer_switch', 'state': 'off', 'attributes': {'color_mode': None, 'brightness': None, 'friendly_name': 'Chandelier '}, 'last_changed': '2024-04-29T03:40:26.377794+00:00', 'last_updated': '2024-04-29T03:40:26.377794+00:00'}
2024-04-28 20:43:59.934 DEBUG (MainThread) [custom_components.presence_simulation] Switch of light.s2_dimmer_switch foreseen at 2024-05-02 03:40:26.377794+00:00
2024-04-28 20:43:59.934 DEBUG (MainThread) [custom_components.presence_simulation] Randomize the event within a range of +/- 0 sec
2024-04-28 20:43:59.934 DEBUG (MainThread) [custom_components.presence_simulation] Randomize the event of 0.0 seconds
2024-04-28 20:43:59.934 DEBUG (MainThread) [custom_components.presence_simulation] initial_secs_left 258986.443362, target_time 2024-05-02 03:40:26.377794+00:00
2024-04-28 20:43:59.934 DEBUG (MainThread) [custom_components.presence_simulation] Simulate one entity: light.s2_dimmer_switch_2
2024-04-28 20:43:59.934 DEBUG (MainThread) [custom_components.presence_simulation] State {'entity_id': 'light.s2_dimmer_switch_2', 'state': 'off', 'attributes': {'color_mode': None, 'brightness': None, 'friendly_name': 'Mudroom Light '}, 'last_changed': '2024-04-26T03:43:59.807097+00:00', 'last_updated': '2024-04-26T03:43:59.807097+00:00'}
2024-04-28 20:43:59.935 DEBUG (MainThread) [custom_components.presence_simulation] Switch of light.s2_dimmer_switch_2 foreseen at 2024-04-29 03:43:59.807097+00:00
2024-04-28 20:43:59.935 DEBUG (MainThread) [custom_components.presence_simulation] Switching light light.s2_dimmer_switch_2 to off
2024-04-28 20:43:59.937 DEBUG (MainThread) [custom_components.presence_simulation] State {'entity_id': 'light.s2_dimmer_switch_2', 'state': 'on', 'attributes': {'color_mode': None, 'brightness': None, 'friendly_name': 'Mudroom Light '}, 'last_changed': '2024-04-26T14:23:59.224764+00:00', 'last_updated': '2024-04-26T14:23:59.224764+00:00'}
2024-04-28 20:43:59.937 DEBUG (MainThread) [custom_components.presence_simulation] Switch of light.s2_dimmer_switch_2 foreseen at 2024-04-29 14:23:59.224764+00:00
2024-04-28 20:43:59.937 DEBUG (MainThread) [custom_components.presence_simulation] Randomize the event within a range of +/- 0 sec
2024-04-28 20:43:59.937 DEBUG (MainThread) [custom_components.presence_simulation] Randomize the event of 0.0 seconds
2024-04-28 20:43:59.938 DEBUG (MainThread) [custom_components.presence_simulation] initial_secs_left 38399.286746, target_time 2024-04-29 14:23:59.224764+00:00
2024-04-28 20:43:59.938 DEBUG (MainThread) [custom_components.presence_simulation] Simulate one entity: light.s2_dimmer_switch_3
2024-04-28 20:43:59.938 DEBUG (MainThread) [custom_components.presence_simulation] State {'entity_id': 'light.s2_dimmer_switch_3', 'state': 'off', 'attributes': {'color_mode': None, 'brightness': None, 'friendly_name': 'Family Room Light '}, 'last_changed': '2024-04-26T03:43:59.807097+00:00', 'last_updated': '2024-04-26T03:43:59.807097+00:00'}
2024-04-28 20:43:59.938 DEBUG (MainThread) [custom_components.presence_simulation] Switch of light.s2_dimmer_switch_3 foreseen at 2024-04-29 03:43:59.807097+00:00
2024-04-28 20:43:59.938 DEBUG (MainThread) [custom_components.presence_simulation] Switching light light.s2_dimmer_switch_3 to off
2024-04-28 20:43:59.942 DEBUG (MainThread) [custom_components.presence_simulation] State {'entity_id': 'light.s2_dimmer_switch_3', 'state': 'on', 'attributes': {'color_mode': 'brightness', 'brightness': 255, 'friendly_name': 'Family Room Light '}, 'last_changed': '2024-04-26T16:26:39.632191+00:00', 'last_updated': '2024-04-26T16:26:39.632191+00:00'}
2024-04-28 20:43:59.942 DEBUG (MainThread) [custom_components.presence_simulation] Switch of light.s2_dimmer_switch_3 foreseen at 2024-04-29 16:26:39.632191+00:00
2024-04-28 20:43:59.942 DEBUG (MainThread) [custom_components.presence_simulation] Randomize the event within a range of +/- 0 sec
2024-04-28 20:43:59.942 DEBUG (MainThread) [custom_components.presence_simulation] Randomize the event of 0.0 seconds
2024-04-28 20:43:59.942 DEBUG (MainThread) [custom_components.presence_simulation] initial_secs_left 45759.68949, target_time 2024-04-29 16:26:39.632191+00:00
2024-04-28 20:43:59.943 DEBUG (MainThread) [custom_components.presence_simulation] Simulate one entity: remote.harmony_hub
2024-04-28 20:43:59.943 DEBUG (MainThread) [custom_components.presence_simulation] State {'entity_id': 'remote.harmony_hub', 'state': 'off', 'attributes': {'activity_list': ['Watch TV', 'Watch Prime TV'], 'current_activity': 'PowerOff', 'activity_starting': None, 'devices_list': ['Samsung Amp', 'TELUS DVR', 'LG TV'], 'last_activity': 'Watch TV', 'friendly_name': 'Family Room Harmony Hub'}, 'last_changed': '2024-04-26T03:43:59.807097+00:00', 'last_updated': '2024-04-26T03:43:59.807097+00:00'}
2024-04-28 20:43:59.943 DEBUG (MainThread) [custom_components.presence_simulation] Switch of remote.harmony_hub foreseen at 2024-04-29 03:43:59.807097+00:00
2024-04-28 20:43:59.943 DEBUG (MainThread) [custom_components.presence_simulation] Switching entity remote.harmony_hub to off
2024-04-28 20:43:59.945 DEBUG (MainThread) [custom_components.presence_simulation] State {'entity_id': 'remote.harmony_hub', 'state': 'on', 'attributes': {'activity_list': ['Watch TV', 'Watch Prime TV'], 'current_activity': 'Watch TV', 'activity_starting': 'Watch TV', 'devices_list': ['Samsung Amp', 'TELUS DVR', 'LG TV'], 'last_activity': 'Watch TV', 'friendly_name': 'Family Room Harmony Hub'}, 'last_changed': '2024-04-26T16:58:12.716167+00:00', 'last_updated': '2024-04-26T16:58:12.716167+00:00'}
2024-04-28 20:43:59.946 DEBUG (MainThread) [custom_components.presence_simulation] Switch of remote.harmony_hub foreseen at 2024-04-29 16:58:12.716167+00:00
2024-04-28 20:43:59.946 DEBUG (MainThread) [custom_components.presence_simulation] Randomize the event within a range of +/- 0 sec
2024-04-28 20:43:59.946 DEBUG (MainThread) [custom_components.presence_simulation] Randomize the event of 0.0 seconds
2024-04-28 20:43:59.946 DEBUG (MainThread) [custom_components.presence_simulation] initial_secs_left 47652.769556, target_time 2024-04-29 16:58:12.716167+00:00
2024-04-28 20:43:59.947 DEBUG (MainThread) [custom_components.presence_simulation] Presence simulation will be relaunched in 3 days
2024-04-28 20:44:14.484 DEBUG (MainThread) [custom_components.presence_simulation] Stopped presence simulation
2024-04-28 20:44:14.485 DEBUG (MainThread) [custom_components.presence_simulation] entity.restore_states True
2024-04-28 20:44:14.485 DEBUG (MainThread) [custom_components.presence_simulation] Restoring scene after the simulation
2024-04-28 20:44:22.981 DEBUG (MainThread) [custom_components.presence_simulation] Stopped presence simulation
2024-04-28 20:44:22.982 DEBUG (MainThread) [custom_components.presence_simulation] entity.restore_states True
2024-04-28 20:44:22.982 DEBUG (MainThread) [custom_components.presence_simulation] Restoring scene after the simulation
slashback100 commented 5 months ago

Hello,

Thanks for your investigation. I indeed detected this behavior and fixed it in #120. Still not released though. I'll try to release it asap.