Get "Formatted" value based on the StateDescription in a rule


I’m using the NetworkUpsBinding which gives the status from the connected ups back as a String.

When i call ups_status.toString:
It returns OL when on line power or OB when on Battery Power, etc etc,.

In the PaperUI i see the state being represented as Online or On battery, and using the rest API i see that there is a StateDescription implemented.

I want to push the status to my phone so that i know that there is some-thing happening with the power, but i want to see the value based on the StateDescription.

I am able to get the correct value using:
ups_status.stateDescription.options.filter[stateOption | stateOption.value == ups_status.state.toString].get(0).getLabel()

Is there a simpler way than this?

When searching in the forums or documentation i could not find anything related to rules in combination with state description.



Not to get at the state options that the binding sets for you.

An alternative is to use a simple MAP transform to convert text “OB” to “On Battery” yourself,or any other lookup mechanism.

Using scripted automation, you can use EnrichedItemDTOMapper

from import EnrichedItemDTOMapper
enriched_dto ="ups_status"), False, None, None, None).transformedState