Dynamic Icon for Garadget

Hello HA Community,

I have two Garadget Covers for my Garage which I love, however, I’m looking for a way to Dynamically change the default icon to reflect the status of Open/Close and at the same time have the controls to over the garage. The Cover is currently configured for the MQTT Platform.

I also have a MQTT sensor that give me the correct status (Open/Close), which I do use, but I would rather have the default icon change and hide or remove the sensor from the front-end. Attached are two images for the current front-end and another of what I would like to do.

gardget--current-icon
Current View

gardget-icon
Desired Viiew

I would imagine you can use icon_template for the switch/control entity. I’m not sure if it could disable the open/close buttons like you have in the screenshot though.

Hello Kallb123,

I don’t mind if the buttons stay active all of the time as long as I can get them on the same row as the Garage icons. I do have icon template working for the sensors, but I cannot figure out how to get it on the Cover for the MQTT Platform.

cover: 
  - platform: mqtt
    name: "Left Garage"
    command_topic: "garadget/LeftGarage/command"
    state_topic: "garadget/LeftGarage/status"
    payload_open: "open"
    payload_close: "close"

Any sample code help would be greatly appreciated. Thanks.

I think you can just copy and paste the icon template from the sensor to the cover. It’s not documented, but it seems to work for everything I’ve tried. For example:

cover: 
  - platform: mqtt
    name: "Left Garage"
    command_topic: "garadget/LeftGarage/command"
    state_topic: "garadget/LeftGarage/status"
    payload_open: "open"
    payload_close: "close"
    icon_template: copy and paste!

If that doesn’t work then maybe you’ll have to combine it all into a template_cover?? Try the above first though as it’s a simple copy paste :slight_smile:

I added this one line but it did not work. I simply copied it from my template sensor.

icon_template: ‘{% if is_state(“sensor.left_garage_status”, “closed”) %}mdi:garage{% else %}mdi:garage-open{% endif %}’

I’m fairly new to HA so I’m not sure how to do a template cover. Below is the code for my Cover Sensor.

 - platform: mqtt
   name: 'Left Garage Status'
   state_topic: 'garadget/LeftGarage/status'
   value_template: '{{ value_json.status }}'

 - platform: template
   sensors:
      left_garage_state:
      friendly_name: 'Left Garage State'
      value_template: '{{ states.sensor.left_garage_status.state }}'
      icon_template: '{% if is_state("sensor.left_garage_status", "closed") %}mdi:garage{% else %}mdi:garage-open{% endif %}'

I’m not sure either but I will have a guess. Keep the entities you have above and reference them in the template.

cover:
  - platform: template
    covers:
      garage_doorleft_new:
        friendly_name: "Garage Door Left"
        value_template: "{{ states.sensor.left_garage_status.state }}"
        icon_template: ‘{% if is_state(“sensor.left_garage_status”, “closed”) %}mdi:garage{% else %}mdi:garage-open{% endif %}’
        open_cover:
          service: cover.open_cover
          data:
            entity_id: cover.garage_left_old
        close_cover:
          service: cover.close_cover
          data:
            entity_id: cover.garage_left_old
        stop_cover:
          service: cover.stop_cover
          data:
            entity_id: cover.garage_left_old

So this template gets its value and icon from the state of the sensor you already have, and the open/close/stop commands just reference the cover entity you already defined. Obviously you’ll need the same for the other garage door.

You are a GENIUS…!!! It worked on the first try. Even the Open/Close button gets disabled appropriately. I’m going to clean up my final code and post it just in case anyone else would like to do the same. Two minor questions, if you don’t mind.

  1. Is there a way to dynamically concatenate “-open” or “-closed” after the Friendly Name or after the icon?
  2. The stopped has never worked even but its not a big deal - any thoughts

Thanks a bunch.

Haha that’s great! I’m glad it’s working, I’m not a genius though, hone assistant is just really great to work with.

I have no idea about question 2, as I have no covers in my set up. I can guess at question 1… I don’t think there’s a simple way to do it. I feel like there should be an action in an automation that can change the friendly name, but I don’t think that exists. So there’s 2 options. Option 1 is easier but probably doesn’t work:

friendly_name: ‘{% if is_state(“sensor.left_garage_status”, “closed”) %}Garage Door Left Closed{% else %}Garage Door Left Open{% endif %}’

OR

friendly_name_template: ‘{% if is_state(“sensor.left_garage_status”, “closed”) %}Garage Door Left Closed{% else %}Garage Door Left Open{% endif %}’

I don’t think that’s supported, but it would be a nice solution.

Option 2 is very complicated and relies on having double entities in different groups. Groups have a set_visibility action, so it is possible to show and hide these dynamically. For example you set up the entities: garage_doorleft_new_open, garage_doorleft_new_closed, garage_doorright_new_open, garage_doorright_new_closed. The closed and open are identical to each other, except you have a different friendly name. Then you put them into individual groups. To finish it off, you need a set of automations… Either 2 (with a bunch of if statements, or 4 simple automations).

I’m on mobile so I don’t want to type all the code, but the automation should do the following: when the left sensor changes from open to closed, set the visibility of the left open group to hidden and set the visibility of the left closed group to visible. So you’re replacing the entity in your interface with a new one that’s identical but with a different name! You’ll need the other 3 of those automations (left door closed to open, right door open to closed, right door closed to open).

So that’s a pretty ridiculous solution. It would be good if option 1 works, if not I’ll make a feature request.

Seems like you already got this doing what you want, but for what its worth, to get my myq garage door to display with the dynamic garage icon, all I had to do was add this to my customize.yaml:

    cover.garage_door:
      device_class: garage

Not sure if garadget would work the same way.

If you added this to customize for the template cover it would work properly!

cover.garage_door:
  device_class: garage

Ah! device_class: garage is a much better solution than mine! :see_no_evil:

Anyone got any idea about appening open/closed to the friendly_name?

No worries, I think your solution is still good exercise to see how flexible HA can be.

I don’t think that templating is supported in friendly_names, so I’m not sure how you’d go about it. My only very bad idea that definitely won’t work is to create a script on the server that reads the door state, updates the friendly_name in customize.yaml, and then calls the reload_core_config service. But as I said, this is a very bad idea that definitely won’t work.

Kallb123 - I have tried both of the friendly name you suggested, but, neither of them worked.

mikeg1130 - device_class: garage - When use with the Garadget MQTT Cover, it only partially worked. The closed garage icon shows up, but it does not change to open. I believe the reason is that when I check the state of the entity it is always “unknown”.

As marthocoo suggested putting device_class: garage with the Cover Template worked as well.

MikeG - it sounds like your idea would work, but it just seem like a lot of trouble. HA should take one of Kallb123 idea and make it a feature.

Thanks for all of your help, but for now I will live without it. I am happy with how its currently working. I will post my final code later.

Here is the final code that I used to get it working.
Also NOTE: You could that removed icon_template below use device_class: garage in customize.yaml to dynamically change the icon instead. Because I have two doors I duplicated all of this for the next door.

### This goes under Cover Section in your configuration.yaml file ###
cover: 
  - platform: mqtt
    name: "Left Garage"
    command_topic: "garadget/LeftGarage/command"
    state_topic: "garadget/LeftGarage/status"
    payload_open: "open"
    payload_close: "close"

 - platform: template
   covers:
      garage_door_left:
         friendly_name: "Garage Door Left"
         icon_template: >
           '{% if is_state("sensor.garage_status_left", "closed") %}
              mdi:garage
           {% else %}
              mdi:garage-open
           {% endif %}'
        open_cover:
          service: cover.open_cover
          data:
             entity_id: cover.left_garage
        stop_cover:
          service: cover.stop_cover
          data:
             entity_id: cover.left_garage
        close_cover:
        service: cover.close_cover
        data:
          entity_id: cover.left_garage


### This goes in your sensors.yaml file or in the Sensor Section or the configuration.yaml ###
- platform: mqtt
  name: 'Garage Status Left'
  state_topic: 'garadget/LeftGarage/status'
  value_template: '{{ value_json.status }}'


## GARAGE GROUP ##
garage_doors:
name: Garage Doors
entities:
  - cover.garage_door_left
  - cover.garage_door_right
1 Like

I have an idea that I want to try and that is to use INPUT_SELECT for the Garage Doors and dynamically set the state based on the current status.

Do you think that will work?

I have garagepi and mine already look like the OP desired. But I want to have the left garage be the mdi:garage-open-variant // garage-variant since its a 2x stall.
I’ve tried but can’t get it working.

Deejayfool, has developed a true dynamic icon, the best I have ever seen: