uvjim / linksys_velop

Home Assistant integration for the Linksys Velop
MIT License
50 stars 7 forks source link

New device alert code from readme produces error messages #380

Closed dredjohn21 closed 1 year ago

dredjohn21 commented 1 year ago

I tried to create an automation to alert based on new device per readme and copy pasted:


alias: 'Notify: New Device on Mesh'
description: ''
trigger:
  - platform: event
    event_type: linksys_velop_new_device_on_mesh
condition: []
action:
  - service: persistent_notification.create
    data:
      notification_id: >-
        linksys_velop_new_device_{{
        trigger.event.data.connected_adapters[0].get('mac', 'N/A') }}
      title: 🆕 Device Found
      message: >-
        <b>{{ trigger.event.data.name }}</b>

        |   |   |   |

        |---|---|---| {% if trigger.event.data.mesh_device_id is not none %}

        |Mesh:|&emsp;|{{ device_attr(trigger.event.data.mesh_device_id,
        'name_by_user') or device_attr(trigger.event.data.mesh_device_id,
        'name') }}| {% endif %} {% if trigger.event.data.parent_name is not none
        %}

        |Parent:|&emsp;|{{ trigger.event.data.parent_name }}| {% endif %} {% if
        trigger.event.data.connected_adapters is not none %}

        |Guest:|&emsp;|{{ 'Yes' if
        trigger.event.data.connected_adapters[0].get('guest_network', False) is
        eq true else 'No' }}|

        |IP:|&emsp;|{{ trigger.event.data.connected_adapters[0].get('ip', 'N/A')
        }}|

        |MAC:|&emsp;|{{ trigger.event.data.connected_adapters[0].get('mac',
        'N/A') }}| {% endif %} {% if trigger.event.data.description is not none
        %}

        |Description:|&emsp;|{{ trigger.event.data.description }}| {% endif %}
        {% if trigger.event.data.manufacturer is not none %}

        |Manufacturer:|&emsp;|{{ trigger.event.data.manufacturer }}| {% endif %}
        {% if trigger.event.data.model is not none %}

        |Model:|&emsp;|{{ trigger.event.data.model }}| {% endif %} {% if
        trigger.event.data.serial is not none %}

        |Serial:|&emsp;|{{ trigger.event.data.serial }}| {% endif %} {% if
        trigger.event.data.operating_system is not none %}

        |Operating System:|&emsp;|{{ trigger.event.data.operating_system }}| {%
        endif %}
mode: parallel

Unfortunately I get an error message in the logs when I add a new Wi-Fi device:

extra keys not allowed @ data['notification_id']

Any tips and tricks on how to get working?

uvjim commented 1 year ago

Thos examples need updating actually because I changed the event format a while ago.

This is what I use in my setup and it seems to work.

alias: "Notify: Velop Information"
description: ""
trigger:
  - platform: event
    event_type: linksys_velop_event
    event_data:
      subtype: new_device
    id: Device Found
    alias: When new device is found
  - platform: event
    event_type: linksys_velop_event
    event_data:
      subtype: new_node
    id: Node Found
    alias: When new node is found
  - platform: event
    event_type: linksys_velop_event
    event_data:
      subtype: new_primary_node
    id: Primary Node Changed
    alias: When primary node has changed
  - platform: event
    event_type: linksys_velop_event
    event_data:
      subtype: logging_stopped
    id: Logging Stopped
    alias: When logging has stopped
condition: []
action:
  - variables:
      title_prefix: "Linksys Velop - "
  - if:
      - condition: template
        value_template: "{{ trigger.id in [\"Logging Stopped\"] }}"
    then:
      - variables:
          notification_id: logging_stopped
          message: Logging has stopped for {{ trigger.event.data.get('name') }}
      - service: persistent_notification.create
        data:
          notification_id: "{{ notification_id }}"
          title: "{{ title_prefix }}{{ trigger.id }}"
          message: "{{ message }}"
    else:
      - variables:
          notification_id: >-
            {{ trigger.event.event_type }}_{{
            trigger.event.data.get('unique_id') or
            trigger.event.data.get('serial') }}
          message: >-
            {% if trigger.event.data.get('name') is not none %}
              ## {{ trigger.event.data.name }}
            {% endif %}

            |   |   |   |

            |---|---|---| {% if trigger.event.data.get('mesh_device_id') is not
            none %}

            |Mesh:|&emsp;|{{ device_attr(trigger.event.data.mesh_device_id,
            'name_by_user') or device_attr(trigger.event.data.mesh_device_id,
            'name') }}| {% endif %} {% if trigger.event.data.get('parent_name')
            is not none %}

            |Parent:|&emsp;|{{ trigger.event.data.parent_name }}| {% endif %} {%
            if trigger.event.data.get('host') is not none %}

            |Host:|&emsp;|{{ trigger.event.data.host }}| {% endif %} {% if
            trigger.event.data.get('connected_adapters') is not none and
            trigger.event.data.get('connected_adapters') | count > 0 %}

            |Guest:|&emsp;|{{ 'Yes' if
            trigger.event.data.connected_adapters[0].get('guest_network', False)
            is eq true else 'No' }}|

            |IP:|&emsp;|{{ trigger.event.data.connected_adapters[0].get('ip',
            'N/A') }}|

            |MAC:|&emsp;|{{ trigger.event.data.connected_adapters[0].get('mac',
            'N/A') }}| {% endif %} {% if trigger.event.data.get('description')
            is not none %}

            |Description:|&emsp;|{{ trigger.event.data.description }}| {% endif
            %} {% if trigger.event.data.get('manufacturer') is not none %}

            |Manufacturer:|&emsp;|{{ trigger.event.data.manufacturer }}| {%
            endif %} {% if trigger.event.data.get('model') is not none %}

            |Model:|&emsp;|{{ trigger.event.data.model }}| {% endif %} {% if
            trigger.event.data.get('serial') is not none %}

            |Serial:|&emsp;|{{ trigger.event.data.serial }}| {% endif %} {% if
            trigger.event.data.get('operating_system') is not none %}

            |Operating System:|&emsp;|{{ trigger.event.data.operating_system }}|
            {% endif %}
      - service: persistent_notification.create
        data:
          notification_id: "{{ notification_id }}"
          title: "{{ title_prefix }}{{ trigger.id }}"
          message: "{{ message }}"
mode: parallel
dredjohn21 commented 1 year ago

Worked perfectly - thank you!!!!! This is such a helpful integration.

uvjim commented 1 year ago

README updated now. The automation above was already in there so I've removed the offending bad ones.

dredjohn21 commented 1 year ago

Thank you!