dariusz
September 5, 2022, 7:55pm
1
I have configured HA to read UPS (type/model SMT1500I) basic data…
Via SNMP platform…
Configuration part:
# UPS_SMT1500I (A)
# battery capacity
- platform: snmp
name: 'SMT1500I (A) battery capacity'
host: 192.168.1.166
community: public
baseoid: .1.3.6.1.4.1.318.1.1.1.2.3.1.0
unit_of_measurement: '%'
value_template: ' {{((value | int) * 100)}} '
# battery actual voltage
- platform: snmp
name: 'SMT1500I (A) battery actual voltage'
host: 192.168.1.166
community: public
baseoid: .1.3.6.1.4.1.318.1.1.1.2.3.4.0
unit_of_measurement: 'V'
value_template: ' {{((value | int) / 10) | round(1) }} '
# input voltage
- platform: snmp
name: 'SMT1500I (A) input voltage'
host: 192.168.1.166
community: public
baseoid: .1.3.6.1.4.1.318.1.1.1.3.2.1.0
unit_of_measurement: 'V'
# battery temperature
- platform: snmp
name: 'SMT1500I (A) battery temperature'
host: 192.168.1.166
community: public
baseoid: .1.3.6.1.4.1.318.1.1.1.2.3.2.0
unit_of_measurement: '°C'
value_template: ' {{((value | int) / 10) | round(1) }} '
# output load
- platform: snmp
name: 'SMT1500I (A) output load'
host: 192.168.1.166
community: public
baseoid: .1.3.6.1.4.1.318.1.1.1.4.2.3.0
unit_of_measurement: '%'
# battery recommended replace date
- platform: snmp
name: 'SMT1500I (A) recommended replace date'
host: 192.168.1.166
community: public
baseoid: .1.3.6.1.4.1.318.1.1.1.2.2.21.0
unit_of_measurement: 'M/D/Y'
# status
- platform: snmp
name: 'SMT1500I (A) status'
host: 192.168.1.166
community: public
baseoid: .1.3.6.1.4.1.318.1.1.1.4.1.1.0
unit_of_measurement: ''
For ‘status’ number is displayed.
The question is - what is the easiest way to convert this digit to one of the text below?
In this case ‘status’ 2, to have displayed ‘on line’
unknown(1),
onLine(2),
onBattery(3),
onSmartBoost(4),
timedSleeping(5),
softwareBypass(6),
off(7),
rebooting(8),
switchedBypass(9),
hardwareFailureBypass(10),
sleepingUntilPowerReturn(11),
onSmartTrim(12),
ecoMode(13),
hotStandby(14),
onBatteryTest(15),
emergencyStaticBypass(16),
staticBypassStandby(17),
powerSavingMode(18),
spotMode(19),
eConversion(20),
chargerSpotmode(21),
inverterSpotmode(22),
activeLoad(23),
batteryDischargeSpotmode(24),
inverterStandby (25),
chargerOnly(26)
Hellis81
(Hellis81)
September 5, 2022, 8:02pm
2
You need to make a template sensor.
My advice would be to add a blank entry then the list like this:
{% set list = {"",
"unknown",
"onLine",
"onBattery",
...
} %}
# assuming sensor name
{{ list[ states('sensor.smt1500i_(A)_status')] }}
1 Like
dariusz
September 6, 2022, 9:44am
3
Thank you for advice…
I’ve followed this… But the sensor does not appear on the list of available entities.
I’m doing somnething wrong?
Configuration check does not show any errors…
# UPS SMT1500I (A) status text
- name: SMT1500I_A_status_text
# unique_id: 'smt1500i_a_status_text'
state: >
{{ list[ states('sensor.smt1500i_a_status')] }}
{% set list = {"",
"unknown",
"onLine",
"onBattery",
} %}
Troon
(Troon)
September 6, 2022, 9:50am
4
Is this your first template sensor? Where in your config is this found?
Also, you must define list
before you use it. @Hellis81 ’s example was quite clear, defining the list
then pulling out the appropriate item — you’ve flipped them around which won’t work. There is an error in the example, though: list
is defined as a dictionary with braces {}
rather than brackets []
.
Example using the new template format and a tuple (items)
instead of a list [items]
:
template:
- sensor:
- name: SMT1500I_A_status_text
unique_id: cdc5fc01-e306-401c-8904-c177eb851790
state: >-
{% set status_list = ('',
'unknown',
'onLine',
'onBattery',
'onSmartBoost',
'timedSleeping',
'softwareBypass',
'off',
'rebooting',
'switchedBypass',
'hardwareFailureBypass',
'sleepingUntilPowerReturn',
'onSmartTrim',
'ecoMode',
'hotStandby',
'onBatteryTest',
'emergencyStaticBypass',
'staticBypassStandby',
'powerSavingMode',
'spotMode',
'eConversion',
'chargerSpotmode',
'inverterSpotmode',
'activeLoad',
'batteryDischargeSpotmode',
'inverterStandby',
'chargerOnly') %}
{{ status_list[states('sensor.smt1500i_a_status')|int] }}
Hellis81
(Hellis81)
September 6, 2022, 10:02am
5
Correct…
We could have used {}
but then it would have needed to be { 0:"", 1:"unknown", 2:"online"...}
.
Which is not as good solution.
Hellis81
(Hellis81)
September 6, 2022, 10:17am
6
Another method is to use regex:
{% set status = "unknown(1),
onLine(2),
onBattery(3),
onSmartBoost(4),
timedSleeping(5),
softwareBypass(6),
off(7),
rebooting(8),
switchedBypass(9),
hardwareFailureBypass(10),
sleepingUntilPowerReturn(11),
onSmartTrim(12),
ecoMode(13),
hotStandby(14),
onBatteryTest(15),
emergencyStaticBypass(16),
staticBypassStandby(17),
powerSavingMode(18),
spotMode(19),
eConversion(20),
chargerSpotmode(21),
inverterSpotmode(22),
activeLoad(23),
batteryDischargeSpotmode(24),
inverterStandby (25),
chargerOnly(26)" | regex_findall('(.*)\(' ~ states('sensor.smt1500i_a_status') ~'\)') %}
{{ status[0] }}
Here I used a variable instead of the sensor.
dariusz
September 6, 2022, 10:43am
7
Perfect… Both versions are working.
Thank you for support…
Hellis81
(Hellis81)
September 6, 2022, 11:06am
8
I didn’t notice this before but it seems your battery is overcharged. 100000% could be dangerous
dariusz
September 6, 2022, 11:21am
9
Yes… Thank you for pointing… Some issue with roundings… This was next in plan to correct that.
The returned value directly from UPS is ‘1’.
Rounding - as below - is cousing to dispaly ‘100,000’.
How to have the display only ‘100’ ?
unit_of_measurement: '%'
value_template: ' {{((value | int) * 100) | round(0) }} '
123
(Taras)
September 6, 2022, 12:34pm
10
Another way to do the same thing:
template:
- sensor:
- name: SMT1500I_A_status_text
unique_id: cdc5fc01-e306-401c-8904-c177eb851790
state: >-
{{ [ '', 'unknown', 'onLine', 'onBattery', 'onSmartBoost', 'timedSleeping',
'softwareBypass', 'off', 'rebooting', 'switchedBypass', 'hardwareFailureBypass',
'sleepingUntilPowerReturn', 'onSmartTrim', 'ecoMode', 'hotStandby', 'onBatteryTest',
'emergencyStaticBypass', 'staticBypassStandby', 'powerSavingMode', 'spotMode', 'eConversion',
'chargerSpotmode', 'inverterSpotmode', 'activeLoad', 'batteryDischargeSpotmode', 'inverterStandby',
'chargerOnly' ].index(states('sensor.smt1500i_a_status')) }}
dariusz
September 6, 2022, 8:23pm
11
My fault… The returned value is 1000, so must be divided by 10…
Then display is 100%.
dariusz
December 21, 2023, 1:32pm
12
Some question - what changed in SNMP integration?
I mean - suddently ‘Battery recomende replacement date’ is not displyed.
Error mesage says: ‘this entity is no longer provided in SNMP integration’.
Is that any way to improve that?
UPS battery replace date is rather important parameter…