Garage Door Dynamic Icon

Hello,

I am trying to get my garage door icon to change with the status of open/closed. I have done this successfully with battery icons but the same code format is not working with my garage door. The only difference is that the garage door is already an entity (cover.garage_door) and I am not creating my own sensor from the data.

Battery Icon Code (this works):

- platform: template
  sensors:
    garage_door_battery:
      friendly_name: "Battery"
      value_template: "{{states.cover.garage_door.attributes.battery_level | round (0)}}"
      unit_of_measurement: '%'
      icon_template: 
        '{% if (states.sensor.garage_door_battery.state) == "100" %}
          mdi:battery
        {% elif (states.sensor.garage_door_battery.state) >= "90" %}
          mdi:battery-90
        {% elif (states.sensor.garage_door_battery.state) >= "80" %}
          mdi:battery-80
        {% elif (states.sensor.garage_door_battery.state) >= "70" %}
          mdi:battery-70
        {% elif (states.sensor.garage_door_battery.state) >= "60" %}
          mdi:battery-60
        {% elif (states.sensor.garage_door_battery.state) >= "50" %}
          mdi:battery-50
        {% elif (states.sensor.garage_door_battery.state) >= "40" %}
          mdi:battery-40
        {% elif (states.sensor.garage_door_battery.state) >= "30" %}
          mdi:battery-30
        {% elif (states.sensor.garage_door_battery.state) >= "20" %}
          mdi:battery-20
        {% elif (states.sensor.garage_door_battery.state) >= "10" %}
          mdi:battery-10
        {% else %}
          mdi:battery-alert
        {% endif %}'

Code in my covers.yaml:

- platform: template
  covers:
    garage_door:
      icon_template:
        '{% if (states.cover.garage_door.state) == "closed" %}
          mdi:garage
         {% else %}
          mdi:garage-open
         {% endif %}'

Enitity:

Front End:
image

2 Likes

Try this:

    icon_template: >-
      {% if is_state('sensor.garage_door', 'closed') %}
        mdi:garage
      {% else %}
        mdi:garage
      {% endif %}

Might be easier ways but uou could use an input_boolean as the switch which would then have an on and off state and so change the icon colour. Then just trigger the door with an automation dependant on the input_boolean state.

That did not work, unfortunately.

After defining my garage door cover, I used customize to indicate that the cover was of the “garage” device class. This gave me the open/closed garage door icon automatically.

  customize:
    cover.garage_overhead_door:
      device_class: garage

More on customizing entities is available in the docs.

2 Likes

This worked!

I added this to my customize.yaml:

#Garage Door
cover.garage_door:
friendly_name: Front
device_class: garage

image

Thanks so much!

2 Likes

Interesting, I didn’t know there was built-in icon switching functionality based on the device class. Thanks for the update.

@cjlee89 please could I ask you for your configuration.yaml config for your garage door.
Mine is this below

GARAGE DOOR

cover:

  • platform: mqtt
    name: “GARAGE DOOR”
    state_topic: “cmnd/2/POWER2”
    command_topic: “cmnd/GARAGE_DOOR/POWER”
    payload_open: “ON”
    payload_close: “ON”
    payload_stop: “ON”
    state_open: “ON”
    state_closed: “OFF”
    optomistic: false
    retain: false
    my customize.yaml I did as you did. What happens with me is that the door opens and closes but does not show up or down state. thanks Mark

Sure! Mine is coming over from Wink though since HA does not like my controller - http://www.gocontrol.com/detail.php?productId=4

https://github.com/cjlee89/Home-Assistant

1 Like

I seem to have the same problem after updating HA
What do I need to change in the Card Configuration

Also I have this under customize but it has no affect

  customize:
    # Add an entry for each entity that you want to overwrite.
    cover.sonoff_sv_garage:
      device_class: garage
      homebridge_cover_type: garage_door
      friendly_name: Garageport

Also I just took my first step into doing these Card configuration and thought that would generate a lovelaceui.yaml file? but I don’t seem to have one?

I had the same issue. And I see you’re also using a Sonoff SV. I don’t know if you’ve experience this, but when I “open” the door twice in a row, it basically just toggled it twice, and ended up closing it. I wrapped the MQTT garage door cover with a template cover that prevents this. And the template cover also has a custom dynamic icon that works :slight_smile:

cover:
  - platform: mqtt
    name: garagedoor_mqtt
    command_topic: cmnd/GarageDoor/POWER
    payload_open: "ON"
    payload_close: "ON"
    payload_stop: "ON"
    state_topic: cmnd/GarageDoor/POWER2
    state_open: "ON"
    state_closed: "OFF"
    optimistic: false
    retain: false

  - platform: template
    covers:
      garagedoor:
        friendly_name: Garage Door
        value_template: '{{ is_state("cover.garagedoor_mqtt", "open") }}'
        icon_template: '{% if is_state("cover.garagedoor_mqtt", "open") %}mdi:garage-open{% else %}mdi:garage{% endif %}'
        open_cover:
          - condition: state
            entity_id: cover.garagedoor_mqtt
            state: 'closed'
          - service: cover.open_cover
            entity_id: cover.garagedoor_mqtt
        close_cover:
          - condition: state
            entity_id: cover.garagedoor_mqtt
            state: 'open'
          - service: cover.close_cover
            entity_id: cover.garagedoor_mqtt

I basically ignore cover.garagedoor_mqtt in favour of cover.garagedoor in all cases.

Hi @SteveDinn

This sounds really promising!
Could explain how to do this? is all this coded directly in the new configure UI or is this for the configuration.yaml (Sorry I am still old school)

cover:
  - platform: mqtt
    name: "sonoff sv garage"
    state_topic: "cmnd/garagestate/POWER2"
    command_topic: "cmnd/Sonoff_SV_Garage/POWER"
    payload_open: "ON"
    payload_close: "ON"
    payload_stop: "ON"
    state_open: "ON"
    state_closed: "OFF"
#    optomistic: false
#    retain:false

Would then be:

cover:
  - platform: mqtt
    name: garagedoor_mqtt
    command_topic: cmnd/Sonoff_SV_Garage/POWER
    payload_open: "ON"
    payload_close: "ON"
    payload_stop: "ON"
    state_topic: cmnd/garagestate/POWER2
    state_open: "ON"
    state_closed: "OFF"
    optimistic: false
    retain: false

  - platform: template
    covers:
      garagedoor:
        friendly_name: Garage Door
        value_template: '{{ is_state("cover.garagedoor_mqtt", "open") }}'
        icon_template: '{% if is_state("cover.garagedoor_mqtt", "open") %}mdi:garage-open{% else %}mdi:garage{% endif %}'
        open_cover:
          - condition: state
            entity_id: cover.garagedoor_mqtt
            state: 'closed'
          - service: cover.open_cover
            entity_id: cover.garagedoor_mqtt
        close_cover:
          - condition: state
            entity_id: cover.garagedoor_mqtt
            state: 'open'
          - service: cover.close_cover

Where to put this? and what about the Raw config editor do I need to create something under cards?
Sorry still trying to wreck my head around the new cards :slight_smile:

Best regards
Casperse

1 Like

I haven’t touched the configure UI at all. I’m editing everything in Visual Studio Code. Everything I posted is for configuration.yaml.

From what I posted here, you only have to add “cover.garagedoor” to your cards, and you can keep “cover.garagedoor_mqtt” completely hidden.

Thanks!

I tried adding it and comment the old code out like this:

cover:
#  - platform: mqtt
#    name: "sonoff sv garage"
#    state_topic: "cmnd/garagestate/POWER2"
#    command_topic: "cmnd/Sonoff_SV_Garage/POWER"
#    payload_open: "ON"
#    payload_close: "ON"
#    payload_stop: "ON"
#    state_open: "ON"
#    state_closed: "OFF"
#    optomistic: false
#    retain:false

  - platform: mqtt
    name: garagedoor_mqtt
    command_topic: cmnd/Sonoff_SV_Garage/POWER
    payload_open: "ON"
    payload_close: "ON"
    payload_stop: "ON"
    state_topic: cmnd/garagestate/POWER2
    state_open: "ON"
    state_closed: "OFF"
    optimistic: false
    retain: false

  - platform: template
    covers:
      garagedoor:
        friendly_name: Garage Door
        value_template: '{{ is_state("cover.garagedoor_mqtt", "open") }}'
        icon_template: '{% if is_state("cover.garagedoor_mqtt", "open") %}mdi:garage-open{% else %}mdi:garage{% endif %}'
        open_cover:
          - condition: state
            entity_id: cover.garagedoor_mqtt
            state: 'closed'
          - service: cover.open_cover
            entity_id: cover.garagedoor_mqtt
        close_cover:
          - condition: state
            entity_id: cover.garagedoor_mqtt
            state: 'open'
          - service: cover.close_cover

And I selected the new: cover.garagedoor

For some reason its not working correctly?
Pressing the up arrow opens the garagedoor but it looks like this

image

I then have to wait and press the Up arrow again to close the garagedoor?
I have a magnet that should tell HA that the door is open and switch to the Down Arrow?
I also noticed that the old square “stop button” is gone?

What have I not changed correctly?
Again thanks for your help, its much appreciated

BTW: I even made it as a switch because the notification gave me problems: :thinking:

##########################
###  Garage Switch     ###
##########################
switch:
  - platform: template
    switches:
      garagen:
        value_template: "{{ is_state('cover.sonoff_sv_garage', 'open') }}"
        turn_on:
          service: cover.close_cover
          data:
            entity_id: cover.sonoff_sv_garage
        turn_off:
          service: cover.open_cover
          data:
            entity_id: cover.sonoff_sv_garage
        icon_template: >-
          {% if is_state('cover.sonoff_sv_garage', 'open') %}
            mdi:garage-open
          {% else %}
            mdi:garage
          {% endif %}

If you look at the documentation for the template cover entity, I just left out the “stop_cover:” section, but you could add:

stop_cover:
  service: cover.stop_cover
  entity_id: cover.garagedoor_mqtt

I left it out because there was no good condition to prevent it from just opening or closing the door if it wasn’t moving, since they’re all the same commands.

If you watch your MQTT broker’s topics, do you see the garage door’s state topic get published when the reed switch is opened or closed?

Hmm yes the same signal toogles the 3 different states: Up, stop, Down

Hmm this is what I see in the log

1552939960: |-- data=username=casperse&password=&topic=&acc=-1&clientid= 1552939960: |-- aclcheck(casperse, stat/Sonoff_S20_3/RESULT, 2) SUPERUSER=Y by http 1552939960: |-- Cached [1C3017049859B695686D5DE3BAA81E313193CC3D] for (client id not available,casperse,2) 1552939960: |-- mosquitto_auth_acl_check(..., client id not available, casperse, stat/Sonoff_S20_3/POWER, MOSQ_ACL_WRITE) 1552939960: |-- url=http://127.0.0.1:8080/superuser 1552939960: |-- data=username=casperse&password=&topic=&acc=-1&clientid= 1552939960: |-- aclcheck(casperse, stat/Sonoff_S20_3/POWER, 2) SUPERUSER=Y by http 1552939960: |-- Cached [BAA579721889F040F8ED090BAB381155AD7F738A] for (client id not available,casperse,2) 1552939960: |-- mosquitto_auth_acl_check(..., client id not available, casperse, stat/Sonoff_S20_3/POWER, MOSQ_ACL_READ) 1552939960: |-- aclcheck(casperse, stat/Sonoff_S20_3/POWER, 1) CACHEDAUTH: 0 1552939977: |-- mosquitto_auth_acl_check(..., client id not available, casperse, cmnd/Sonoff_SV_Garage/POWER, MOSQ_ACL_WRITE) 1552939977: |-- aclcheck(casperse, cmnd/Sonoff_SV_Garage/POWER, 2) CACHEDAUTH: 0 1552939977: |-- mosquitto_auth_acl_check(..., client id not available, casperse, cmnd/Sonoff_SV_Garage/POWER, MOSQ_ACL_READ) 1552939977: |-- aclcheck(casperse, cmnd/Sonoff_SV_Garage/POWER, 1) CACHEDAUTH: 0

BTW
Did you also run these special command on the Sonoff_SV when setting it up?
I found some update to them for the web console

Tasmota updates have changed some necessary settings!
Here’s what you need now: (Thanks Chris Norton)
Switchretain 1
Powerretain 1
switchtopic2 garagestate
switchmode1 0
switchmode2 2

GPIO 14 to 10 Switch2
GPIO 4 to 22 Relay2
pulsetime1 1

Hrm
I’m going to say, “probably”. It’s been a while since I did it, but I followed DrZzzs’ video on it.

Are you using mosquitto as your MQTT broker? You can watch the published topics using this command:

mosquitto_sub -v -h localhost -p 1883 -u [username] -P [password] -t '#'

As for your reed switch, I didn’t see any ‘garagestate’ topics in that log.

Yes I am using the Mosquitto broker
Would that command be used when logged in through putty to HA? (Sorry I haven’t looked at MQTT before, I would love a UI :slight_smile: for that)

I just removed the code for the switch.garagedoor and that have made the arrow switch state (So the it might just be working now!)

one more thing I made a notification on the state change of my switch.garagedoor
How are you triggering a notification when somebody opens the door?
My setup before this change was like this (I even had IOS notification working with a live video feed, none of this works after the many updates sigh
)

UPDATE: I changed the trigger to garage.door and that works ok

# Automations notification (2) for garageport ALWAY (Disabled open if Nobodys home) 
  - alias: 'Notification: Garageport open'
    hide_entity: false
    initial_state: 'on'

trigger:
  - platform: state
    entity_id: cover.garagedoor
    from: 'closed'
    to: 'open'

    action:
      - service: notify.ios_group_caspersen_home
        data:
          message: "Garageporten er Ă„ben? {{ states('sensor.time') }}"
          title: "Home Assistant"

UPDATE: Its really not so reliable anymore I pressed the up arrow and it opens the garage door
I then tried to close it and nothing happened I then pressed it again and it sent multiple “push” to the garage door which made it go a little crazy (light on and off signals that the door is going down, so I had alittle lightshow for whole minute and then it closed the door?

Trying to see the commands through putty I get:
Connection Refused: not authorised.
I am using the Mosquitto user and password

Just noticed that you’re missing the conditions in the template cover. In my example, there is a condition to only execute the open script when HA thinks it is closed, and the same but opposite for the close script. That was the entire purpose of the template cover for me. Having a dynamic icon was just a bonus.

For notifications, I was using PushBullet, but I recently moved everything to Telegram. I have an automation that lets me know if the garage door opens when there’s nobody home, or if the garage door is open when we leave.

automation:

This one sends me a notification when I’ve left the door open, and everybody leaves the house, or it’s after 9pm.

  - alias: Garage door left open
    initial_state: 'ON'
    trigger:
      - platform: state
        entity_id: group.device_trackers
        to: 'off'
      - platform: time
        at: '21:00:00'
    condition:
      condition: and
      conditions:
        - condition: state
          entity_id: cover.garagedoor
          state: 'open'
    action:
      - service: notify.telegram_steve
        data_template:
          title: Garage door opened
          message: >
            Garage door has been left open
            {%- if is_state('group.device_trackers', 'off') %} and nobody is home.
            {% elif ((now().hour >= 21) or (now().hour < 7)) %} and it's a strange time.
            {% else %} but everything seems cool.
            {%- endif %}

This one will notify me if the door opens and nobody is home or it’s late. They’re pretty much the same, just with the triggers and conditions swapped. I could probably combine them into one, but they work, so I haven’t bothered.

  - alias: Garage door opened
    initial_state: 'ON'
    trigger:
      - platform: state
        entity_id: cover.garagedoor
        to: 'open'
    condition:
      condition: and
      conditions:
        - condition: state
          entity_id: cover.garagedoor
          state: 'open'
        - condition: or
          conditions:
            - condition: state
              entity_id: group.device_trackers
              state: 'off'
            - condition: time
              after: '21:00:00'
              before: '07:00:00'
    action:
      - service: notify.telegram_steve
        data_template:
          title: Garage door opened
          message: >
            Garage door has been opened
            {%- if is_state('group.device_trackers', 'off') %} but nobody is home.
            {% elif ((now().hour >= 21) or (now().hour < 7)) %} and it's a strange time.
            {% else %} but everything seems cool.
            {%- endif %}