Counter warning/error - issue

I’m trying to use the counters to show the number of errors/warnings, but it’s not reporting anything?
I’m using the latest hass release 0.84.3 - Is anyone using these counters for error counting ?

- alias: 'Counter error'
  initial_state: True
  trigger:
  - platform: event
    event_type: system_log_event
    event_data:
      level: ERROR
  action:
    - service: counter.increment
      entity_id: counter.error

- alias: 'Counter warning'
  trigger:
    platform: event
    event_type: system_log_event
    event_data:
      level: WARNING
  action:
    service: counter.increment
    entity_id: counter.warning

image

anyone…?

Are you sure the shape of your event trigger is correct? What does the event data look like in the homeassistant.log file?

I have this in the log

2018-12-19 20:19:46 ERROR (MainThread) [homeassistant.helpers.service] Error rendering data template: UndefinedError: ‘dict object’ has no attribute ‘event’
2018-12-19 20:19:59 WARNING (Thread-8) [custom_components.sensor.plex_recently_added] Host 213.49.94.127 is not available
2018-12-19 20:20:03 ERROR (MainThread) [homeassistant.helpers.service] Error rendering data template: UndefinedError: ‘dict object’ has no attribute ‘event’
2018-12-19 20:20:04 ERROR (MainThread) [homeassistant.helpers.service] Error rendering data template: UndefinedError: ‘dict object’ has no attribute ‘event’
2018-12-19 20:20:04 ERROR (MainThread) [homeassistant.helpers.service] Error rendering data template: UndefinedError: ‘dict object’ has no attribute ‘event’
2018-12-19 20:20:05 ERROR (MainThread) [homeassistant.helpers.service] Error rendering data template: UndefinedError: ‘dict object’ has no attribute ‘event’

well that’s an error, doesn’t show the event data. That could be the cause of your problem. If you change the logging level to INFO you should be able to see the actual event data.

petro
still nothing, as per your advice

logger:
  default: INFO


2018-12-21 22:25:53 WARNING (MainThread) [homeassistant.loader] You are using a custom component for sensor.illuminance which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2018-12-21 22:25:53 INFO (MainThread) [homeassistant.loader] Loaded sensor.waze_travel_time from homeassistant.components.sensor.waze_travel_time
2018-12-21 22:25:53 INFO (MainThread) [homeassistant.loader] Loaded sensor.Places from custom_components.sensor.Places
2018-12-21 22:25:53 WARNING (MainThread) [homeassistant.loader] You are using a custom component for sensor.Places which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.

I think you may need to add debugging.

Try adding this to logger:

# Example configuration.yaml entry
logger:
  default: info
  logs:
    homeassistant.components.logger: debug
1 Like

yes, i do, and I think it is identical…

  - alias: Count warnings
    id: 'Count warnings'
#    initial_state: 'on'
    trigger:
      platform: event
      event_type: system_log_event
      event_data:
        level: WARNING
    action:
      service: counter.increment
      entity_id: counter.warning_counter

  - alias: Count errors
    id: 'Count errors'
#    initial_state: 'on'
    trigger:
      platform: event
      event_type: system_log_event
      event_data:
        level: ERROR
    action:
      service: counter.increment
      entity_id: counter.error_counter

even had to reset the restore state to not restore errors counted on restart:

counter:
  warning_counter:
    name: Warnings
    icon: mdi:alert
    restore: False
  error_counter:
    name: Errors
    icon: mdi:alert-circle
    restore: False

##########################################################################################
# Scripts
##########################################################################################

script:
  reset_error_counter:
    alias: 'Reset Error counter'
    sequence:
      service: counter.reset
      data:
        entity_id: counter.error_counter

  reset_warning_counter:
    alias: 'Reset Warning counter'
    sequence:
      service: counter.reset
      data:
        entity_id: counter.warning_counter

@elRadix sorry to warm this old thread up, but I just stumbled over the same problem.

The fix, in my case, was to add:

system_log:
  fire_event: true

to the configuration.yaml… and it started working :wink:

can you share your full config please :sweat_smile:

This is how it’s configured now:

system_log:
  fire_event: true

counter:
  homeassistant_errors:
    name: Errors
    icon: mdi:alert-octagram
    restore: false
  homeassistant_warnings:
    name: Warnings
    icon: mdi:alert
    restore: false

automation:
  - alias: Count Home Assistant errors
    trigger:
      platform: event
      event_type: system_log_event
      event_data:
        level: ERROR
    action:
      service: counter.increment
      entity_id: counter.homeassistant_errors

  - alias: Count Home Assistant warnings
    trigger:
      platform: event
      event_type: system_log_event
      event_data:
        level: WARNING
    action:
      service: counter.increment
      entity_id: counter.homeassistant_warnings

script:
  homeassistant_reset_error_counter:
    alias: 'Fehler zurück setzen'
    sequence:
      service: counter.reset
      data:
        entity_id: counter.homeassistant_errors

  homeassistant_reset_warning_counter:
    alias: 'Warnungen zurück setzen'
    sequence:
      service: counter.reset
      data:
        entity_id: counter.homeassistant_warnings
5 Likes

Is it possible to track errors/warnings during HA startup ?
2022.2.9 - my counters become incrementing some time after HA started.