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

Override entity prevents switching off #293

Open hcrohland opened 1 year ago

hcrohland commented 1 year ago

Description

I have a a threshold sensor which triggers when illumination is higher than a certain level as an override for a motion sensor triggered EC.

The documentation says: "You can define entities which stop EC from transitioning into active state if those entities are in on state". But the override is also used in active state.

Since the threshold is lower than the illumination created by the controlled light, the light never switches off.

The EC goes into the following state:

sensor_type: duration
delay: 180s
last_triggered_by: binary_sensor.lumi_lumi_sensor_motion_aq2_18cbe307_ias_zone
last_triggered_at: 2022-12-05 10:47:32.718405
icon: mdi:timer-off-outline
friendly_name: eingang
expires_at: 2022-12-05T10:50:32.718532
service_data: 
entity_id: light.iluminize_5120_1200_249828fe_on_off

sensor_turned_off_at: 2022-12-05T10:48:42.719310
overridden_by: binary_sensor.helligkeit_eingang
overridden_at: 2022-12-05 10:50:22.500030

Configuration

entity_controller:
  eingang:
    sensor: binary_sensor.lumi_lumi_sensor_motion_aq2_18cbe307_ias_zone
    sensor_type: duration
    entity: light.iluminize_5120_1200_249828fe_on_off
    overrides:
      - binary_sensor.helligkeit_eingang

Steps to reproduce

Steps to reproduce the behavior:

  1. Trigger motion with the treshold low enough

Expected behavior

This is how the component should work:

  1. Trigger motion
  2. EC switches light on
  3. Override triggers, but EC continues since it is already active....
  4. EC continues and switches light off after timeout

Actual Behaviour

This is what actually happened:

  1. Trigger motion
  2. EC switches light on
  3. Override triggers
  4. EC goes into override mode

Version

HA 2022.11.5
EC 9.6.0
danobot commented 1 year ago

This sounds like expected behaviour. When it goes in override it should stop whatever it's doing because something is overriding the controller.

alh84001 commented 1 year ago

I would disagree - if entity controller is active, it's too late to override it - so it should do its thing until its done. In my mind override is used for transition to active state, not for overriding the controller in its functionality.

Well, at least it should be configurable, and I'll make a PR soon-ish to provide a flag (or a list of states in which to consult override) for this.

BTW, I have the exact scenario that OP posted:

hcrohland commented 1 year ago

Yes, the current behaviour prevents the entity controller to be usable for motion sensors with illuminance control. The light changes the illuminance and that leads to the lights staying on indefinitely

alh84001 commented 1 year ago

However, thinking about it more, we already do have a way to set up behaviour for transition to active - it is the sensor property. It's just a matter of making a composite binary sensor of motion and luminance (threshold).

I have a feeling that even if we could change override behaviour, it still would be a bad experience, since you would have old bright luminance value cached, and I suspect there could be some weird timing interplay here between when luminance gets updated on next trigger and when motion gets updated.

In any case, I'll actually drop the override config, and play with configuring trigger sensor more.

alh84001 commented 1 year ago
- trigger:
    - platform: state
      entity_id: binary_sensor.a_motion_sensor
      for:
        milliseconds: 100
  binary_sensor:
    - name: "Motion Light Trigger"
      unique_id: "a_motion_light_trigger"
      state: >
        {% set is_on = is_state('binary_sensor.a_motion_light_trigger', 'on') %}       
        {% set is_ec_active = is_state('entity_controller.a_motion_light', 'active_timer') %}
        {% set is_not_over_luminance_threshold = not is_state('binary_sensor.an_illuminance_upper_threshold_sensor', 'on') %}
        {% set is_motion_detected = is_state('binary_sensor.a_motion_sensor') %}

        # ignore luminance sensor if trigger itself is already on,
        # or if entity controller that is triggered is already active
        {% if is_on or is_ec_active %}
        {{ is_motion_detected }}
        {% else %}
        {{ is_motion_detected and is_not_over_luminance_threshold }}
        {% endif %}

Above is the template trigger that I ended up with, and it seems to be covering the stated use-case well. It's by no means fully tested, but that will come with time.

pomeloy commented 1 year ago

I am also struggling with this type of scenario. @alh84001 thank you for your input. Could you explain where EC actually comes into play again? Do you use another automation to turn the lights on now?

alh84001 commented 1 year ago

EC configuration is then simple, with the trigger defined as above

entity_controller:
    a_motion_light:
      sensor: binary_sensor.a_motion_light_trigger
      entity: light.some_light_to_control
      sensor_type: duration
      sensor_resets_timer: true

Note that a_motion_light is checked in the binary sensor defined above, and that that sensor (a_motion_light_trigger) is used here.