šŸ›” Watchman - keeps track of missing entities and services in your config files

Is there anything in the config ignored options? How many entities are shown if you do what Tom suggests four posts above?

Hi There

This works for me, after some modification, to display missing services. Breaking out all of the lines is not required, it just helped me for clarity.

Markdown to display WatchMan report missing services ā€¦

  - type: markdown
    content: >-
      <h2>
      <ha-icon icon='mdi:shield-half-full'>
      </ha-icon>
      Services report
      </h2>
      <h3> Missing Services:
      {{ states.sensor.watchman_missing_services.state }}
      </h3>
            {%- for item in state_attr("sensor.watchman_missing_services","entities") %}
      <hr>
      <table>
      <tr>
      <td>
      {{ item.id }}
 
      <a title="{{item.occurrences}}">
      {{item.occurrences.split('/')[-1] }}
      </a>
      </td>
      </tr>
      </table>
      {%- endfor %}
    card_mod:
      style:
        ha-markdown:
          $: |
            ha-markdown-element:first-of-type hr{
              border-color: #303030;
            }
2 Likes

This worked or me. Thank you!

I have added a few things to make my Watchman Card more helpful to me:
Tracking the number of ZWave Devices alive vs. connected.
Tracking the number of Zigbee2MQTT devices.

sensor.yaml

  - platform: template
    sensors:
       count_zwave_devices:
        friendly_name: 'ZWave'
        icon_template: mdi:z-wave
        value_template: >
          {% set total = states|selectattr('object_id', 'search', 'node_status')|list|count %}
          {% set dead = states|selectattr('object_id', 'search', 'node_status')|selectattr('state', 'in', 'dead, unavailable, unknown') | list | count %}
          {{ total - dead }} Alive/{{ total }} Total

      count_zigbee_devices:
        friendly_name: 'Zigbee'
        icon_template: mdi:z-wave
        value_template: >
          {% set entities = integration_entities('mqtt') %}
          {% set ns = namespace(unique_ids = []) %}
          {% for entity in entities %}
            {% if device_id(entity) not in ns.unique_ids %}
              {% set ns.unique_ids = ns.unique_ids + [device_id(entity)] %}
            {% endif%}
          {% endfor %}
          {{ ns.unique_ids | count -2 }}  ## -2 was added for my config to be accurate, yours will differ. i have 2 mqtt devices that are not zigbee

Watchman Report Card:

<h2> <ha-icon icon='mdi:shield-half-full'></ha-icon> Watchman report</h2> <h3>Missing Entities: {{ states.sensor.watchman_missing_entities.state }} </h3> {%- for item in state_attr("sensor.watchman_missing_entities", "entities") %} <hr> <table><tr> <td> <ha-icon icon='mdi: {%- if item.state=="missing"-%}cloud-alert' {%- elif item.state=="unavail" -%}cloud-off-outline' {%- else-%}cloud-question' {%- endif -%} ></ha-icon> {{ item.id }} [{{item.state}}] <a title="{{item.occurrences}}"> {{item.occurrences.split('/')[-1].split(':')[0]}}</a> </td></tr></table> {%- endfor %}
<h2> <ha-icon icon='mdi:z-wave'></ha-icon> ZWave report</h2> <h3>Devices: {{ states.sensor.count_zwave_devices.state }}
<h2> <ha-icon icon='mdi:zigbee'></ha-icon> Zigbee report</h2> <h3>Devices: {{ states.sensor.count_zigbee_devices.state }}

image

3 Likes

Does anyone know why I keep getting an error trying to get Watchman to send me a telegram notification?

Trying via the developer panel caling the report service;

service: watchman.report
data:
  create_file: true
  send_notification: true
  service: notify.telegram
  data:
    parse_mode: html
  parse_config: true
  chunk_size: true
Logger: homeassistant.helpers.script.websocket_api_script
Source: custom_components/watchman/__init__.py:422
Integration: Watchman ([documentation](https://github.com/dummylabs/thewatchman), [issues](https://github.com/dummylabs/thewatchman/issues))
First occurred: 2:37:59 PM (2 occurrences)
Last logged: 2:38:31 PM

websocket_api script: Error executing script. Unexpected error for call_service at pos 1: the JSON object must be str, bytes or bytearray, not dict

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 451, in _async_step await getattr(self, handler)() File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 684, in _async_call_service_step await service_task File "/usr/src/homeassistant/homeassistant/core.py", line 1808, in async_call task.result() File "/usr/src/homeassistant/homeassistant/core.py", line 1845, in _execute_service await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)( File "/config/custom_components/watchman/__init__.py", line 240, in async_handle_report await async_report_to_notification( File "/config/custom_components/watchman/__init__.py", line 422, in async_report_to_notification data = {} if service_data is None else json.loads(service_data) File "/usr/local/lib/python3.10/json/__init__.py", line 339, in loads raise TypeError(f'the JSON object must be str, bytes or bytearray, ' TypeError: the JSON object must be str, bytes or bytearray, not dict

If anyone would like a Mushroom-ized version of this, I created one in my install:

type: custom:stack-in-card
title: Possible Issues
cards:
  - type: custom:auto-entities
    card:
      type: grid
      columns: 1
      square: false
    card_param: cards
    filter:
      template: >-
        {%- for item in
        state_attr("sensor.watchman_missing_entities","entities") -%}
          {{
            {
              'type': "custom:mushroom-template-card",
              'entity': item.id,
              'primary': item.state + ' ' + item.id,
              'secondary': item.occurrences,
              'icon_color': "red" if item.state == "missing" else "orange" if item.state == "unavail" else "yellow",
              'icon': "mdi:cloud-alert" if item.state == "missing" else "mdi:cloud-off-outline" if item.state == "unavail" else "mdi:cloud-question"
              }
            }},
        {%- endfor -%}

Looks like this:

image

7 Likes

I have managed to achieve this - a bit late but I hope it helps someone :slight_smile:


# https://github.com/custom-cards/flex-table-card
- type: custom:flex-table-card
  title: 'Watchman Missing Entities'
  entities:
    include: sensor.watchman_missing_entities
  columns:
  - name: Entity
    align: left
    data: entities
    modify: x.id
  - name: State
    align: left
    data: entities
    modify: x.state
  - name: Occurrences
    align: left
    data: entities
    modify: x.occurrences
1 Like

Is there a way to set up an automation that run only when one specific entity is marked as unavailable or missing? Iā€™ve tried using the following as a conditional template ā€œ{{ ā€˜camera.netatmo_cameraā€™ in state_attr(ā€˜sensor.watchman_missing_entitiesā€™, ā€˜entitiesā€™) }}ā€ but it is always false event when camera.netatmo_camera is listed under ID in state attributes

Hi,

I tried installing The Watchman and recieved the below error:

    https://github.com/dummylabs/thewatchman is not a valid add-on repository

Iā€™m running 2023.5.3

How did you install it? I have watchman and I didnā€™t need to add a repository to my add-on repositories.

From the github link you provided:

Quick start

  1. Go to the ā€œIntegrationsā€ section on HACS, click ā€œExplore and download repositoriesā€ and search for ā€œwatchmanā€, then click ā€œDownload this repository with HACSā€.
  2. Restart Home Assistant, go to Settings->Devices and Services->Add Integration and select Watchman integration. If integration not found, try to empty your browser cache and reload page.
  3. Go to Developer Tools ā†’ Services, type watchman and select Watchman: report service then press ā€œCall Serviceā€ button. Check watchman_report.txt file in your configuration directory.

Watchman is not an add-on. Itā€™s an integration.

you install it thru HACS and not the add-on store. HACS does not provide add-ons, only integrations.

Thanks ! Iā€™m new to HA and didnā€™t have HACS installed. I just did so and was then able to get Watchman installed as well.

Thank you, here is a bit modified version:

type: custom:flex-table-card
title: Watchman Missing Entities
entities:
  include: sensor.watchman_missing_entities
columns:
  - name: Entity
    data: entities
    modify: x.id
  - id: id_state
    name: State
    data: entities
    modify: x.state
  - name: Occurrences
    data: entities
    modify: x.occurrences.split(':')[0]
  - name: Lines
    data: entities
    modify: x.occurrences.split(':')[1]
sort_by: id_state

I myself prefer sorting by the ā€œOccurrencesā€ column:

    sort_by:
      - id_state
      - id_occurrences ##add this key to the corresponding column

Also, for me ā€œOccurrenceā€ is needed only for missing entities, then it may be done by this:

      - id: id_occurrences
        name: Occurrences
        data: entities
        modify: >-
          if(x.state == 'missing')
            x.occurrences.split(':')[0]
          else
            ''
      - name: Lines
        data: entities
        modify: >-
          if(x.state == 'missing')
            x.occurrences.split(':')[1]
          else
            ''

Also, for me it is better to have 3 separate lists for unavailable, unknown, missing; registered a FR for this.


A small remark: noticed a small assumption (absolutely not critical): only one ā€œoccurrenceā€ is reported for an ā€œentityā€, but an ā€œentityā€ may have several ā€œoccurrencesā€ (i.e. several files). Absolutely unimportant: a user may ā€œcleanupā€ missing entities in reported files, then ā€œre-watchā€ and check other files from a new report.

4 Likes

@scr, this is fantastic!

if my notification service is an email, what do I put in this section - just to show the whole report in the body of the email?

image

Thanks for any help in advance!

Iā€™ve been moving some of the yaml based items to helpers, but now I start to wonder: Does Watchman also report on helpers with missing entities, for instance a Threshold helper, template helper, etc with missing entities?

Depends on if Watchman monitors the ā€œcore.config_entriesā€ file.
In my observations, Watchman does not see when a new shiny UI-based template sensors become unavailable.
Off-topic: for me, see zero reasons to move my setup to UI-based helpers / templates.

Well, to give an example: I use thresholds a lot (is it dark outside so lights should go on and stuff like that). From the UI the threshold limits are accessible via the gui and do not require a restart when limits are changed. Also, they get displayed with the device they are linked to, it represents there as an entity same as the original ones. This makes navigation to those entities easier. And they can be assigned to an area, while the config version could not because it didnā€™t allow for a unique id.

1 Like

Yes, there are SOME advantages of UI-based config - but there are disadvantages as well, and for me the latter is more important now.
Sorry for off-topic.

Just looking at my Watchman integration
http://homeassistant.local:8123/hacs/repository/455174197
the graphics are missing.

This is a great tool, it really comes in handy when I am trying to rationalise entity names.

Is there a way with manually or using watchman to know if any entities used in the ui are missing?
ā€“ I typically decide to rename an entity, run watchman and see what it finds and then have to manually check all the dashboard pages for entity missing errors.