Room-card value mapping

Hello, I’m trying to use room-card for my new dashboard. I have sensor for battery in my thermostat. One weird thing is that in developer tools I can see two states (on/off) which indicates if battery is low or not. But if I open up the device and click on entity I can see two different states (Normal/Low). How is that possible?

I want to show Normal/Low in my dashboard, but for now I can only see Off/On

I tried to use something like this:

value_template: >-
  {% if states('binary_sensor.0x0c4314fffe63a974_battery_low') == 'off' %}
    Normal
  {% elif states('binary_sensor.0x0c4314fffe63a974_battery_low') == 'on' %}
    Low
  {% endif %}

Which works in developer tools, but not on my room-card. I also tried to create a binary_sensor in configuration.yaml and use it in room-card, that also does not work

binary_sensor:
  - platform: template
    sensors:
      battery_low_status:
        value_template: >-
          {% if is_state('binary_sensor.0x0c4314fffe63a974_battery_low', 'off') %}
            Normal
          {% elif is_state('binary_sensor.0x0c4314fffe63a974_battery_low', 'on') %}
            Low
          {% endif %}

What I’m missing?

There are a number of “room” cards. Which one are you using?

(github link?)

Hi, I’m using this one:

Anyone please?

I can only see the possibility to template styles, not the state itself: Room Card Templating

Does your binary sensor work that way at all?

I was able to set the color of the icon, but not change the value of the state, maybe I’m using wrong syntax :confused:

    - entity: binary_sensor.0x0c4314fffe63a974_battery_low
        state_color: true
        show_icon: true
        name: Thermostat battery
        icon:
          template: 
            styles: >
              if (entity.state == 'off') return 'color: green;'; 
              if (entity.state == 'on') return 'color: red;';

I tried this, but I guess the return statement is wrong

 styles: 
          template: >
            if (entity.state == 'off') return entity.state == 'Normal'; 
            if (entity.state == 'on') return entity.state == 'Low';

Compare with the documentation example: The semicolons are to much.

I don’t understand, the two examples above are exactly the same in terms of semicolons …

vs.


return 'color: green';

Both examples works with color (I’m not saying that it’s okay) :).

But I need to get working the one with states and this one seems correct, but does not work:

 if (entity.state == 'off') return entity.state == 'Normal'; 
 if (entity.state == 'on') return entity.state == 'Low';

With color for example like this it works:

if (entity.state == 'high') return 'color: green';  
if (entity.state == 'medium') return 'color: yellow'; 
if (entity.state == 'low') return 'color: red';

So I don’t know if it’s problem with my code or I just can’t use it like this. I’m pretty new to HA and yaml coding.

Again: I cannot see a possibility to template the state itself.