Customizing garage door icons

Hi team, I flashed ESPHome on a garage door cover and I can control it through Home Assistant. I am trying to get the icon for the garage door to reflect the status of the garage door. I am having trouble conceptualizing the best way to do this in ESPHome. I am hoping to do it there to keep everything self-contained and clean. I imagine it involves using lambda but I do not have experience with C++. I have done plenty of searching and have had trouble getting it to work. Could someone lend me a hand?
Bonus points if you can tell me why when I expose these devices to google home, it sees them but tells me “something went wrong” when I click on them :face_with_raised_eyebrow:
EDIT: Found the problem with google assistant. covers need a secure_devices_pin configured.

cover:
  - platform: template
    name: "Main Garage Door"
    id: maingaragedoor
    device_class: garage
    lambda: |-
      if (id(doorclosed).state) {
        return COVER_CLOSED;
      } else {
        return COVER_OPEN;
      }
    open_action:
      - if:
          condition:
            binary_sensor.is_off: doorclosed
          then:
            - logger.log: "Door is already open"
          else:
            - switch.turn_on: greenLED
            - if:
                condition:
                  switch.is_on: relay
                then:
                  # just in case someone manually changed it
                  - switch.turn_off: relay
                  - delay: 0.5s
            # Turn the OPEN switch on briefly
            - switch.turn_on: relay
            - delay: 0.2s
            - switch.turn_off: relay
            - switch.turn_off: greenLED
    close_action:
      - if:
          condition:
            binary_sensor.is_on: doorclosed
          then:
            - logger.log: "Door is already closed"
          else:
            - switch.turn_on: greenLED
            - if:
                condition:
                  switch.is_on: relay
                then:
                  # just in case someone manually changed it
                  - switch.turn_off: relay
                  - delay: 0.5s
            # Turn the OPEN switch on briefly
            - switch.turn_on: relay
            - delay: 0.2s
            - switch.turn_off: relay
            - switch.turn_off: greenLED
    optimistic: true
    assumed_state: true

I don’t understand. It should already change the icon based on the current state. Or are you wanting something other than the open/closed garage door icons?

And why do you have these as true? Seems like you already have a way to know whether it’s open or closed. You could also greatly simplify your open and close actions with these false, since it wouldn’t let you try to do an action that doesn’t match the current state.

I am trying to replace icon with a 2-door garage icon. Simply want to instead use mdi:garage-variant and mdi:garage-open-variant.

Thanks for tips on optimistic/assumed state. Not much thought was put into it. I just lifted this from ESPHome customization for NEXX Garage doors deluxe example.

Gotcha. I don’t think that’s possible in ESPHome (without basically doing it all in C++), unfortunately. I think the only way to use dynamic icons for a cover that aren’t included in one of the device class options is to use a template cover in Home Assistant:

Actually kind of a bummer, as I just happen to be working on a project where it’d be nice to have custom icons for some covers but I’d prefer everything to be fully local on the ESP.

I’ll also add that there IS an icon option in ESPHome covers, but that only sets a static icon which isn’t very useful.

Thanks. That’s too bad if it doesn’t work. One thing though, you said its not possible without doing it in C++. Isn’t a lambda function calling in C++?

Yes, but I was meaning making the entire cover, not just changing the icon.

https://esphome.io/custom/custom_component.html

Compiles and uploads without errors, doesn’t change the icon in HASS tho. Maybe after restarting, but not live.

switch:
- platform: gpio
    name: None
    id: ${device_name}_relay
    icon: mdi:electric-switch
    entity_category: diagnostic
    pin: 
      number: 12
    restore_mode: ALWAYS_OFF
    on_turn_on:
      - lambda: |-
          id(${device_name}_relay).set_icon("mdi:electric-switch");
    on_turn_off:
      - lambda: |-
          id(${device_name}_relay).set_icon("mdi:electric-switch-closed");

Also:, tested and tried

cover:
  - platform: template
    device_class: door # gate - not working in Google Ass

Would that change the icon in the ESP device web_server (if you’re using that?)

I can change the icon in HA easily enough. I know there’s a dire warning about using web_server in ESPHome devices, but I’ve found it occasionally useful. Having custom icons would be a nice touch.

I see - My hope was to make the cover in ESPHome rather than in configuration.yaml. I am trying to keep everything I can in the UI and everything self-contained. It is otherwise too frustrating when, say two years later, one tries to recall how something was configured when it breaks. Don’t ask me how I know :wink:

Thanks, does this give an advantage over the code I had in OP? The cover is showing up just fine (and now I was able troubleshoot and get get it to work in google home) but the custom icons reflecting are not there yet.

Nope, web server is not showing any icons.

I use web server in all my 36 devices, couldnt live without it. (testing, logging, internal entities etc) and no problems.

Not sure where it is used then, if it doesn’t change in HA - ESPHome: esphome::EntityBase Class Reference :thinking: I just added it hoping it would work, and havent removed it. This is my device.

@nima - yes, i also wanted a garage door and tried all the possible device classes, but garage door is unavailable in Google. Well i just read that:

covers with device types door , garage , or gate .

But mine didn’t work as gate, so i changed it to door.

Yes mine was not working until I added secure device pin. Have you tried that?

1 Like