calypso
December 19, 2021, 6:58pm
1
So my inverter states its state numerically. I would like to map those values to a word. I have attempted to follow what I can find online but I am not coming right nor can I find official documentation on this.
- platform: template
sensors:
multiplus_inverter_state:
friendly_name: "Inverter State"
unit_of_measurement: "State"
entity_id: sensor.multiplus_inverter_state_numeric
value_template: >-
{% set mapper = {
'0' : 'Off',
'1' : 'Low Power',
'2' : 'Fault',
'3' : 'Bulk',
'4' : 'Absorbtion',
'5' : 'Float',
'6' : 'Storage',
'7' : 'Equalize',
'8' : 'Passthru',
'9' : 'Inverting',
'10' : 'Power Assist',
'11' : 'Power Supply',
'252' : 'Bulk Protection' } %}
{% set state = states.sensor.multiplus_inverter_state_numeric %}
{{ mapper[state] if state in mapper else 'Unknown' }}
Any idea why this doesn’t work?
calypso
December 19, 2021, 7:32pm
3
Ahh, the sneaky spacing.
Still never fixed for me, unfortunately. Still get an unknown value.
petro
(Petro)
December 19, 2021, 7:42pm
4
Use the states method, not the states machine
calypso
December 20, 2021, 6:32am
5
Ela Petro. You lost me here. Any examples of docs that I can follow?
calypso
December 20, 2021, 9:11am
7
Even with those changes, seems like no matter what I do I always get an unknown. Clecking for more details I can see that it is pulling the correct numeric state though.
tom_l
December 20, 2021, 9:48am
8
Using the template editor, what result does this give:
{{ states('sensor.multiplus_inverter_state_numeric') }}
petro
(Petro)
December 20, 2021, 5:09pm
10
Post exactly what you tried when it’s unavailable. Typically, people make mistakes on templates and it’s impossible to tell if they fixed it correctly.
finity
December 20, 2021, 8:10pm
11
But in case you want to know what the original problem was…
{% set state = states.sensor.multiplus_inverter_state_numeric.state %}
notice the “.state” at the end.
calypso
December 20, 2021, 8:12pm
12
- platform: template
sensors:
multiplus_inverter_state:
friendly_name: "Inverter State"
unit_of_measurement: "State"
entity_id: sensor.multiplus_inverter_state_numeric
value_template: >-
{% set mapper = {
'0' : 'Off',
'1' : 'Low Power',
'2' : 'Fault',
'3' : 'Bulk',
'4' : 'Absorbtion',
'5' : 'Float',
'6' : 'Storage',
'7' : 'Equalize',
'8' : 'Passthru',
'9' : 'Inverting',
'10' : 'Power Assist',
'11' : 'Power Supply',
'252' : 'Bulk Protection' } %}
{% set state = states('sensor.multiplus_inverter_state_numeric')|int(0) %}
{{ mapper[state] if state in mapper else 'Unknown' }}
# Inverter States, 0=Off;1=Low Power;2=Fault;3=Bulk;4=Absorption;5=Float;6=Storage;7=Equalize;8=Passthru;9=Inverting;10=Power assist;11=Power supply;252=Bulk protection
petro
(Petro)
December 20, 2021, 8:44pm
13
calypso:
|int(0)
Remove that. Your dictionary (what you cal mapper) uses umbers that are wrapped in quotes. That means they aren’t actually numbers but strings. So he mapper will fail. You want to keep your state a string, I.e. remove the int cast
1 Like
calypso
December 21, 2021, 7:30am
14
Petro is that man. Thank you.
Now I can study this so I understand it better + copy pasta for future.