Skip to content

Instantly share code, notes, and snippets.

@aschamberger
Last active October 31, 2023 07:24
Show Gist options
  • Save aschamberger/0ab0bd03561288cbb2ab079cad8f8a86 to your computer and use it in GitHub Desktop.
Save aschamberger/0ab0bd03561288cbb2ab079cad8f8a86 to your computer and use it in GitHub Desktop.
blueprint:
name: SNMP - trap deactivates lan port
description: Recieved SNMP port down trap deactivates the LAN port to prevent
unauthorized change of LAN devices.
domain: automation
input:
source_ip:
name: SNMP trap source IP address
description: IP address to distinguish multiple devices
selector:
text:
port_number:
name: LAN port number
description: The LAN port number that the entity is controlling.
selector:
number:
min: 1
max: 48
mode: box
port_entity:
name: LAN port entity
description: The LAN port entity that shall be controlled.
selector:
entity:
domain: switch
notify_device:
name: Mobile Device
description: Select a device that runs the official Home Assistant app to receive notifications. If you wish to notify a group of devices use the field below to override this selection. This can be left blank in that case
default: false
selector:
device:
integration: mobile_app
notify_group:
name: Notification Group
description: The name of the group to send notifications to. If set, this will override individual devices above.
default: ""
source_url: https://gist.github.com/aschamberger/0ab0bd03561288cbb2ab079cad8f8a86
mode: parallel
max_exceeded: silent
variables:
port_number: !input 'port_number'
port_entity: !input 'port_entity'
group: !input notify_group
group_target: "{{ group | lower | replace('notify.', '') | replace(' ','_') }}"
notify_device: !input 'notify_device'
trigger:
- platform: event
event_type: snmp_trap
event_data:
_trap_oid: 1.3.6.1.6.3.1.1.5.3
_source: !input 'source_ip'
id: snmp_trap
condition:
- condition: template
value_template: >-
{{ trigger.event.data["1.3.6.1.2.1.2.2.1.1."+port_number|string] is defined }}
action:
- service: switch.turn_off
data: {}
target:
entity_id: !input 'port_entity'
- choose:
- conditions: "{{ notify_device and not group_target }}"
sequence:
- device_id: !input notify_device
domain: mobile_app
type: notify
title: "SNMP port down trap notification"
message: "{{ state_attr(port_entity, 'friendly_name') }}"
- conditions: "{{ group_target }}"
sequence:
- service: "notify.{{ group_target }}"
data:
title: "SNMP port down trap notification"
message: "{{ state_attr(port_entity, 'friendly_name') }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment