Change icon base on state

I’m trying to setup icons so that it can reflect the based on the state of the entity. for example, I have door sensors that I would like to show door-open icon when the sensor is on and door when it’s closed. I’m new in home automation so I can’t figure out how to accomplish this. Please see attachment for detail and thank you from advance.

configuration.yaml


# Configure a default setup of Home Assistant (frontend, api, etc)
homeassistant:
  latitude: !secret latitude
  longitude: !secret longitude
  elevation: 1207
  unit_system: imperial
  time_zone: America/Los_Angeles
  name: Potenza Home
  customize: !include customize.yaml

default_config:

# Uncomment this if you are using SSL/TLS, running in Docker container, etc.
http:

  ssl_certificate: /ssl/fullchain.pem
  ssl_key: /ssl/privkey.pem

# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
zone: !include  zone.yaml
switch: !include switch.yaml
sensor: !include sensor.yaml

# lutron bridge
lutron_caseta:
  host: !secret lutron_ip
  keyfile: /ssl/lutron/caseta.key
  certfile: /ssl/lutron/caseta.crt
  ca_certs: /ssl/lutron/caseta-bridge.crt

# Smart Life
tuya:
  username: !secret tuya_user
  password: !secret tuya_pass
  country_code: 1
  platform: smart_life


# input boolean
input_boolean:
  garen_home:
    name: Garen Home
    initial: off
    icon: mdi:human-male

  audrey_home:
    name: Audrey Home
    initial: off
    icon: mdi:human-female

  home_occupied:
    name: Home Occupied 
    initial: off
    icon: mdi:human-male-female

  guest:
    name: Guest 
    initial: off
    icon: mdi:airplane

# Samsung Tv
media_player:
  - platform: samsungtv
    host: 10.107.0.33
    name: Living Room TV
    mac: 7c:64:56:b1:24:9a
    port: 8001

customize.yaml

switch.kitchen_island_light:
  friendly_name: Kitchen Island Light
  icon: mdi:vanity-light

light.audrey_s_office_main_light:
  friendly_name: Audrey's Office Light
  icon: mdi:spotlight

light.garen_s_office_main_light:
  friendly_name: Garen's Office Light
  icon: mdi:spotlight  

switch.front_porch_sconces:
  friendly_name: Porch Light
  icon: mdi:outdoor-lamp

light.front_foyer_main_light:
  friendly_name: Entrance/Foyer Light
  icon: mdi:spotlight  

light.living_room_couch_light:
  friendly_name: Couch Light
  icon: mdi:spotlight

switch.hallway_light:
  friendly_name: Hallway Light
  icon: mdi:ceiling-light

switch.living_room_backyard_light:
  friendly_name: Living Room Backyard Light
  icon: mdi:outdoor-lamp

switch.kitchen_backyard_light:
  friendly_name: Kitchen Backyard Light
  icon: mdi:outdoor-lamp

switch.garage_backyard_light:
  friendly_name: Garage Backyard Light
  icon: mdi:outdoor-lamp

binary_sensor.front_door_sensor:
  friendly_name: Front Door
  icon: mdi:door
  
binary_sensor.kitchen_door_sensor:
  friendly_name: Kitchen Door
  icon: mdi:door

binary_sensor.garage_back_door_sensor:
  friendly_name: Garage Back Door
  icon: mdi:door

binary_sensor.living_room_door_sensor:
  friendly_name: Living Room Door
  icon: mdi:door

switch.07200135bcddc20558b7:
  friendly_name: Garage Main Light
  icon: mdi:wall-sconce-flat

sensor.honeywell_th6320zw2003_t6_pro_series_thermostat_battery_level:
  friendly_name: Honeywell Thermostat Battery Level

sensor.honeywell_th6320zw2003_t6_pro_series_thermostat_relative_humidity:
  friendly_name: Humidity
  icon: mdi:water-percent

sensor.schlage_allegion_be469zp_connect_smart_deadbolt_battery_level:
  friendly_name: Front Door Lock Battery Level

lock.schlage_allegion_be469zp_connect_smart_deadbolt_locked:
  friendly_name: Front Door
  icon: mdi:lock

Assign a ‘door’ device class to the door sensors.

Also please don’t post screen shots of your configuration. Paste correctly formatted configuration snippets instaed. This makes it a lot easier for us to help you. How to help us help you - or How to ask a good question

Sorry about that i have replaced it with my configuration file

1 Like

Good work. Now I can simply copy and paste to show you how:

binary_sensor.front_door_sensor:
  friendly_name: Front Door
  device_class: door

This will have two icons, one for open and one for closed as well as changing to the active colour when open.

I didnt know that would be that easy lol. Thank you!!

Hi everyone,

Sorry for the newb question, but I’m sure I’m missing something here. I have a Lomoto garage door opener integrated through Tuya.

https://www.amazon.com/gp/product/B086MKP14K/ref=ppx_yo_dt_b_asin_image_o02_s00?ie=UTF8&psc=1

It is picked up as a switch by HA, and I set it up as a button. This gets me part way there, as it will change the color when the door is open, but not the icon. So I am trying to get it to work based off the state of the sensor. I added the code to my customize.yaml

binary_sensor.garage_door2_sensor:
  friendly_name: Garage Door 2
  device_class: garage_door

So what is the next step to implement it in my lovelace ui?

Thanks in advance,