Dear HA Community,
I’m facing some configuration problems with remapping sensor values.
I have a network switch that I would like to monitor in HA over SNMP.
I have the following sensor configured (one for every port, but let’s keep it simple):
- platform: snmp
name: 'SNMP XS1920-12 Port 3'
host: 192.168.1.254
baseoid: 1.3.6.1.2.1.2.2.1.8.3
community: mycommunity
version: '2c'
scan_interval: 60
accept_errors: true
That correctly gives me numeric sensor values for the ports.
There are multiple possible values: 1 for port state up, 2 for port state down, 3 for port testing, etc.
I would like to remap the values to strings of what the state actually is.
Therefore following some other threads on this forum, I tried adding:
value_template: >-
{% set mapper = {
'1' : 'Up',
'2' : 'Down',
'3' : 'Testing',
'4' : 'Unk',
'5' : 'Dormant',
'6' : 'notPresent',
'7' : 'lowerLayerDown' } %}
{% set state = states.sensor.snmp_xs1920_12_port_3.state %}
{{ mapper[state] if state in mapper else 'Weird State' }}
and also tried:
value_template: >-
{% set mapper = ['Weird State', 'Up', 'Down', 'Testing', 'Unk', 'Dormant', 'notPresent', 'lowerLayerDown'] %}
{{ mapper[states.sensor.snmp_xs1920_12_port_3.state | int] }}
In both cases I’m getting “Weird State” regardless of the actual port state, as if the value is never matched.
Is there something I’m missing?
The value from the device is in fact an integer:
# snmpwalk -v2c -c mycommunity 192.168.1.254 1.3.6.1.2.1.2.2.1.8.3
iso.3.6.1.2.1.2.2.1.8.3 = INTEGER: 1
Thank you very much in advance for any help.
Cheers!