Graph your configuration

Here’s a demo: https://happyleavesaoc.github.io/hagraph.html (zoom and pan with your mouse)

This is a little project that takes your configuration.yaml and makes a graph based on the relationships between your components and entities. It’s a nice way to visualize your automations. I was able to identify many changes to make in my configuration based on what I saw on the graph.

I know this tool works on my config. It might not work on yours. If it doesn’t, paste the error here and if possible, link to your config.

16 Likes

Very cool… I’m getting an error when attempting to run:

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/site-packages/pygraphviz/agraph.py", line 1289, in _get_prog
    runprog = self._which(prog)
  File "/usr/local/lib/python3.5/site-packages/pygraphviz/agraph.py", line 1523, in _which
    raise ValueError("No prog %s in path." % name)
ValueError: No prog neato in path.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/local/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.5/site-packages/hagraph/__main__.py", line 30, in <module>
    main()
  File "/usr/local/lib/python3.5/site-packages/hagraph/__main__.py", line 26, in main
    to_agraph(graph).draw(args.get('output_file'), prog=args.get('prog'))
  File "/usr/local/lib/python3.5/site-packages/pygraphviz/agraph.py", line 1469, in draw
    data = self._run_prog(prog, args)
  File "/usr/local/lib/python3.5/site-packages/pygraphviz/agraph.py", line 1304, in _run_prog
    runprog = r'"%s"' % self._get_prog(prog)
  File "/usr/local/lib/python3.5/site-packages/pygraphviz/agraph.py", line 1291, in _get_prog
    raise ValueError("Program %s not found in path." % prog)
ValueError: Program neato not found in path.

You’re probably missing graphviz. Install that on your system and try again. I should add that to the install instructions.

hmm, pip install graphviz ran fine but same error

I think you have to install the graphviz package proper, not the python module.

So like:

yum install graphviz graphviz-devel

or

apt-get install graphviz graphviz-dev
1 Like

That did it, thanks! Also, the www folder… Should that exist already? I’m running in a docker container so the location differs a bit and I’m not seeing it.

Should it sit alongside the components folder?

It probably won’t exist yet. Make the www directory alongside your configuration.yaml.

so how does this work, does it read your yaml files or does it look at the events table in the history database? Just trying to decide if it would work for me since 90% of my automations are in AppDaemon and are driven by group memberships, not hard coded.

It reads your YAML files. You won’t get much out of it if you’re using AppDaemon.

I’ve successfully installed hagraph, however, when runnign it, I get the error ValueError: no server
Full trace:

Traceback (most recent call last):
  File "/usr/lib/python3.4/runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.4/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/PlexMediaServer/hass/lib/python3.4/site-packages/hagraph/__main__.py", line 30, in <module>
    main()
  File "/PlexMediaServer/hass/lib/python3.4/site-packages/hagraph/__main__.py", line 25, in main
    graph = make_graph(conf)
  File "/PlexMediaServer/hass/lib/python3.4/site-packages/hagraph/__init__.py", line 236, in make_graph
    add_core_edges(conf, graph)
  File "/PlexMediaServer/hass/lib/python3.4/site-packages/hagraph/__init__.py", line 200, in add_core_edges
    add_script(name, data, graph)
  File "/PlexMediaServer/hass/lib/python3.4/site-packages/hagraph/__init__.py", line 170, in add_script
    graph.add_edge(script_entity, target, label=get_service(step))
  File "/PlexMediaServer/hass/lib/python3.4/site-packages/hagraph/__init__.py", line 125, in get_service
    raise ValueError('no service')
ValueError: no service

Any ideas why this might happen? Also, my config is split up, maybe that’s why it doesn’t work?

It is fine to have a split config. It is failing to find a service in one of your scripts. If you post your script yaml, we can figure out why.

It’s better for me to post my HA repo, since it’s on Github: https://github.com/Tommatheussen/Home-Assistant-Configuration

I’ve added a quick print in the failing steps, it seems it fails on a dummy sensor I have, which only gets populated after I activated a script.
I’ve added the print at line 170 from init.py (printing the step), and it shows me this: OrderedDict([('condition', 'numeric_state'), ('entity_id', 'sensor.new_commits'), ('above', 1)])
perhaps it’s helpful to figure out the issue

EDIT, that step is shown here: https://github.com/Tommatheussen/Home-Assistant-Configuration/blob/master/script/get_latest_config.yaml#L4
EDIT 2: it seems that the condition is not recognized as a valid service in the sequence

Ah, I didn’t know conditions can be in script sequences.

If you want, you can temporarily fix it like such:

if const.ATTR_SERVICE not in step and 'service_template' not in step:
    continue

inserted after line 169 in hagraph's __init__.py

I’ll cut a new release with a proper fix as well.

1 Like

Will try that when I get home.
Btw, thanks for this, been meaning to visualize my connections for a while now :slight_smile:

It works!
I’m wondering, would it be possible to show items that are not connected to any other things?

Great, glad to hear it.

It is possible to show unconnected stuff. But that info is not very useful in a graph. What’s the use case?

1 Like

Well, since I only recently started with H and don’t have a lot of stuff to integrate yet, I’ve got some default and dummy stuff configured, but almost nothing is connected yet,
seeing these items as single entries in the graph would show that they are tracked as well (since they are configured after all).
Perhaps as an optional parameter to include those entries so it’s not included by default, that way people can choose wether they want it or not

Very interesting, thanks!

Wow!
It worked flawlessly, thanks!
It looks like a giant spider :grinning:

Wow, quite the config. What are those giant nodes? I guess those are service_templates?