Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#######################################################################################################################
## Package - Device Trackers
#######################################################################################################################
homeassistant:
customize:
alert.system_network_device:
icon: mdi:devices
category: system
device_tracker.jason_tracker:
icon: mdi:map-marker-circle
device_type: location
device_tracker.sheri_tracker:
icon: mdi:map-marker-circle
device_type: location
device_tracker.jphone:
device_type: location
device_tracker.sphone:
device_type: location
device_tracker.google_maps_xx:
device_type: location
device_tracker.google_maps_xx:
device_type: location
device_tracker.jphone_ping:
device_type: ping
device_tracker.sphone_ping:
device_type: ping
device_tracker.jlaptop_wifi_ping:
device_type: ping
device_tracker.sphone_bt:
device_type: bluetooth
device_tracker.jlaptop_bt:
device_type: bluetooth
device_tracker.stablet_bt:
device_type: bluetooth
device_tracker.fugoo_speaker_bt:
device_type: bluetooth
device_tracker.sheri_headphones_bt:
device_type: bluetooth
device_tracker.jason_headphones_bt:
device_type: bluetooth
device_tracker.laundry_room_speaker_bt:
device_type: bluetooth
device_tracker.living_room_speaker_bt:
device_type: bluetooth
device_tracker.bathroom_speaker_bt:
device_type: bluetooth
device_tracker.bedroom_display_bt:
device_type: bluetooth
device_tracker.dining_room_display_bt:
device_type: bluetooth
device_tracker.garage_speaker_bt:
device_type: bluetooth
device_tracker.jrouter:
device_type: wired
device_tracker.network_switch:
device_type: wired
device_tracker.upstairs_wifi_ap:
device_type: wired
device_tracker.lorex_nvr:
device_type: wired
device_tracker.myq_bridge:
device_type: wired
device_tracker.lutron_bridge:
device_type: wired
device_tracker.ipcam_ch1:
device_type: wired
device_tracker.ipcam_ch11:
device_type: wired
device_tracker.ipcam_ch12:
device_type: wired
device_tracker.jlaptop_wifi:
device_type: wireless
device_tracker.jphone_wifi2:
device_type: wireless
device_tracker.jphone_wifi5:
device_type: wireless
device_tracker.sphone_wifi:
device_type: wireless
device_tracker.stablet_wifi:
device_type: wireless
device_tracker.nest_thermostat_wifi:
device_type: wireless
device_tracker.upstairs_protect_wifi:
device_type: wireless
device_tracker.downstairs_protect_wifi:
device_type: wireless
device_tracker.living_room_speaker_wifi:
device_type: wireless
device_tracker.bathroom_speaker_wifi:
device_type: wireless
device_tracker.laundry_room_speaker_wifi:
device_type: wireless
device_tracker.garage_speaker_wifi:
device_type: wireless
device_tracker.dining_room_display_wifi:
device_type: wireless
device_tracker.bedroom_display_wifi:
device_type: wireless
device_tracker.living_room_tv_wifi:
device_type: wireless
device_tracker.deck_tv_wifi:
device_type: wireless
device_tracker.bedroom_tv_wifi:
device_type: wireless
device_tracker.lg_fridge_wifi:
device_type: wireless
device_tracker.lg_dishwasher_wifi:
device_type: wireless
device_tracker.hydrawise_wifi:
device_type: wireless
device_tracker.balboa_spa_wifi:
device_type: wireless
# Guest Devices
device_tracker.dawn_iphone_wifi:
device_type: wireless
device_tracker.lucy_iphone_wifi:
device_type: wireless
device_tracker.dawn_ipad:
device_type: none
device_tracker:
#######################################################################################################################
## Device Tracking
## https://www.home-assistant.io/components/device_tracker/
#######################################################################################################################
#######################################################################################################################
## NMAP Tracker
## https://www.home-assistant.io/integrations/nmap_tracker/
#######################################################################################################################
- platform: nmap_tracker
hosts: 192.168.1.0/24 # complete local subnet
#OPTION hosts: # wired network only
home_interval: 1
exclude:
- !secret HASSIO_IP
scan_options: -F –host-timeout 5s
#######################################################################################################################
## GLOBAL DEFAULTS - place after first instantiated tracker
#######################################################################################################################
consider_home: 60 # seconds after not seen for away state
interval_seconds: 120 #NOTE scanning whole network this times out if left at default 00:12 - rpi slow
new_device_defaults:
track_new_devices: true
#######################################################################################################################
## Bluetooth Tracker
## https://www.home-assistant.io/components/device_tracker.bluetooth_tracker/
#######################################################################################################################
- platform: bluetooth_tracker
request_rssi: true
#######################################################################################################################
## Ping Tracking
## https://www.home-assistant.io/integrations/ping/
#######################################################################################################################
- platform: ping
hosts:
jphone_ping: !secret JPHONE_IP
sphone_ping: !secret SPHONE_IP
jlaptop_ping: !secret JLAPTOP_IP
jlaptop_wifi_ping: !secret JLAPTOP_WIFI_IP
#######################################################################################################################
## Unifi # - Use either unifi OR unifi direct - unifi direct doesn't require unifi controller
## https://www.home-assistant.io/components/device_tracker.unifi/
## https://www.home-assistant.io/components/device_tracker.unifi_direct/
#######################################################################################################################
- platform: unifi_direct
host: !secret UNIFI_IP
username: !secret UNIFI_DIRECT_AP_USERNAME
password: !secret UNIFI_DIRECT_AP_PASSOWRD
#######################################################################################################################
## Google Maps
## https://www.home-assistant.io/components/device_tracker.google_maps/
#######################################################################################################################
- platform: google_maps
username: !secret J2_GMAIL_EMAIL
max_gps_accuracy: 200
#######################################################################################################################
## Composite Device Trackers # https://github.com/pnbruckner/ha-composite-tracker
## - Away is 'not_home'
## - Home is 'home' in states
#######################################################################################################################
- platform: composite
name: Jason Tracker
time_as: device_or_local
require_movement: false
entity_id:
- device_tracker.jphone
- device_tracker.jphone_ping
- device_tracker.jphone_wifi2
- device_tracker.jphone_wifi5
- device_tracker.jphone_bt
- device_tracker.google_maps_xx
- platform: composite
name: Sheri Tracker
time_as: device_or_local
require_movement: false
entity_id:
- device_tracker.sphone
- device_tracker.sphone_ping
- device_tracker.sphone_wifi
- device_tracker.sphone_bt
- device_tracker.google_maps_xx
binary_sensor:
- platform: template
sensors:
#######################################################################################################################
## Network Device Alert (unknown/new device)
#######################################################################################################################
network_device_alert:
unique_id: network_device_alert
value_template: "{{ states('sensor.unknown_devices_total')|int > 0 and is_state('binary_sensor.alerts_enabled','on') }}"
sensor:
- platform: template
sensors:
#######################################################################################################################
## Unknown Network Devices
#######################################################################################################################
unknown_devices_total:
unique_id: unknown_devices_total
icon_template: mdi:router-wireless
value_template: "{{ states.device_tracker|selectattr('attributes.device_type','eq',null)|list|count }}"
attribute_templates:
devices: "{{ states.device_tracker|selectattr('attributes.device_type','eq',null)|map(attribute='entity_id')|list }}"
unknown_devices_online:
friendly_name: Unknown Devices
unique_id: unknown_devices_online
icon_template: mdi:devices
value_template: >
{{ states.device_tracker|selectattr('attributes.device_type','eq',null)
|selectattr('state','eq','home')|list|count -}}/{{- states('sensor.unknown_devices_total') }}
#######################################################################################################################
## Wireless Network Devices
#######################################################################################################################
wireless_devices_total:
unique_id: wireless_devices_total
icon_template: mdi:router-wireless
value_template: "{{ states.device_tracker|selectattr('attributes.device_type','eq','wireless')|list|count }}"
wireless_devices_online:
friendly_name: Wireless Devices
unique_id: wireless_devices_online
icon_template: mdi:router-wireless
value_template: >
{{ states.device_tracker|selectattr('attributes.device_type','eq','wireless')
|selectattr('state','eq','home')|list|count -}}/{{- states('sensor.wireless_devices_total') }}
#######################################################################################################################
## Wired Network Devices
#######################################################################################################################
wired_devices_total:
unique_id: wired_devices_total
icon_template: mdi:devices
value_template: "{{ states.device_tracker|selectattr('attributes.device_type','eq','wired')|list|count }}"
wired_devices_online:
friendly_name: Wired Devices
unique_id: wired_devices_online
icon_template: mdi:server
value_template: >
{{ states.device_tracker|selectattr('attributes.device_type','eq','wired')
|selectattr('state','eq','home')|list|count -}}/{{- states('sensor.wired_devices_total') }}
#######################################################################################################################
## Bluetooth Devices
#######################################################################################################################
bluetooth_devices_total:
unique_id: bluetooth_devices_total
icon_template: mdi:devices
value_template: "{{ states.device_tracker|selectattr('attributes.device_type','eq','bluetooth')|list|count }}"
bluetooth_devices_online:
friendly_name: Bluetooth Devices
unique_id: bluetooth_devices_online
icon_template: "{{ 'mdi:bluetooth' if is_state('binary_sensor.bluetooth_alert','off') else 'mdi:bluetooth-off' }}"
value_template: >
{{ states.device_tracker|selectattr('attributes.device_type','eq','bluetooth')
|selectattr('state','eq','home')|list|count -}}/{{- states('sensor.bluetooth_devices_total') }}
#######################################################################################################################
## Alert - Network Device
#######################################################################################################################
alert:
system_network_device:
name: Unknown Device
title: Unknown Network Device
message: >
{%- if states.sensor.unknown_devices_total.attributes.devices is defined -%}
{%- if states('sensor.unknown_devices_total')|int == 0 -%}
No unknown devices.
{%- else -%}
{%- for device in state_attr('sensor.unknown_devices_total','devices') -%}
- {{ device }}{%- if not loop.last -%}<br>{%- endif -%}
{%- endfor -%}
{%- endif -%}
{%- endif -%}
entity_id: binary_sensor.network_device_alert
state: 'on'
repeat: 60
can_acknowledge: true
skip_first: false
notifiers: mobile_app_jphone
data:
subject: There are unknown network devices.
tag: network_device
group: System
channel: Alert
importance: high
vibrationPattern: '200, 200, 200, 200, 200, 200, 200'
ledColor: !secret WARNING_COLOR
priority: high
ttl: 0
timeout: 3600
persistent: false
sticky: false
clickAction: /lovelace/system
color: !secret WARNING_COLOR
icon_url: !secret HASSIO_ICON
actions:
- action: pause_network_device_alert
title: Pause
automation:
#######################################################################################################################
## System -Network Device Alert
#######################################################################################################################
- id: system_network_device_alert
alias: "[System] Network Device Alert"
description: Play announcement when alert is active.
initial_state: true
mode: single
trigger:
- platform: state
entity_id: alert.system_network_device
to: 'on'
action:
- service: persistent_notification.create
data:
title: Unknown Network Device
message: >
{%- if states.sensor.unknown_devices_total.attributes.devices is defined -%}
{%- if states('sensor.unknown_devices_total')|int == 0 -%}
No unknown devices.
{%- else -%}
There are an unknown devices on the network.
{% for device in state_attr('sensor.unknown_devices_total','devices') %}
- {{ device }}
{%- endfor -%}
{%- endif -%}
{%- endif -%}
notification_id: network_device
- service: script.tts_announcement
data:
play_message: |
Attention!
There is an unknown device on the network.
#######################################################################################################################
## System - Close Network Device Notifications
#######################################################################################################################
- id: system_close_network_device_notifications
alias: "[System] Close Network Device Notifications"
description: Dismiss notifications on all devices.
initial_state: true
mode: single
max_exceeded: silent
trigger:
- platform: state
entity_id: alert.system_network_device
to:
- idle
- 'off'
#BUG from_state of dismissed persistent notifcations is unknown, use state_changed event
- platform: event
event_type: state_changed
event_data:
entity_id: persistent_notification.network_device
- platform: event
event_type: mobile_app_notification_cleared
event_data:
tag: network_device
- platform: event
event_type: mobile_app_notification_action
event_data:
action: pause_network_device_alert
condition:
#BUGFIX conditions required as workaround for unknown persistent notification state
- condition: or
conditions:
- "{% if trigger.entity_id is defined %}{{ trigger.entity_id == 'alert.system_network_device' and states('alert.system_network_device') in ['idle','off'] }}{% endif %}"
- "{% if trigger.event is defined %}{{ trigger.event.data['tag'] == 'network_device' }}{% endif %}"
- "{% if trigger.event is defined %}{{ trigger.event.data['action'] == 'pause_network_device_alert' }}{% endif %}"
- "{% if trigger.event is defined %}{{ trigger.event.event_type == 'state_changed' and not is_state('persistent_notification.network_device','notifying') }}{% endif %}"
action:
- service: script.close_notifications
data:
target: mobile_app_jphone
category: system
tag: network_device
pause: "{% if trigger.event is defined %}{{ trigger.event.data['action'] == 'pause_network_device_alert' }}{% endif %}"
- delay:
seconds: 180 # prevent recursive triggers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment