Helping with templating

Hi,

I have synology router and HA integration is publishing a lot of interesting information from it.
One thing I would like to do is have an entity panel reporting for example signal strength of all devices connected ideally sorted by strength.

Sensor I have is a device_tracker one and attributes are as below example.
Having quite a lot of those if the template creation (which anyway I don’t know how to create and it is main reason of this post) could be automated it would be great.

Has anyone a suggestion?

source_type: router
scanner: SynologySrmDeviceScanner
band: 2.4G
connection: wifi
current_rate: 72
dev_type: others
hostname: *removed*
ip6_addr: 
ip_addr: *removed*
is_banned: false
is_beamforming_on: false
is_guest: false
is_high_qos: false
is_low_qos: false
is_manual_dev_type: false
is_manual_hostname: false
is_online: true
is_parental_controlled: false
is_qos: false
is_wireless: true
mac: *removed*
max_rate: 96
mesh_node_id: 0
rate_quality: high
signal_strength: 87
transfer_rx_rate: 0
transfer_tx_rate: 0
friendly_name: *removed*

Create a template sensor with an attribute from your device_tracker.

Hi,

Yes I see…I was wondering if I could do it in a more automated way: otherwise I will have to create 50+ sensors manually :frowning:

Use the template editor to build the yaml for you then copy/paste the result into your config.

mmm not very clear…my fault for sure as not being really a pro :slight_smile:

Paste this into developer tools -> template editor then copy the results into configuration.yaml. If you have a separate sensor file, remove the first line and paste the remainder. You may need to adjust the spacing.

sensor:
- platform: template
  sensors:
{%- for dt in states.device_tracker if dt.attributes.signal_strength is defined %}
    {{ dt.object_id }}_signal_strength:
      friendly_name: {{ dt.name }} Signal Strength
      value_template: >
        {{ "{{{{ state_attr('{}','signal_strength') }}}}".format(dt.entity_id) }}
      device_class: signal_strength
{%- endfor %}
1 Like