A small tool to help me working with the Finite State Machine Sensor for Home Assistant by generating a png and converting the definition between JSON and YAML.
See https://github.com/edalquist/ha_state_machine for the Sensor.
- write your definition in YAML instead of JSON
- convert from YAML to JSON and back
- generate an image of the state machine using graphviz
initial:
a: state2
b: state3
state2:
a: initial
b: state3
state3:
a: initial
b: state2Note that in yaml the first state is the default/initial state.
$ hasmtool example.yaml example.json
{
"state": {
"status": "initial"
},
"transitions": {
"initial": {
"a": "state2",
"b": "state3"
},
"state2": {
"a": "initial",
"b": "state3"
},
"state3": {
"a": "initial",
"b": "state2"
}
}
} $ hasmtool example.json example.png
source: https://github.com/edalquist/ha_state_machine/blob/main/example.json
{
"state": {
"status": "IDLE"
},
"transitions": {
"IDLE": {
"above": "STARTING"
},
"STARTING": {
"timeout": { "after": 6, "to": "RUNNING" },
"below": "IDLE"
},
"RUNNING": {
"below": "STOPPING"
},
"STOPPING": {
"timeout": { "after": 15, "to": "DONE" },
"above": "RUNNING",
"middle": "RUNNING"
},
"DONE": {
"timeout": { "after": 15, "to": "IDLE" }
}
}
}Working MVP.
It started with the desire to have a visualization of the FSM, then I realised I like yaml more than json for it, so one thing led to another...

