Skip to main content

Visualize Home Assistant Finite State Machines

Project description

hasmtools

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.

Features

  • write your definition in YAML instead of JSON
  • convert from YAML to JSON and back
  • generate an image of the state machine using graphviz

Examples

YAML input file

initial:
  a: state2
  b: state3
state2:
  a: initial
  b: state3
state3:
  a: initial
  b: state2

Note that in yaml the first state is the default/initial state.

Converted to JSON

 $ hasmtool example.yaml example.json
{
    "state": {
        "status": "initial"
    },
    "transitions": {
        "initial": {
            "a": "state2",
            "b": "state3"
        },
        "state2": {
            "a": "initial",
            "b": "state3"
        },
        "state3": {
            "a": "initial",
            "b": "state2"
        }
    }
}

Finally converted to PNG

 $ hasmtool example.json example.png

State Machine rendered as png

An example with timeouts

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" }
    }
  }
}

FSM with timeouts

Status

Working MVP.

Why Did I Do This?

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...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hasmtools-0.0.3.tar.gz (90.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hasmtools-0.0.3-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file hasmtools-0.0.3.tar.gz.

File metadata

  • Download URL: hasmtools-0.0.3.tar.gz
  • Upload date:
  • Size: 90.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for hasmtools-0.0.3.tar.gz
Algorithm Hash digest
SHA256 d8471a1e1cc97e5e0b5c1fa7f3d42f3d25531fb14fb1f1183bbd3f81d692d6eb
MD5 e9bd4de0db22b2ccce57ffae0c9ff51a
BLAKE2b-256 84a280f59dbcd77403f3c1d65ace7e08a3cf7b8238423b8e998cac78f1bb3c14

See more details on using hashes here.

Provenance

The following attestation bundles were made for hasmtools-0.0.3.tar.gz:

Publisher: publish.yml on mutax/hasmtools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hasmtools-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: hasmtools-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for hasmtools-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 52f395258b46830d434d1d114f7eb810020b966339c829c1be9738a234ceb1a4
MD5 e7d1f518d4601610bd42e07998fff2e8
BLAKE2b-256 072159b0ba73c200f3ae36f5f632d7028b3ad55d72288d69cf413bb5e7bc80c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for hasmtools-0.0.3-py3-none-any.whl:

Publisher: publish.yml on mutax/hasmtools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page