Meshcore Contact Management (combining a template plus hold-action)

With my home-based node I am using the Meshcore Integration over IP. Because in my area the Meshcore mesh is pretty active (more people wanted to talk with others in stead of themselves) at one point in time you will need to do some contact management. This is my result to simplify this process. How does it look like?

You can find the complete how-to description on my github repository

Because I had a hard time to find the proper syntax for the template / (hold-)action combination I will highlight this also here:

type: custom:auto-entities
show empty: false
card:
  type: entities
filter:
  template: |-
    {% set time = now() | as_timestamp | int %} {% set type =
    states['input_select.meshcore_contact_type'].state[:1] |  int %} {% set
    days_old = states['input_number.meshcore_days_old'].state |  int %} {% set
    ignore_list = ['not', 'required' ] %} 

    {% set DEVICES = states.binary_sensor
      | rejectattr('entity_id', 'in', ignore_list)
      | selectattr('entity_id', 'search', 'meshcore')
      | selectattr('entity_id', 'search', '_contact')
      | selectattr('state', 'eq', 'stale') 
      | selectattr('attributes.type', 'eq', type )
      | selectattr('attributes.lastmod', 'lt', time - days_old*60*60*24)
      | sort(attribute='attributes.lastmod')
      | list  
    %}  
    {% if DEVICES | length > 0 %}
      [
      {% for DEVICE in DEVICES -%}
        {{{
          'entity': DEVICE.entity_id,
          'name': DEVICE.name,
          'hold_action': {
            'action':'call-service',
            'service' : 'script.meshcore_remove_contact_script',
            'service_data' : {
              'entity_id' : DEVICE.entity_id }}
              
        }}},
      {% endfor %}

Inside the official topic Auto-entities - Automatically fill cards with entities containing six years and over 1800 comments I found my inspiration in record #853 but first I required a more simplified example which would open doors for me, this was found in #893. Good examples are key to success.

1 Like