Problem with values and entity_id in template for pfsense Mbps monitor

Hi Community,

after updating to the last ha version my template construct showing in/out traffic with snmp and template is not working anymore. I guess I have a problem with entity_id in sensor, but I don’t get to the right hook:

sensor:
  # -- Define the raw SNMP counters
  - platform: snmp
    name: pfSense NIC WAN In Counter Raw
    host: 192.xxxxx
    community: hassio
    baseoid: 1.3.6.1.2.1.2.2.1.10.2
  - platform: snmp
    name: pfSense NIC WAN Out Counter Raw
    host: 192.xxxxx
    community: hassio
    baseoid: 1.3.6.1.2.1.2.2.1.16.2
  # -- Define the statistics enabled counters
  - platform: statistics
    name: pfSense NIC WAN In Counter
    entity_id: sensor.pfsense_nic_wan_in_counter_raw
    sampling_size: 2
    max_age:
      minutes: 5
  - platform: statistics
    name: pfSense NIC WAN Out Counter
    entity_id: sensor.pfsense_nic_wan_out_counter_raw
    sampling_size: 2
    max_age:
      minutes: 5
  # -- Define the actual sensor templates you'll use
  - platform: template
    sensors:
      pfsense_nic_wan_in_mbps:
        icon_template: mdi:cloud-download-outline
        friendly_name: 'pfsense WAN Traffic In'
        unit_of_measurement: 'Mbps'
        **entity_id: sensor.pfsense_nic_wan_in_counter**
        value_template: >
          {% if state_attr('sensor.pfsense_nic_wan_in_counter','change_rate') > 0 %}
            {{ (((state_attr('sensor.pfsense_nic_wan_in_counter','change_rate')|float)*8)/1000000)|round(2) }}
          {% else  %}
            0
          {% endif %}
      pfsense_nic_wan_out_mbps:
        icon_template: mdi:cloud-upload-outline
        friendly_name: 'pfsense WAN Traffic Out'
        unit_of_measurement: 'Mbps'
        **entity_id: sensor.pfsense_nic_wan_out_counter**
        value_template: >
          {% if state_attr('sensor.pfsense_nic_wan_out_counter','change_rate') > 0 %}
            {{ (((state_attr('sensor.pfsense_nic_wan_out_counter','change_rate')|float)*8)/1000000)|round(2) }}
          {% else  %}
            0
          {% endif %}

The

sensor.pfsense_nic_wan_in_counter_raw
sensor.pfsense_nic_wan_out_counter_raw

are set,
also
sensor.pfsense_nic_wan_out_counter
sensor.pfsense_nic_wan_in_counter

but in the frontend

sensor. pfsense_nic_wan_in_mbps
sensor. pfsense_nic_wan_out_mbps

now is unavailable.

I need help, I don’t get it… :smiley:

Thank you!

You need to set defaults for your floats and rounds… Updating Templates with the new default values in 2021.10.x

I found a good example to adopt:

  - platform: snmp
    name: 'USG WAN in'
    host: 192.168.1.1
    baseoid: 1.3.6.1.2.1.2.2.1.10.2
    community: 'public'
    version: '2c'
    scan_interval: 10
  - platform: snmp
    name: 'USG WAN out'
    host: 192.168.1.1
    baseoid: 1.3.6.1.2.1.2.2.1.16.2
    community: 'public'
    version: '2c'
    scan_interval: 10
  - platform: derivative
    name: wan_in_der
    source: sensor.usg_wan_in
    unit_time: s
    unit: B
  - platform: derivative
    name: wan_out_der
    source: sensor.usg_wan_out
    unit_time: s
    unit: B
 - platform: template
   sensors:
      wan_in_mbps:
           value_template:  "{{ [((states('sensor.wan_in_der')|float(none)*8)/1000000)|round(2, default=none),0]|max }}"
          unit_of_measurement: 'Mbps'
          friendly_name: "WAN In der Alex"
     wan_out_mbps:
          value_template:  "{{ [((states('sensor.wan_out_der')|float(none)*8)/1000000)|round(2, default=none),0]|max }}"
         unit_of_measurement: 'Mbps'
         friendly_name: "WAN Out der Alex"

Now it works again. Thank you!

If you’re interested in a full blown pfsense integration I put one together. Details here: pfSense Integration