Geekzone: technology news, blogs, forums
Guest
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.


sfrasernz

227 posts

Master Geek


#299439 7-Sep-2022 17:55
Send private message

Does anyone have a working config they could share for Home Assistant that will change icons based on the state of the entity?

 

I've tried several configs from the HA forums but a lot of the commands are deprecated and none seem to work. The closest I've got is the config below but the states don't change the icon.

 

MQTT is working and I can control the door and see the State change from 1 (closed) to 0 (open). 

 

 

 

The following is in my configuration.yaml file running HASS 2022.8.7

 

 

 

mqtt:
  cover:
       - name: "Garage Door MQTT"
      device_class: "garage"
      state_topic: "shellies/shelly1-485519/input/0"  
      command_topic: "shellies/shelly1-485519/relay/0/command"
      state_closed: "1"
      state_open: "0"
      payload_open: "toggle"
      payload_stop: "toggle"
      payload_close: "toggle"
      payload_available: "online"
      payload_not_available: "offline"
      icon: >-
        {% if states['cover.garage_door_mqtt'].state == 'closed' %}
        'mdi:garage'
        {% elif states['cover.garage_door_mqtt'].state == 'open' %}
        'mdi:garage-open'
        {%else%}
        'mdi:alert'
        {%endif%}


Filter this topic showing only the reply marked as answer Create new topic
sfrasernz

227 posts

Master Geek


  #2964403 7-Sep-2022 19:01
Send private message

Ok....in case anyone else stumbles across this topic I finally found have a working solution.

 

 

I created a binary_sensor based on the MQTT traffic to determine the position of the door.

 

 

 

mqtt:

 

  binary_sensor:

 

    - name: "Garage Door MQTT"

 

      state_topic: "shellies/shelly1-485519C/input/0"

 

      payload_on: "1"

 

      payload_off: "0"

 

 

 

and then added the following to change the icon based on the binary sensor above. 

 

 

 

 

 

binary_sensor:

 

  - platform: template

 

    sensors:

 

      garage:

 

        friendly_name: GarageTest

 

        device_class: opening

 

        value_template: "{{ is_state('binary_sensor.garage_door_mqtt', 'on') }}"

 

        icon_template: >

 

          {% if is_state('binary_sensor.garage_door_mqtt', 'on') %}

 

             mdi:garage-open

 

          {% else %}

 

             mdi:garage

 

          {% endif %}

 


 

 

 

The button on the Dashboard now shows the door state and even changes colour. 

 

 

 

 

 




eluSiveNZ
190 posts

Master Geek


  #2964410 7-Sep-2022 20:09
Send private message

Seems a bit overkill. Can’t you just set the “device_class” as garage_door in the MQTT binary sensor config?

sfrasernz

227 posts

Master Geek


  #2964414 7-Sep-2022 20:17
Send private message

I wish it was - unless I'm missing something obvious.

 

Setting the Device Class to Garage will change the Color of the icon based on its state but not the icon itself (from showing a closed door to an open door).




timmmay
20591 posts

Uber Geek

Trusted
Lifetime subscriber

  #2964415 7-Sep-2022 20:24
Send private message

I have a bit of code that half works and looks something like that. I don't understand the various symbols that can go at the start of the template (> vs |- vs |2-), I can't find any documentation about it - but I haven't tried very hard.

 

 

 

{%- set icons = {
  "heating": "mdi:fire",
  "cooling": "mdi:snowflake",
  "drying": "mdi:water-percent",
  "idle": "mdi:air-conditioner",
  "fan": "mdi:fan",
  "off": "mdi:power"} -%}
{{ icons[state_attr("climate.itc_living", "hvac_action")|lower] | default("mdi:autorenew") }}


1yippy1
67 posts

Master Geek


  #2964416 7-Sep-2022 20:36
Send private message

this works for me shows blue garage icon when closed and yellow open icon when open:

 

switch garage:
  - platform: template
    switches:
      garage:
        turn_on:
          service: homeassistant.toggle
          data:
            entity_id: switch.garage_door_open_close
        turn_off:
          service: homeassistant.toggle
          data:
            entity_id: switch.garage_door_open_close
        value_template: "{{is_state('binary_sensor.garage_door', 'on')}}"    
        icon_template: >-
          {% if is_state('binary_sensor.garage_door', 'on') %}
            mdi:garage-open
          {% else %}
            mdi:garage
          {% endif %}


sfrasernz

227 posts

Master Geek


  #2964417 7-Sep-2022 20:44
Send private message

THANK YOU! 

 

The above works flawlessly. 


Filter this topic showing only the reply marked as answer Create new topic





News and reviews »

Gen Threat Report Reveals Rise in Crypto, Sextortion and Tech Support Scams
Posted 7-Aug-2025 13:09


Logitech G and McLaren Racing Sign New, Expanded Multi-Year Partnership
Posted 7-Aug-2025 13:00


A Third of New Zealanders Fall for Online Scams Says Trend Micro
Posted 7-Aug-2025 12:43


OPPO Releases Its Most Stylish and Compact Smartwatch Yet, the Watch X2 Mini.
Posted 7-Aug-2025 12:37


Epson Launches New High-End EH-LS9000B Home Theatre Laser Projector
Posted 7-Aug-2025 12:34


Air New Zealand Starts AI adoption with OpenAI
Posted 24-Jul-2025 16:00


eero Pro 7 Review
Posted 23-Jul-2025 12:07


BeeStation Plus Review
Posted 21-Jul-2025 14:21


eero Unveils New Wi-Fi 7 Products in New Zealand
Posted 21-Jul-2025 00:01


WiZ Introduces HDMI Sync Box and other Light Devices
Posted 20-Jul-2025 17:32


RedShield Enhances DDoS and Bot Attack Protection
Posted 20-Jul-2025 17:26


Seagate Ships 30TB Drives
Posted 17-Jul-2025 11:24


Oclean AirPump A10 Water Flosser Review
Posted 13-Jul-2025 11:05


Samsung Galaxy Z Fold7: Raising the Bar for Smartphones
Posted 10-Jul-2025 02:01


Samsung Galaxy Z Flip7 Brings New Edge-To-Edge FlexWindow
Posted 10-Jul-2025 02:01









Geekzone Live »

Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.



Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.