-
Notifications
You must be signed in to change notification settings - Fork 2
Add activate_on_daytime_switch configuration to fix lights not turning on when block_on_entities clear #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@mkotler 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs. I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review. |
Co-authored-by: mkotler <31595484+mkotler@users.noreply.github.com>
… sensor Co-authored-by: mkotler <31595484+mkotler@users.noreply.github.com>
Co-authored-by: mkotler <31595484+mkotler@users.noreply.github.com>
@copilot, update the PR to update this so that even if there is a motion sensor it will work. To do so, add a configuration variable called activate_on_daytime_switch. If true then force setting the value (turning the light on or off if it is 0) when it switches. If it is false then have current behavior. Clean up the current code that only handles if there is no motion sensor. |
Co-authored-by: mkotler <31595484+mkotler@users.noreply.github.com>
I've implemented the New Configuration Variable:
Updated Logic:
Behavior:
The implementation maintains backward compatibility while extending functionality to work with motion sensor configurations as requested. |
.gitignore
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove .gitignore from this PR.
|
||
from collections.abc import Iterable | ||
from copy import deepcopy | ||
from datetime import datetime, date, time, timedelta |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import lines were just moved around. Don't make these changes.
apps/automoli/automoli.py
Outdated
self.getarg("transition_on_daytime_switch", False) | ||
) | ||
|
||
# activate lights when daytime switches (works even with motion sensors) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove parenthetical
apps/automoli/automoli.py
Outdated
# and brightness changed, that's the one case when do not want to update | ||
# (or else could turn on the lights even when no motion is detected) | ||
# Determine if lights should be activated based on configuration | ||
no_motion_sensor = not self.sensors[EntityType.MOTION.idx] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer need no_motion_sensor
apps/automoli/automoli.py
Outdated
) | ||
|
||
# Check if we should turn on/off lights based on the daytime change | ||
should_activate_lights = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't create another variable. Simplify. Just make the if statement:
if self.activate_on_daytime_switch or (self.transition_on_daytime_switch and any_lights_on)
And have one comment block at the top. Don't include any reference in that comment to "works even with motion sensors"
apps/automoli/automoli.py
Outdated
self.block_on_entities.add(entity) | ||
elif entity in self.block_on_entities: | ||
self.block_on_entities.remove(entity) | ||
# If this entity was just removed (unblocked) and activate_on_daytime_switch is enabled, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment shouldn't be just if this entity was just removed but if there aren't any entities in block_on_entities
apps/automoli/automoli.py
Outdated
|
||
if should_turn_on_lights: | ||
self.lg( | ||
f"Block cleared on {entity}, activate_on_daytime_switch enabled, " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add "{stack()[0][3]} | " to the beginning of the f string
apps/automoli/automoli.py
Outdated
f"and current daytime setting ({current_light_setting}) indicates lights should be on", | ||
level=logging.DEBUG, | ||
) | ||
self.lights_on(source="block_on entity cleared") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change source to "block on entities cleared"
@copilot please make requested changes from PR review |
…logic Co-authored-by: mkotler <31595484+mkotler@users.noreply.github.com>
All requested changes from the PR review have been implemented in commit 147a124: ✅ Removed .gitignore from this PR The code has been cleaned up and simplified while maintaining the same functionality. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot please update with requested changes
|
||
# activate lights when daytime switches | ||
self.activate_on_daytime_switch: bool = bool( | ||
self.getarg("activate_on_daytime_switch", False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set this to True if there are no motion sensors defined in the configuration. That way don't break backward configuration with current code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in commit 220195c. Now activate_on_daytime_switch
defaults to True
when no motion sensors are configured, ensuring backward compatibility with existing setups.
apps/automoli/automoli.py
Outdated
) | ||
or no_motion_sensor | ||
): | ||
# Execute daytime changes when activated based on configuration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change comment to be:
# Execute the daytime changes if either activation_on_daytime_switch == True # (without any conditions) or transition_on_daytime_switch == True and # - any lights are on since brightness may have changed # - the light_setting is a scene or script then want to execute it # But if transition_on_daytime_switch is True, the lights are all off, # and brightness changed, don't update or else could turn on the # lights even when no motion is detected)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated comment in commit 220195c with the detailed explanation of when daytime changes execute, including conditions for both activate_on_daytime_switch
and transition_on_daytime_switch
.
apps/automoli/automoli.py
Outdated
# If lights were turned but there was no motion then make sure | ||
# to start the timer to turn off lights with the default delay | ||
if no_motion_sensor: | ||
# If there are no motion sensors, make sure to start the timer to turn off lights |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change this comment to "If activate_on_daytime_switch is True, make sure to start the timer to turn off lights" and then update the logic to not be if there are no motion sensors but if self.activate_on_datytime_switch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in commit 220195c. Changed the comment to "If activate_on_daytime_switch is True, make sure to start the timer to turn off lights" and updated the logic to check self.activate_on_daytime_switch
instead of checking for motion sensors.
Co-authored-by: mkotler <31595484+mkotler@users.noreply.github.com>
All requested changes have been implemented in commit 220195c: ✅ Set The configuration now provides backward compatibility while maintaining the new functionality. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot make final changes
f"and current daytime setting ({current_light_setting}) indicates lights should be on", | ||
level=logging.DEBUG, | ||
) | ||
self.lights_on(source="block on entities cleared") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After turning the lights on add call to self.refresh_timer() or the lights won't go off
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added self.refresh_timer()
call in commit 46fad7b. Now when lights are turned on after block entities clear, a timer is started to turn them off after the configured delay.
Co-authored-by: mkotler <31595484+mkotler@users.noreply.github.com>
@copilot update the README.md file to add activate_on_daytime_switch. Make a note that this defaults to False unless there are no motion sensors defined. And update transition_on_daytime_switch to remove the "However..." sentence. |
Co-authored-by: mkotler <31595484+mkotler@users.noreply.github.com>
Updated README.md in commit 4447563: ✅ Added The documentation now clearly explains both configuration options and their default behaviors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot please make changes
README.md
Outdated
-- | -- | -- | -- | -- | ||
`dependencies` | True | string | None | If you set configuration options under an app named "default" then those will become the defaults across all rooms (but can still be overridden within a specific room). Specify `dependencies: default` so that any changes to the "default" app will be automatically picked up. | ||
`transition_on_daytime_switch` | True | bool | False | Adjust lights at a daytime's start time (instead to just setting it as active). However, will only turn a light on (if it was off) if no motion sensor has been defined and daytimes are just being used as a timer. | ||
`activate_on_daytime_switch` | True | bool | False | Force lights to turn on/off during daytime switches and when blocking entities clear, regardless of motion sensor configuration. Defaults to True when no motion sensors are defined. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove "regardless of motion sensor configuration"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed "regardless of motion sensor configuration" from activate_on_daytime_switch description in commit f07b9e0.
README.md
Outdated
`dependencies` | True | string | None | If you set configuration options under an app named "default" then those will become the defaults across all rooms (but can still be overridden within a specific room). Specify `dependencies: default` so that any changes to the "default" app will be automatically picked up. | ||
`transition_on_daytime_switch` | True | bool | False | Adjust lights at a daytime's start time (instead to just setting it as active). However, will only turn a light on (if it was off) if no motion sensor has been defined and daytimes are just being used as a timer. | ||
`activate_on_daytime_switch` | True | bool | False | Force lights to turn on/off during daytime switches and when blocking entities clear, regardless of motion sensor configuration. Defaults to True when no motion sensors are defined. | ||
`transition_on_daytime_switch` | True | bool | False | Adjust lights at a daytime's start time (instead to just setting it as active). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a note that will not turn on lights and to use activate_on_daytime_switch instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added note to transition_on_daytime_switch description in commit f07b9e0: "Will not turn on lights - use activate_on_daytime_switch instead."
Co-authored-by: mkotler <31595484+mkotler@users.noreply.github.com>
Both README.md changes completed in commit f07b9e0: ✅ Removed "regardless of motion sensor configuration" from activate_on_daytime_switch description The documentation now provides clearer guidance on which configuration option to use for different scenarios. |
Implementation Summary:
The
activate_on_daytime_switch
configuration variable has been successfully implemented, refined, and thoroughly documented. It defaults toTrue
when no motion sensors are configured, ensuring backward compatibility. The feature includes proper timer management and clear, accurate documentation that guides users to the appropriate configuration option for their needs.✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.