Open/Close and Motion Device Icons

I recently moved all my Door/Window and Motion Binary sensors into groups. For example:

  doorstatus:
    name: Door Sensors
    entities:
    - binary_sensor.aeotec_dsb29_doorwindow_sensor_2nd_edition_back
    - binary_sensor.aeotec_dsb29_doorwindow_sensor_2nd_edition_front

Before this move each of these sensors were at the top of the web ui and when a door opened or motion was detected these device(s) showed a nice black check mark. The sensors in a group have different (yellow with white check) icons which I find a bit hard to see.

doors

Is there a way these icons can be changed when contained within a goup? Preferably a black check as before

You can use themes to change the colour of most HA elements:

The item you want to change is:

paper-item-icon-active-color:

1 Like

You can change the icon and state to whatever you want using templates.
Notice in my group below, open doors and windows have the state ‘Open’ and ‘Closed’ instead of ‘On’ and ‘Off’ and their icons change to reflect their current state.

Door%20Window%20Template

In your sensors.yaml file :

- platform: template
  sensors:
    front_door:
      value_template: >-
        {% if states.binary_sensor.front_door_sensor.state == 'off' %}
          Open
        {% elif states.binary_sensor.front_door_sensor.state == 'on' %}
          Closed
        {% else %}
          n/a
        {% endif %}
      icon_template: >
        {% if states.binary_sensor.front_door_sensor.state == 'off' %}
          mdi:door-open
        {% elif states.binary_sensor.front_door_sensor.state == 'on' %}
          mdi:door-closed
        {% else %}
          mdi:help
        {% endif %} 

Then you end up with a new sensor, in the above case, sensor.front_door :slight_smile:

3 Likes

I am trying to implement both ideas here. It took a bit but I got the jest of themes, As for the template example, this works well with any of my door/window sensors ‘included’ into HA. What I am having problems with is how to do the same with my (zigbee) “virtual sensors” which are not part of HA and I update these sensors externally.
These -vsensors are defined as:

  patio_door:
    friendly_name: "Patio"
    value_template: "off"      

I have tried to modify the value_template but have not been able to get any way to make it work. For example I have tried

  sumppumproom_door:
    friendly_name: "Sump Pump Room"
    value_template: >-     
      {% if states.sensor.sumppumproom_door.state == 'off' %}
        Closed
      {% elif states.sensor.sumppumproom_door.state == 'on' %}
        Open
      {% else %}
        n/a
      {% endif %}
    icon_template: >
      {% if states.sensor.sumppumproom_door.state == 'off' %}
        mdi:circle-outline
      {% elif states.sensor.sumppumproom_door.state == 'on' %}
        mdi:check-circle
      {% else %}
        mdi:help
      {% endif %} 

Obviously HA does not like if states.sensor.sumppumproom_door.state
Is there a means I can get this approach to work or do I have to define 2 sensors such as:

  sumppumproom_door:
    friendly_name: "to be Hidden"
    value_template: "off"      

  sumppumproomdoor2:
    friendly_name: "Sump Pump Room"
    value_template: >-     
      {% if states.sensor.sumppumproom_door.state == 'off' %}
        Closed
      {% elif states.sensor.sumppumproom_door.state == 'on' %}
        Open
      {% else %}
        n/a
      {% endif %}
    icon_template: >
      {% if states.sensor.sumppumproom_door.state == 'off' %}
        mdi:circle-outline
      {% elif states.sensor.sumppumproom_door.state == 'on' %}
        mdi:check-circle
      {% else %}
        mdi:help
      {% endif %}

Just set device_class in your binary sensors correctly and you get the correct icons and correct wording automatically. No need for extra templates and crap.


Examples:
    exit_doors_stuck:
      friendly_name: Exit Door Stuck
      device_class: door
      value_template: "{{ is_state('group.exit_doors', 'on') }}"
      delay_on: 
        minutes: 5
   
    garage_doors_stuck:
      friendly_name: Garage Door Stuck
      device_class: garage_door
      value_template: "{{ is_state('group.garage_doors', 'on') }}"
      delay_on: 
        minutes: 10
   
    family_room_tv:
      friendly_name: Family Room TV
      device_class: power
      value_template: "{{not is_state('media_player.family_room_tv', 'off') }}"
4 Likes

Thank you for this! This thread helped me get my doors showing the icons I wanted with the status they’re in! :+1:

Thanks for this information! By setting the device_class for my 4 door sensors, they now show the proper statuses and icons!

One follow up question though: in my config the 4 binary sensors sit in a group called ‘all_windows’. The overall status of this group is still ‘on’ or ‘off’. Is it possible to have the group status use the same ‘open’ and ‘closed’ statuses as the individual sensors?

This is a good question. I am convinced it used to work that way; but sometime around 0.9x it changed. I’ve not found confirmation of that; but did have to change some automations that use a group to on/off to work.

Many thanks jwelter! device_class is just THE BEST solution :slight_smile:

I found that going into Configuration on the left, then customization then choosing my entity , then “pick attribute” which is device_class, I can do this without editing any files

1 Like

“device_class” doesn’t seem to work for binary_sensor when the platform is “remote_rpi_gpio”. HASS (v0.96.5) gives me an error that device_class isn’t supported. Am I doing something wrong?
thanks

binary_sensor:
  - platform: remote_rpi_gpio
    host: x.x.x.x
    #pull_mode: UP
    invert_logic: true
    device_class: garage_door
    ports:
      17: garagedoor2

What does delay_on do?

delay_on and delay_off do exactly what the name means; they wait to set on or off by the amount of time specified so work well to debounce noisy templates. Like the “for” in automations.