🛡 Watchman - keeps track of missing entities and actions in your config files

Would like to present a custom integration to identify entities and services in your configuration files that either no longer exist or have a wrong state. Along with a few sensors, it may create a text version of the report or send it via notification service of choice.

Please don’t be afraid of the documentation volume, I’ve tried to keep the balance between versatility and simplicity of use during development, so all parameters are optional: GitHub - dummylabs/thewatchman: Home Assistant custom integration to keep track of missing entities and actions in your config files

Example of a Markdown Lovelace card:

Example of a text report:

-== WATCHMAN REPORT ==-  

-== Missing 1 service(-s) from 38 found in your config:
+--------------------------------+---------+------------------------------------------+
| Service                        | State   | Location                                 |
+--------------------------------+---------+------------------------------------------+
| xiaomi_miio.vacuum_goto        | missing | automations.yaml:599,605                 |
+--------------------------------+---------+------------------------------------------+

-== Missing 3 entity(-es) from 216 found in your config:
+--------------------------------+---------+------------------------------------------+
| Entity                         | State   | Location                                 |
+--------------------------------+---------+------------------------------------------+
| sensor.stats_pm25_10_median    | unavail | customize.yaml:14                        |
| sensor.xiaomi_miio_sensor      | unavail | automations.yaml:231,1348                |
| vacuum.roborock_s5max          | unavail | automations.yaml:589,603,610,1569        |
+--------------------------------+---------+------------------------------------------+

-== Report created on 03 Feb 2022 17:18:55
-== Parsed 200 files in 0.96s., ignored 66 files 
-== Generated in: 0.01s. Validated in: 0.00s.

New in version 0.5.0:

  • support of custom reports within a Lovelace card!
  • sensor.watchman_missing_entities and sensor.watchman_missing_services are now automatically updated when a relevant entity or service changes state

New in version 0.4.0:

  • UI options support. Existing yaml configuration will be imported upon the first run and can be safely removed afterwards
  • send_notification service parameter is set to false if omitted (breaking change)
  • default report file name changed to watchman.txt
  • a few minor improvements
46 Likes

Very liked the idea, thanks for sharing. I am scared what my system’s current state with report :slight_smile: too many problems might become visible

1 Like

I’d like this. I wonder if there is a way to programmatically delete entities.

Unfortunately, this seems to be impossible while watchman is using regular expressions to detect character sequences which looks like an entity or a service. To be able to safely remove an entry from a yaml file the integration should be able to analyze and interpret quite complex data structures as well as custom yaml tags like !include, !secret, and so on. This seems to be feasible, but makes parsing a much more difficult task.

I tried it by running just the “watchman.report” service with no service data:

image

and I’m getting the following result.

If I don’t specify a default notification service in the configuration.yaml I get an error:

image

and the report is never saved to the default text path.

If I do configure a default notification service in configuration.yaml the notification gets sent correctly and everything is listed there properly along with the correctly generated text file.

The issue is that I only want to create the text file and not get a notification when I use it.

What am I doing wrong?

The report gets created or updated even if you see this error message. Try to run service like this:

service: watchman.report
data:
  send_notification: false

Explanation: If send_notification service parameter wasn’t explicitly set to false, it is true by default, this why watchman complains about missing service parameter. I was thinking about default values for send_notification and create_file parameters, probably it is worth to have them false by default and require user to always specify either or both of them.

1 Like

Wow!

Thanks for this. None of these were false positives.

Missing 181 entity(-es) from 1178 found in your config:

It’s amazing what can creep in over a few years.

2 Likes

Simply brilliant, thank you :+1:t2:

1 Like

@scr Thank You so much for this Integration. It worked GREAT; I was able to clean up and rename some entities !!!

1 Like

I found a few misconfigured automations, a misnamed input_number, a whole bunch of old customizations that were no longer needed and some unnecessary logbook, history and recorder excludes.

2 Likes

This is fantastic - I’m almost embarrassed with the amount of broken stuff in my config!

Hey @scr,
this is the first time I hear about your integration… and I was searching for this function quite a few times.
Did you consider registering with HACS so your repo is automatically included in listings and therefore can be found via the search function? That would be most amazing.

Also, UI configuration and an entity holding all warnings as attribute would be great - no rush hahaha

This is superb, now I have had time to play with this I notice a few things that are probably user error but would love your input:

Config:

watchman: 
  check_lovelace: true
  startup_delay: 60
  ignored_files: 
    - /config/custom_components/*
  ignored_items: 
    - scene.* # ignore everything in scene domain 
  ignored_states:
    - unavailable
  columns_width: [30, 11, 60]

Section of report:

-== WATCHMAN REPORT ==-  

-== Missing 1 service(-s) from 50 found in your config:
+--------------------------------+-------------+--------------------------------------------------------------+
| Service ID                     | State       | Location                                                     |
+--------------------------------+-------------+--------------------------------------------------------------+
| switch.turn_                   | missing     | automations.yaml:29                                          |
+--------------------------------+-------------+--------------------------------------------------------------+

-== Missing 66 entity(-es) from 575 found in your config:
+--------------------------------+-------------+--------------------------------------------------------------+
| Entity ID                      | State       | Location                                                     |
+--------------------------------+-------------+--------------------------------------------------------------+
| switch.pc_hibernate            | unavail     | automations.yaml:199,807                                     |
| switch.laptop_shutdown         | unavail     | automations.yaml:798                                         |
| switch.pc_lock                 | unavail     | automations.yaml:815                                         |

The first service listed (there were a lot more but thanks to you, not any more :slight_smile: ) relates to a template switch turn on, is there any way to exclude template entries like this and or exclude this particular line from the yaml file I wonder?

Also under missing entities, I have a big long list of entities that are unavailable, mostly as they relate to MQTT sensors that spend most of their lives in this state, so as you can see I have tried to exclude “unavailable” in the config above, but they still show?

In trying to work this out I also set column widths to show state column as 11 (based on the longest state being “unavailable” at 11 characters) but it still shows “unavail” and not “unavailable”. I also tried putting exclude unavail in the config but obviously the yaml checker spits this out.

Am i doing something wrong can you see?

Thanks again, this is such a wonderful cleansing exercise.

Rossk

1 Like

Sure, PR was created a few days ago and waiting for approval.

Both features are in the backlog. The only problem with UI configuration - so far it has no support for nested data structures like notification service data, that is, part of configuration will remain in yaml.

1 Like

Awesome project, thanks a lot!!

Once added to ignored_items list it should be excluded from the report.

There can be a bug with unavailable state being used in ignored_states, please let me check it out.

So far this is by design (unavailable truncates to unavail) in order make the whole table narrower, there is no relation to the column width.

1 Like

About that. Wouldn’t it anyhow be better to go through a user automation instead of hard-wiring limited actions in the code of this integration!? Doesn’t feel very in-line with standard/normal integrations. I would certainly prefer a solution where your integration populated one or multiple entities, which I can then use in any kind of automation, as a lovelace card, as input for yet another integration, you name it.
For example, see the automation at the bottom of this file: unavailable-entities-sensor/package_unavailable_entities.yaml at c6af99d22eeac2abbd64cd1e4cd0266aebcf415c · jazzyisj/unavailable-entities-sensor · GitHub or the amazing waste collection integration GitHub - mampfes/hacs_waste_collection_schedule: Home Assistant integration framework for (garbage collection) schedules

please let me check it out.

I see the same issue

in order make the whole table narrower

Makes sense but I agree with @rossk, this is confusing.

What would you automate though?

You run the report, you get the results.

You can already automate running the report if you wish, you don’t have to call the service manually.

Current version of integration supports both use cases. You can set up everything in the configuration.yaml and use watchman.report service with no additional parameters. Or, you can specify extra parameters in service data which will take precedence over yaml.

The case makes sense for me and I have it in the backlog. Having only a set of bare entities/attributes will require user to figure out how to make a Lovelace card out of it instead of just get what they want. So there is a text version of the report to make leaning curve less steeper. I believe there should be a possibility to make a Lovelace card, but this shouldn’t be the only way to get information out of watchman.

Please don’t drop the option of a text version though. It’s a lot easier to copy/paste from.

3 Likes