jseidl / hass-magic_areas

Areas with batteries included for Home Assistant
MIT License
273 stars 28 forks source link

Event Loop due to dark state when area has luminance sensor #324

Closed juacas closed 7 months ago

juacas commented 7 months ago

Describe the bug If an area has a light sensor to calculate the "dark state" and the lights turn on, then the dark state goes to "off" and lights are turned off, the dark state goes to "on" and the cycle starts again.

To Reproduce Steps to reproduce the behavior:

  1. Create a helper sensor for "dark state" (i.e. threshold sensor) with luminance sensor.
  2. Configure the area to control lights in "dark state".
  3. Make the presence sensor to trigger presence.
  4. Start the endless loop on-off-on-off.

Expected behavior Not to consider the dark state to turn off the lights when the sensor is in the same room. Maybe with a checkbox in config flow to select "Use "dark state" only for turning on the lights." or "Don't turn off when is not dark."

PD: I tried as a workaround defining a template sensor for darkness with the logic: "is dark and ligth is off" but it didn't work.

Regards.

jseidl commented 7 months ago

This is a known loop and that's why it's not recommended to use the internal luminance for that, but rather the external (outdoors) luminance levels that are not affected by lighting.

"Don't turn off when is not dark." can be emulated by setting "When should lights be controlled" to occupancy only and not for state.

Can you share your template? That should've worked

juacas commented 7 months ago

Thanks for replying so fast!

My template is: {{ (states('light.luzcocina_light') == "off") and (states('binary_sensor.kitchen_is_dark') == 'on' ) }}

But it produces an event race and the light goes on/off very fast for a few seconds until it stabilizes. Then the faked state is "dark" while the light is "on". I know this is a dirty workaround... that doesn't work in real world.

It is a pity not to be able to take advantage of the actual sensor to control the room light. Please consider my proposal that the dark state be optionally used only to turn on the light.

jseidl commented 7 months ago

Try using the state_attr last_changed to help stabilize the flipping. You can add a condition where N seconds must have passed. Also use our #support channel on Discord if you need more help with your template.

Please consider my proposal that the dark state be optionally used only to turn on the light.

Please add a Feature Request on the Discussions tab