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

234 posts

Master Geek
+1 received by user: 13


#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

234 posts

Master Geek
+1 received by user: 13


  #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
192 posts

Master Geek
+1 received by user: 42


  #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

234 posts

Master Geek
+1 received by user: 13


  #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
20858 posts

Uber Geek
+1 received by user: 5350

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
+1 received by user: 1


  #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

234 posts

Master Geek
+1 received by user: 13


  #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








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.