SNMP value template

I have tried this for SNMP of my Synology NAS.
I get no error but also no value. What is wrong?

  - platform: "snmp"
    host: 192.168.1.110
    baseoid: 1.3.6.1.4.1.6574.1.1.0
    name: NAS system status
    value_template: >-
      {% if is_state("sensor.nas_system_status", "1") %}
        Normal
      {% elif is_state("sensor.nas_system_status", "2") %}
        Fejl
      {% endif %}

When I split it up like this it works, but I guess it should be possible to combine the sensor and template, or…?

  - platform: "snmp"
    host: 192.168.1.110
    baseoid: 1.3.6.1.4.1.6574.1.1.0
    name: nas system status_raw

  - platform: template
    sensors:
      nas_system_status:
        value_template: >-
          {% if is_state("sensor.nas_system_status_raw", "1") %}
            Normal
          {% elif is_state("sensor.nas_system_status_raw", "2") %}
            Fejl
          {% endif %}

Have you verified that the oid is correct? What are you using to verify the OID?

I guess the OID should be okay. I get data fine when splitting up the SNMP part and the value template part.
I have also tested with the Paessler SNMP tester.

if your OID is correct and it returns 1 or 2… then this is all you need:

  - platform: "snmp"
    host: 192.168.1.110
    baseoid: 1.3.6.1.4.1.6574.1.1.0
    name: NAS system status
    value_template: >
      {% if value | int == 1 %}
        Normal
      {% else  %}
        Fejl
      {% endif %}
1 Like

Works perfectly :slight_smile:
Thanks

Do you know how it works if I want to do the same thing for a KNX binary sensor?
I want to change the text from on/off to “New mail” and “Normal”
I tried with this but I guess it is not correct. It returns an error in the log.

  - platform: knx
    state_address: '7/3/6'
    name: "New mail"
    data_template: >-
      {% if is_state | == 1 %}
        New mail
      {% else %}
        Normal
      {% endif %}

you’d have to make a template sensor* from that.

So there is no way to combine the sensor part and template in this case like with snmp?

It works with this:

binary_sensor:
  - platform: knx
    state_address: '7/3/6'
    name: "New mail"
Sensor:
  - platform: template
    sensors:
      new_mail:
       value_template: >-
          {% if is_state("binary_sensor.new_mail", "on") %}
            New mail
          {% else  %}
            Normal
          {% endif %}

That is correct. There is no way to combine the two because knx doesn’t support templating for the value.

ahh okay. Thanks :slight_smile:

So just to be 100% sure…
I have another KNX sensor (not binary this time)
I also have to split it up this time like this?

  - platform: knx
    name: Outside Lux raw
    state_address: '7/3/18'
    sync_state: False
    type: 'illuminance'
    
  - platform: template
    sensors:
      udvendig_lux:
        value_template: '{{ (states.sensor.outside_lux_raw.state | float * 1) | round(0) }}'
        friendly_name: 'Outside Lux'
1 Like