Home Assistant Network Alarm System

Hello Community,

I implemented an network alarm system to my Home Assistant instance. If a device on my network goes down Home Assistant is able to inform me about the issue.

Summary: if a major error appears (sensor in group major_error_group goes offline) the automation is triggered an set my “Warning Lamp” to red. Same with the minor_error_group but with yellow. If the system comes up again (the sensor is on again) the Lamp goes green.

States

  • sensor in the major_error_group becomes off state → major issue → lamp becomes red
  • sensor in the minor_error_group becomes off state → minor issue → light is going yellow - except a major error is still “unsolved” (“off”)
  • sensor in the major_error_group becomes on state again → major issue is solved (except there are more than one major issues) → lamp becomes green (except a minor issue is still there → lamp becomes yellow)
  • all sensors in both groups are online again → lamp goes green and after 2 sec. its turned off

For testing purposes I added two switches to simulate a major or a minor issue (no alarm system is finalized without extensive testing ;-)).

At the moment I created a dashboard for my alarm system:

Major Issue:

Minor Issue:

Major and Minor Issue:

With the help of the hacs auto entity card its possible to visualise the errors in your network. The Error-Code helps me to differentiate between the major and the minor issues. The Math behind:

major issue apears: errorcode is incremented by 2
minor issue apears: errorcode is incremented by 1
no major issues: errorcode is decremented by 2
no minor issues: errorcode is decremented by 1

errorcode >= 2: major issue
errorcode  = 1: minor issue 
errorcode  = 0: everything is ok

Instead of the lamp you can trigger a script or send a notification, … the possibilities are more or less endless. Check the code and the automation by yourself.

I hope you like this.

Kind Regards
Chewyf5

P.S.: No systems, network packets or esp’s where harmed during the development.

Configuration.yaml:

binary_sensor:
  - platform: group
    name: "major_error_group"
    entities:
      # add your sensor which causes a major issue
      - binary_sensor.internet_status
      - binary_sensor.simulate_major_error_inverted_state
    all: true

  - platform: group
    name: "minor_error_group"
    entities:
      # add your sensor which causes a minor issue
      - binary_sensor.logitech_media_server
      - binary_sensor.simulate_minor_error_inverted_state
    all: true

input_boolean:
  simulate_major_error:
    name: Simulate Major Error Input
    icon: mdi:alert

  simulate_minor_error:
    name: Simulate Minor Error Input
    icon: mdi:alert-decagram 

input_number:
  error_code:
    name: Error Code 
    icon: mdi:alert-octagon-outline
    max: 3
    min: 0

template:
  - binary_sensor:
      - name: major_error
        state: >
          {{ 
            is_state('binary_sensor.major_error_group', 'off') 
          }}
        device_class: problem

      - name: minor_error
        state: > 
          {{ 
            is_state('binary_sensor.minor_error_group', 'off') 
          }}
        device_class: problem

      # normaly 'on' means problem
      # so the input of input_boolean.simulate_major_error is inverted
      - name: simulate_major_error_inverted_state
        state: >
          {{ not is_state('input_boolean.simulate_major_error','on') }}

        
      # normaly 'on' means problem
      # so the input of input_boolean.simulate_minor_error is inverted
      - name: simulate_minor_error_inverted_state
        state: >
          {{ not is_state('input_boolean.simulate_minor_error','on') }}

Automation

alias: HA - Trigger Alarm 2
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.major_error
    from: "off"
    to: "on"
    id: major_problem
  - platform: state
    entity_id:
      - binary_sensor.major_error
    from: "on"
    to: "off"
    id: major_ok
  - platform: state
    entity_id:
      - binary_sensor.minor_error
    from: "off"
    to: "on"
    id: minor_problem
  - platform: state
    entity_id:
      - binary_sensor.minor_error
    from: "on"
    to: "off"
    id: minor_ok
  - platform: template
    value_template: |
      {{ states('input_number.error_code') | int(0) >= 2 }}
    id: error-code-red
    alias: "template: error code greater or equal 2 (red)"
  - platform: template
    value_template: |
      {{ states('input_number.error_code') | int(0) == 1 }}
    id: error-code-yellow
    alias: "template: error code equal 1 (Yellow)"
  - platform: template
    value_template: |
      {{ states('input_number.error_code') | int(0) == 0 }}
    id: error-code-green
    alias: "template: error code equal 0 (OK)"
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: major_problem
        sequence:
          - service: input_number.increment
            data: {}
            target:
              entity_id: input_number.error_code
          - service: input_number.increment
            data: {}
            target:
              entity_id: input_number.error_code
      - conditions:
          - condition: trigger
            id: major_ok
        sequence:
          - service: input_number.decrement
            data: {}
            target:
              entity_id: input_number.error_code
          - service: input_number.decrement
            data: {}
            target:
              entity_id: input_number.error_code
      - conditions:
          - condition: trigger
            id: minor_problem
        sequence:
          - service: input_number.increment
            data: {}
            target:
              entity_id: input_number.error_code
      - conditions:
          - condition: trigger
            id: minor_ok
        sequence:
          - service: input_number.decrement
            data: {}
            target:
              entity_id: input_number.error_code
      - conditions:
          - condition: trigger
            id: error-code-red
        sequence:
          - service: light.turn_on
            data:
              rgb_color:
                - 224
                - 27
                - 36
              brightness_pct: 75
            target:
              entity_id: light.espnode1
      - conditions:
          - condition: trigger
            id: error-code-yellow
        sequence:
          - service: light.turn_on
            data:
              rgb_color:
                - 246
                - 211
                - 45
              brightness_pct: 75
            target:
              entity_id: light.espnode1
      - conditions:
          - condition: trigger
            id: error-code-green
        sequence:
          - service: light.turn_on
            data:
              rgb_color:
                - 51
                - 209
                - 122
              brightness_pct: 75
            target:
              entity_id: light.espnode1
          - delay:
              hours: 0
              minutes: 0
              seconds: 2
              milliseconds: 0
          - service: light.turn_off
            data: {}
            target:
              entity_id: light.espnode1
mode: queued
max: 10
1 Like

I’m not great reading YAML so maybe its in the code and I missed it but how are you testing the sensors to see if they’re up or down?

@wgstarks - you are right, it is in the code:

i have to sensors that repesents the group: binary_sensor.major_issue and binary_sensor.minor_issue (template sensors). The automation is triggerd by the sensors going up and down (four of the seven triggers).

fill in the code to a home assistant test instance and have fun :wink:

Kind Regards
Chewy

I guess I didn’t phrase my question very well. If the device fails (loses network connection for example) how do you test for that?

Hi @wgstarks

I use some ping sensors. They are are added to the major/minor error group.

binary_sensor:
  - platform: group
    name: "major_error_group"
    entities:
      # add your sensor which causes a major issue
      - binary_sensor.internet_status
      - binary_sensor.simulate_major_error_inverted_state
    all: true

So if a device fails/the device is not pingable anymore, the group major/minor_error_group fails/goes off. A template sensor inverts the result of its respective group:

template:
  - binary_sensor:
      - name: major_error
        state: >
          {{ 
            is_state('binary_sensor.major_error_group', 'off') 
          }}
        device_class: problem

That triggers the automation.

Does this answer your question?