Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 103366

Template binary_sensor &"unknown" state

$
0
0

Got a template sensor, still using an old notation:

      battery_charging_xxx:

        value_template: >-
          {% if .... -%}
            ...
          {%- elif ... -%}
            {{ "unknown" }}
          {%- else -%}
            ...
          {%- endif %}

        icon_template: >-
          {%- if states("binary_sensor.battery_charging_xxx") in ["unavailable","unknown"] -%}
            {{ "mdi:battery-unknown" }}
          {%- elif is_state("binary_sensor.battery_charging_xxx","on") -%}
            {{ "mdi:battery-charging" }}
          {%- else -%}
            {{ "mdi:battery" }}
          {%- endif %}

        availability_template: >-
          ....

The idea is to show the “mdi:battery-unknown” icon for unknown state.
But I keep seeing “mdi:battery” for the icon.

Pasting the code into Dev tools → Templates gives this:

battery_charging_xxx:
        value_template: >-
          unknown
        icon_template: >-
          mdi:battery
        availability_template: >-
          True

“Set state” page gives this:
image

Setting the “unknown” state in the “Set state” gives this output in the Templates:

battery_charging_xxx:
        value_template: >-
          unknown
        icon_template: >-
          mdi:battery-unknown
        availability_template: >-
          True

But UI still showing the “mdi:battery” icon.
And the “icon” internally is still “mdi:battery” too:
template:

{{states("binary_sensor.battery_charging_xxx")}}
{{state_attr("binary_sensor.battery_charging_xxx","icon")}}

output:

unknown
mdi:battery

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 103366

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>