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

[FR] support conditional transitions. #6

Open
erkr opened this issue Oct 14, 2023 · 1 comment
Open

[FR] support conditional transitions. #6

erkr opened this issue Oct 14, 2023 · 1 comment

Comments

@erkr
Copy link

erkr commented Oct 14, 2023

I made some awsome state machines with your integration. The need for substates emerged 😎

The transitions package has support for conditional transitions. It would be great to have that exposed in this integration.
The conditional transitions in the package then have a callback. For the integration that probably becomes a little too exotic.
My proposal is to allow for an optional condition parameter in the statemachine definition. Like this:

  "transitions": {
    "IDLE": {
      "on": "STARTING",
      "high": {"condition"="is_flammable", "to": "HEATING" },
      "high": {"condition"="not is_flammable", "to": "ALARM" },

   }

The condition is_flammable could be added as a boolean attribute on the state machine sensor. And you could provide a service to set / get these attributes.
Maybe a conditions section can be aded to initialyze these attributes:

  "state": {
    "status": "IDLE"
  },
  "conditions": {
    "is_flammable": true,
    ...

  },
  "transitions": {
    ...

This would add support for a kind of sub states.

Best Eric

@erkr
Copy link
Author

erkr commented Oct 15, 2023

Update: thinking it over; adding Boolean attributes would work but still requires a lot of plumbing in the automation. Conditions based on the state of other entities is typically needed (ideally a template expression)

Use case example is a simple motion detection:

  • states: off, on, dimmed
  • But the conditions are triggering only at night and only if the light was not already on when motion is detected.

Modelling that in the state machine without conditions explodes the states and the triggers in the associated automation.

The conditions in this example just need to look up the state of sun.sun and the controlled light (for allowing the transition from off to on)

Best Eric

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant