danobot / entity-controller

Home Assistant Entity and lighting controller for managing devices with timers, scripts, and sun-based time restrictions.
https://danobot.github.io/ec-docs/
GNU General Public License v3.0
289 stars 41 forks source link

trigger_on_deactivate is triggered when giving up control because of an outside change. #309

Closed Pabsilon closed 9 months ago

Pabsilon commented 9 months ago

Hi! First of all, great job with the integration, it works wonderfully well. I've encountered an issue when using scripts.

Description

I have an entity controller for motion controlled lights in my kitchen. These lights are hue, and as such, are dimmable. In general, I use a single script for toggling the lights (omitting some logic, in its base, it's 'if lights are on turn off, else turn on' . This script is used as trigger_on_activate on entity controller, and it's used when pressing the kitchen wall switch. But, for trigger_on_deactivate, I have a different script that adds a longer transition time to turn off the light (Just a turn on service call with brightness 0 and transition 15) so whoever is in the kitchen has a heads up that notion lights are turning off.

My issue is that whenever lights are turned on by EC, and I turn them off manually with the wall switch, the trigger_on_deactivate script is also called, usually resulting in the lights not turning off (they actually dim halfway through, and I think that's an issue for another place)

So, basically, if EC is active and I call the EC trigger_on_activate script again (which is a toggle and changes the observable entity's state), both my script AND the trigger_on_deactivate script are run more or less at the some time.

Configuration

# Motion Activated Kitchen Lights
# These are disabled from sunrise until 30 minutes before sunset
kitchen_motion_light:
  # Sensor Config
  sensor: binary_sensor.kitchen_motion
  sensor_type: duration
  sensor_resets_time: true
  delay: 15

  # Observable Entity
  state_entities:
    - light.kitchen_hues
  state_attributes_ignore:
    - brightness
    - color_temp

  # Time Constraint
  start_time: sunset - 00:30:00
  start_time_action: "off"
  end_time: sunrise

  # Extra Actions
  trigger_on_deactivate: script.turn_off_the_kitchen_slowly
  trigger_on_activate: script.toggle_the_kitchen

Steps to reproduce

Steps to reproduce the behavior:

  1. Trigger EC with motion sensor
  2. Press wall switch which triggers 'script.toggle_the_kitchen'

Expected behavior

This is how the component should work:

  1. Lights turn off because script.toggle_the_kitchen is called
  2. Since EC has been overriden and ended before normal operation, script.turn_off_the_kitchen_slowly is not called

Actual Behaviour

This is what actually happened:

  1. Lights ¿Dim? a bit
  2. script.toggle_the_kitchen is called
  3. script.turn_off_the_kitchen_slowly is called at the same time

Logs

I will provide full logs tomorrow, as I can't restart my main instance at the moment.

Version

V9.6.1
Pabsilon commented 9 months ago

I've been investigating further and I think my issue is not related to entity controller, as using plain 'turn_on' then 'turn_off' calls on the controlled device results in the same problem.

Pabsilon commented 9 months ago

In case someone runs into something similar, it was due to have transition in my calls. For some reason, the hue bulbs in zigbee2mqtt didn't like it.