Skip to content
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

Scene overrides #5

Open
zoe-codez opened this issue Mar 18, 2024 · 1 comment
Open

Scene overrides #5

zoe-codez opened this issue Mar 18, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@zoe-codez
Copy link
Member

zoe-codez commented Mar 18, 2024

There needs to be some sort of mechanism of changing the definition of a scene in response to various situations. For example, I may want a "cozy" scene that is different based on the time of day. Less switches on at night, and dimmer.

The only way of handling that right now is by defining several different scenes, and using a "get the correct scene for this" function. That doesn't fix scenes listed on dashboards, which would bypass this mechanism. It also creates wildly inconsistent code, since there are many ways of tackling this problem.

Instead, this logic should be handled by the room to provide a centralized / standard way of creating this logic.

@zoe-codez zoe-codez added the enhancement New feature or request label Mar 18, 2024
@zoe-codez zoe-codez moved this to Backlog in Home Automation Mar 18, 2024
@zoe-codez
Copy link
Member Author

zoe-codez commented Mar 18, 2024

Concept Solution

Maintain the separate scene definitions, but add a method of altering the call as part of the room

function Example({ automation, context }: TServiceParams) {
  return automation.room({
    context,
    name: "room",
    scenes: {
      evening_high: { definition: {} },
      high: {
        definition: {},
        redirectTo() {
          if (!automation.solar.isBetween("dawn", "dusk")) {
            return "evening_high";
          }
          // anything not a scene name maps to "high"
        },
      },
      off: { definition: {} },
    },
  });
}

The intent being that only high gets listed / used in code logic / dashboards, but evening_high is part of the actual room definition. Any time high is set:

  • room current scene sensor should track the redirect target (evening_high) as an attribute, but report the scene used (high)
  • redirectTo should take inspiration from managed switches (shouldBeOn):
    • function must be sync
    • must return scene name, or undefined (high)
    • can take in an array of things to also update in response to

This gets checked on initial scene set, and will actively work to keep the scene with the best definition. Bonuses:

  • keeps alternate scene definitions available for manual calling
  • backwards compat

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
No open projects
Status: Backlog
Development

No branches or pull requests

1 participant