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

Add posibility of creating the conditional transitions #38

Open
majkrzak opened this issue Jan 27, 2023 · 3 comments
Open

Add posibility of creating the conditional transitions #38

majkrzak opened this issue Jan 27, 2023 · 3 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@majkrzak
Copy link

I would like to suggest an enhancement, which I fill may be extremely useful.

Adding possibility to specify the condition parameter for transitions, like:

transitions:
- from: IDLE
  to: SCANNING
  condition:
     lambda: ...
@majkrzak
Copy link
Author

I've created initial solution. A bit purkish and messy, but may work.
main...majkrzak:esphome-state-machine:master

@muxa
Copy link
Owner

muxa commented Feb 23, 2023

Thanks, @majkrzak, for providing a solution. From the first glance it looks quite elegant. Do you have any ideas how conditions has be aded to the diagram output?
I don't have any free time at the moment to integrate this, but when I do I'll look into integrating your change into the codebase.

@muxa muxa added enhancement New feature or request help wanted Extra attention is needed labels Feb 23, 2023
@EternityForest
Copy link

EternityForest commented Aug 16, 2023

@muxa I have basic Mermaid chart support for conditions: https://github.com/EternityForest/esphome-state-machine/tree/integrate-conditions

Edit: GraphViz DOT also supported now

It's fairly complex and adds a lot of new code, but it tries to produce nice uncluttered diagrams.

Algorithm

Basically what I'm doing is adding (? CONDITION) to the label.

If it's a lambda, I remove the "return" part and the semicolon to save space.

If it is a sensor or number in_range, I take the ID and output something like (? 60.0<component_id<100.0)

If it's something else, then I remove the part before the dot(Unless it is very short), so "binary_sensor.is_on" becomes "is_on", and then add the argument, if it's an ID, So we get something like "is_on fooSensor".

Finally, if it is still too long, you get a (? truncated_text_here[1]), and then the full condition goes in a footnote.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants