..: Change input_boolean icon on state?

HI,

Must be a long day, cause i cant get it to work anymore.
see:

homeassistant:
  customize:
    input_boolean.activity_notification:
#      icon_template: >
#        if (state === 'on') return 'mdi:message-bulleted'; else return 'mdi:message-bulleted-off';
      icon_template: >-
          {% if is_state('input_boolean.activity_notification', 'on') %} mdi:message-bulleted
          {% else %} mdi:message-bulleted-off
          {% endif %}


please see where the error are, ought to be working… (n0…)

thanks,
Marius

1 Like

Now I’m really new to this so me trying to help might not actually help…

But isn’t the template code for “else” written like “elif”? Might be wrong or talking about something entirely different.

Edit: Never mind, realising that’s only if you have several “ifs”…

This gave no error at least :slight_smile:

    entity_picture_template: >
      {% if is_state('input_boolean.activity_notification', 'on') %}
        mdi:message-bulleted
      {% elif is_state('input_boolean.activity_notification', 'off') %}
        mdi:message-bulleted-off
      {% endif %}
1 Like

Hey Marius,

Did you ever get this to work…from my research it can’t be done with input boolean…is that what you found?

Thanks

No.
No issues at all:

input_boolean.notify_motion:
  templates:
    icon: >
      if (state === 'on') return 'mdi:run-fast';
      return 'mdi:eye-off';
    icon_color: >
      if (state === 'on') return 'rgb(251, 210, 41)';
      return 'rgb(54, 95, 140)';
1 Like

please post with correct code-blocks to be able to check your config.

select the code and click the </> in the editor

btw you have customise.yaml with an s, sure thats correct in your config?

I think indentation was my issue…Thanks so much for helping me.

cool, np, glad you got it working

input_boolean.mark_sleeping:
 templates:
    icon: >
      if (state === 'on') return 'mdi:sleep';
      return 'mdi:sleep-off';
    icon_color: >
      if (state === 'on') return 'rgb(251, 210, 41)';
      return 'rgb(54, 95, 140)';

I have the following in my customize.yaml which is linked in under my config.yaml but i cannot get it working, the icons dont set nor does the colours. Does this still work?

yes it does, provided you have custom-ui installed? home-assistant-custom-ui/docs/installing.md at master · andrey-git/home-assistant-custom-ui · GitHub

If still of an interest, there’s a solution without custom-ui -

It’s a WIP for a door lock who has binary sensor for “is (not) lock” and a binary switch for “un/lock” the door.

Create a template binary sensor that can control the icon (and be used on the UI - to un/lock) and an input boolean that will be used by the binary sensor to report (or by the UI - which is actually not needed, but I added it for clarification) to toggle the state of the binary sensor.

This is the configuration.yaml part:

binary_sensor:
  - platform: template
    sensors:
      door_main:
        friendly_name: Main door
        value_template: >- 
          {%- if is_state("input_boolean.door_main", "on") -%}
          true
          {%- else -%}
          false
          {%- endif -%} 
        icon_template: >
          {% if is_state("input_boolean.door_main", "on") %}
            mdi:door-open
          {% else %}
            mdi:door-closed
          {% endif %}

input_boolean:
  door_main:
    name: Main door
    icon: mdi:door-closed

And on the Lovelace UI (I added the entities types to the entity names for better understanding):

entity-button (will be used to un/lock the door) and to show the current state of the door (is or isn’t locked) -

type: entity-button
tap_action:
  action: call-service
  service: input_boolean.toggle
  service_data:  
    entity_id: input_boolean.door_main
hold_action:
  action: none
entity: binary_sensor.door_main
name: Main door (binary_sensor.door_main)

Entities -

entities:
  - entity: input_boolean.door_main
    name: Main door (input_boolean.door_main)
  - entity: binary_sensor.door_main
    name: Main door (binary_sensor.door_main)
show_header_toggle: false
title: Doors
type: entities

it looks like this:
MaxthonSnap20190220174211
MaxthonSnap20190220174233

Hopefully it helps someone :wink:

14 Likes