Creating an Icon with Movement for a Garage Door

Been off the forum for several years, returning home. Have a relatively easy problem I can’t resolve; my skills are rusty. I first dug through posts looking for a solution, but with each, there was some variable that didn’t fit my scenario:

Roll-Up door on a remote metal outbuilding. It has a cheap PRC aftermarket motor that’s not compatible with any US Vendors. I was able to automate it using an Arduino R3 with an Ethernet Hat.

Arduino Setup:
-Door Closure Warning Sequence (15 secs): When triggered for a door closure, Pin 3 sends a pulsating 5VDC to a buzzer and an LED flasher.

  • Closing Door Trigger Sequence: At expiration of a ‘warning sequence’, Pin 5 sends a dry contact closure (5 seconds) to the motor control panel, closing the door.
  • A magnetic sensor at the bottom of the door sets pin 2 to high, the Arduino sends a MQTT message to HA declaring “Closed” status
  • Opening Door Trigger Sequence: Virtually the same, except there is no warning period. Once the door bottom clears the mag sensor, the Arduino sends an MQTT “Open” status message.

HA Setup:

  • MQTT listening for Door Status messages, and sending trigger messages.
  • A simple door icon is set up with a trigger; when the icon is pressed, it sends an MQTT trigger message to the Arduino. When door status messages (High or Low) are received, the status is flipped, and the Icon’s color and shape change. Nothing fancy, and it works

My Problem: There is no immediate change to the button when it is pressed. The gap can be as long as 40 seconds before the proper status updates and changes occur, so other family members are mashing the button repeatedly, thinking the button is stuck or not responding.

What I need: A transitory “DOOR MOVING” state that provides a visual confirmation that the door was triggered and is moving. I’ve tried various solutions, including dumb timers, but nothing works. Since the Arduino only sends two states, there is no actual “movement” state to use as a condition between open and closed.

I can post my coding (Arduino & HA) if needed, but it’s a very basic setup.

Sending Appreciation in advance for any assistance. I recruited an AI engineer initially to help; it screwed up my code so bad it took two days to get back to baseline. Thanks … Brian (Seabass)

Create 2 buttons, and use a hide condition to hide a button when door is not-open or not-closed?

Already got that…it doesn’t help, the binary sensor only reports one end or the other. I need an animation, flashing box, anything that will show that the door is in motion

I has a similar case (something with power on/off).

So I have 2 buttons.

When the unit reports ‘Off’, only the On button shows.
When the On button is pushed, it changes state color, until it is really reported on.
When the unit reports ‘On’, only the Off button shows.
When the Off button is pushed, it changes state color, until it is really reported off.

You mention the binary sensor reports one end, or the other. I assume this is coming from the arduino? I am not so familiar with Arduino, but can’t you create 2 binary sensors…
One for opening (some logic on pin2 + pin3) and one for close (just pin 2)

In ESPHome that would not really be an issue, you can create as many sensors as you’d like (each with their own logic behind it)

I have a different setup but still similar as in smarting up something dumb.
Maybe you can find some inspiration from my solution?
The main relevant difference as I see it is I have two position sensors.

First I have this template (in gui) to give a position number from the two sensors:

{% set c = -50 if states('binary_sensor.garasje_garasjeport_closed_opening') == 'off' else 0 %}
{% set o = 100 if states('binary_sensor.garasje_garasjeport_open_opening') == 'off' else 50 %}
{{ c + o }}

Then I have this template in config.yaml for the button:

- switch:
    - unique_id: fabe1d3a-bdb0-4ab4-8f7f-aaf1600db12e
      turn_on:
        - action: switch.turn_on
          target:
            entity_id:
              - switch.shelly_garasje_switch_2
      turn_off:
        - action: switch.turn_on
          target:
            entity_id:
              - switch.shelly_garasje_switch_2
      default_entity_id: switch.garasjeport2
      icon:
        "{% if states('sensor.garasjeport_posisjon') == '0' %}\n  mdi:garage\n
        {% elif states('sensor.garasjeport_posisjon') == '50' %}\n  mdi:garage-alert\n
        {% else %}\n  mdi:garage-open\n
        {% endif %}"
      state: "{{ states('sensor.garasjeport_posisjon')|int >0 }}"
      name: garasjeport2

This makes the button show an alert symbol while the garage door is not open and not closed.
(PS: my dumb garage door expects a button push, so I have a different automation which turns off ‘switch.shelly_garasje_switch_2’ 150ms after it’s activated.)

You’re not saying where your delay comes from, is it just the mechanics from your 15s timer and then the door closing? In that case maybe you can solve it in a similar way as I did, just replacing my “open sensor” with a helper?

Could you use a template cover and you can use a template to set any state you want:

Kris (and All): Thank YOU. The problem is that HA has no way to determine if door is in motion, it only is provided the end state. Yes, you are correct: the timer functions/loop is fully contained within the Arduino, and that status is not shared with Home Assistant.

Based on the responses, I feel I have not explained my configuration properly. Here is a flow chart of the signal path/logic:

The problem is that Home Assistant is not aware of the 15-second warning loop or the 15-second door travel time.

Possible Solutions?:

  1. Have Arduino respond (MQTT) with either a 30-second or 15 Second “Door In Motion” message, which triggers HA to display a door motion Animated Icon, until the “open” or “close” signal is received and invokes the proper door status icon.
  2. Build a 15 Second or 30 Second “wait loop” directly into HA, which triggers HA to display a door motion animated icon. The “open” or “close” message from the Arduino terminates the loop and invokes the proper door status icon.

My apologies; I realize this also involves an Arduino solution.

Your thoughts? Any examples or templates? Thanks, Brian

The easiest way would probably be your option #2.
Althoug now I’m wondering what you want. Do you want the Icon on your display to change immedeatly when it is pressed, or when the door is actually moving? Or have it show all possible states? (open/closed/warning/moving)

Since you mention other users hammering the button I imagine a change in the icon immedeatly would be the best solution for you?

One third option including more MQTT messages is having individual MQTT messages for the warning loop and the door. You could still run most of the logic on you arduino, it would just be more “verbal” to HA telling it what it’s doing.

Kris…Thanks for your response–

My preferred solution would be for the icon to respond immediately to a valid button press. From a technical standpoint, everything works fine, but the visual feedback is needed from a ‘human’ perspective to verify that the button press resulted in door movement.

I agree with using option 2, but I don’t know enough to implement the coding. When the trigger is activated, the MQTT ‘activate’ message is transmitted (published) to the Arduino. Could that signal also trigger the “door movement” animation?

Once the ‘door movement’ animation is running, it could be halted either after a timer expires, upon receipt of a ‘door’ status change MQTT message from the Arduino, or both.

As far as the “door movement” icon, that could be implemented in many ways; a pretty icon (like used with MyQ) with the door rolling open and shut would be nice, but even a simple flashing “DOOR IN MOTION” message would work; at this point, my goal is only to establish a viable underlying mechanism.

Just for the record, I am a WAN engineer, not a software person. I am good with WAN hardware, explaining processes and signal flows, but not so good at writing the underlying code to make it work.

Thanks Brian

Considering you don’t get a response back from the arduino until the door is completely closed, and you don’t want to modify your arduino, a form of wait loop within HA seems to be your solution.

I like my solution (obviously :laughing:) and would modify it to use in your case.
You could solve it with a boolean helper for my “garage door open” and a timer wich resets when necesary, As it seems more important to show that something is happening than the state being accurate on the second.

template:

{% set c = -50 if states('binary_sensor.garage_door_closed') == 'on' else 0 %}
{% set o = 100 if states('input_boolean.garage_helper') == 'on' else 50 %}
{{ c + o }}

same as my logic above just with a helper instead of an open sensor.
you could have the helper go to off as you press to close the door, and if you were to use my switch template it would immedeately change the icon since the template helper would now go from 100 to 50%

when the door actually closes and the helper hasn’t changed the template value would change to 0% changing the switch-template icon again to closed.

Opening the door would be similar, but you will need a delay to activate your helper to show the door as open and not moving.

Kris:

I understand your concept: set a countdown timer (for example, 1 minute from button press to fully closed), then change the template icons based on the percentage of time elapsed:

{% set c = -50 if states('binary_sensor.garage_door_closed') == 'on' else 0 %}
{% set o = 100 if states('input_boolean.garage_helper') == 'on' else 50 %}
{{ c + o }}
]

However, my coding skills are limited, and I am struggling to modify your template code. Can you provide a bit more detail now to set a timer to start the countdown, and explain how this all fits together?

Thanks Brian
.

no, that’s not exatly what I’m saying, and if you copy/paste my code and change the entity-names (maybe invert boolean logic if needed) you should be there.

First the template helper:
I call it:

'sensor.garasjeport_posisjon'

Create your boolean helper: ‘garage_helper’ in the gui settings → devices → helpers

{% set c = -50 if states('binary_sensor.garage_door_closed') == 'on' else 0 %}
{% set o = 100 if states('input_boolean.garage_helper') == 'on' else 50 %}
{{ c + o }}

Modify and test the helper template first in the developer tools → template to see that you got it right.
You should get ‘0’ when the gate is closed, ‘50’ while moving, and ‘100’ when open.
The boolean you need to flip yourself at this point.
Then add the code as a template helper in the gui settings → devices → helpers

Then the template switch:
I’ve written it in it’s own file, so add this line to config.yaml:

template: !include templates.yaml

Create the file templates.yaml and put this code inside:

- switch:
    - unique_id: fabe1d3a-bdb0-4ab4-8f7f-aaf1600db12e
      turn_on:
        - action: switch.turn_on
          target:
            entity_id:
              - switch.shelly_garasje_switch_2
        - action: input_boolean.turn_off
          target:
            entity_id: input_boolean.garage_helper
      turn_off:
        - action: switch.turn_on
          target:
            entity_id:
              - switch.shelly_garasje_switch_2
        - delay:
            hours: 0
            minutes: 1
            seconds: 0
            milliseconds: 0
        - action: input_boolean.turn_on
          target:
            entity_id: input_boolean.garage_helper
      default_entity_id: switch.garasjeport2
      icon:
        "{% if states('sensor.garasjeport_posisjon') == '0' %}\n  mdi:garage\n
        {% elif states('sensor.garasjeport_posisjon') == '50' %}\n  mdi:garage-alert\n
        {% else %}\n  mdi:garage-open\n
        {% endif %}"
      state: "{{ states('sensor.garasjeport_posisjon')|int >0 }}"
      name: garasjeport2
  • The unique_id: is made up, and it’s purpose is to make this template show in the UI, being able to assign it to an area and so on.
  • My turn_on and turn_off actions goes to the same switch (switch.shelly_garasje_switch_2) which another automation turns off to simulate a button press.
  • You will have to switch theese actions out with sending MQTT messages or however you send commands to your arduino.
  • I’ve added turning a boolean helper off, and on with a delay, but haven’t tested this code myself. Pay attention to entity names!

That’s the logic for your switch.

The rest is the logic for changing the icon based on the status of your first helper, in my case named:

'sensor.garasjeport_posisjon'

You should now have a switch you can use in your dashboards, and the Icon should change immediately when pressed :slight_smile:

I’m not a programmer either, nothing more than a script-kiddie. hopefully all you need to change to make this work is entity-ids, and maybe invert the logic in the first template.

Kris:

I’m sorry, I’m trying to follow your instructions, but once inside the menus, there are so many choices presented that I am not clear on what to select or where to place your code snippets. This is not your fault; it is mine. My skill level at creating templates and helpers is just above zero.

Where I need guidance:

  1. I go to devices/helpers-Add: There are dozens of helpers. I assume you want me to select either a “template” or a “sensor” helper, correct? There is no “Boolean” helper, does that refer to the name of the helper, the type, or something else?

  2. Assuming I select a “Template” helper, there are dozens of fields. Do I paste your Boolean code snippet into the “State” field?

I’m more of a visual learner, if you can create any screenshots, it would help considerably. Again, apologies for my lack of knowledge. I do appreciate your time invested in helping myself and others.

///////// Here is my current configuration.yaml/////////

# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

#SHOP SENSORS
mqtt:
  # This is the sensor that reads the "opening/closing" text from Arduino
  sensor:
    - name: "Garage Door Status"
      state_topic: "office/garage/door"
      unique_id: "garage_door_status_text"
   
    - name: "Garage Door Position"
      state_topic: "office/garage/door/position"
      unit_of_measurement: " %"
      unique_id: "garage_door_position_sensor"
  
  binary_sensor:
    - name: "Garage Door Contact"
      state_topic: "office/garage/door"
      payload_on: "OPEN"
      payload_off: "CLOSED"
      device_class: "garage_door"
      unique_id: "garage_door_binary_sensor"

 
  # This is the button that sends the "PRESS" command
  button:
    - name: "Garage Door Trigger"
      unique_id: "garage_door_relay_01"
      command_topic: "office/garage/trigger/set"
      payload_press: "PRESS" 
      
# The following is  a template I was trying to create
template:
  - cover:
      - name: "Garage Door"
        device_class: garage
        state: >
          {% if is_state('binary_sensor.garage_door_status', 'on') %}
            open
          {% else %}
            closed
          {% endif %}
        open_cover:
          service: button.press
          target:
            entity_id: button.garage_door_trigger
        close_cover:
          service: button.press
          target:
            entity_id: button.garage_door_trigger
        icon: >
          {% if is_state('binary_sensor.garage_door_status', 'on') %}
            mdi:garage-open
          {% else %}
            mdi:garage
          {% endif %}      

/////////Here is my CURRENT custom button card://///////////////

type: custom:button-card
entity: binary_sensor.garage_door_status
name: Garage Door
show_state: false
show_label: true
variables:
  moving: |
    [[[ 
      if (entity.last_changed) {
        return (Date.now() - Date.parse(entity.last_changed) < 30000);
      }
      return false;
    ]]]
state:
  - value: "on"
    color: red
    icon: mdi:garage-open
    label: OPEN
  - value: "off"
    color: green
    icon: mdi:garage
    label: CLOSED
tap_action:
  action: call-service
  service: mqtt.publish
  data:
    topic: office/garage/trigger/set
    payload: PRESS
styles:
  card:
    - animation: |
        [[[
          if (states['binary_sensor.garage_door_status'].last_updated > Date.now() - 30000)
            return 'blink 1s linear infinite';
          else return 'none';
        ]]]

Brian

Time to throw in the towel and move to another platform.

My request was simply to create a moving gagage door animation. I didnt realize that it would require advanced programming skills.

I can understand that all software requires a learning curve, but I planned on using HA to automate my home and REDUCE workload, however, HA is more of a time consuming hobby in itself. For the record, im no slouch when it come to technology, I maintained a Cisco CCIE certification for 18 years. However, unless one simply loves a continous coding project, I see little point in spending all of ones free time continously feeding a YAML monster. HA is the literal vine plant bellowing "FEED ME. FEED ME "

So as you’re painfylly aware of we all have a life outside of HA.
When you choose to add a helper and search for boolean the choise toggle will show up:

You can then test your template in the developer tools before creating the template helper:
something like this:


Try it out and see what happens when you change the boolean (toggle) and open/close your garage door. The template shoulde result ‘0’ when the gate is closed, ‘50’ while moving, and ‘100’ when open.

Try this before moving on.

After all this is just a hobby, if you don’t like it you can always choose to spend your time on something else.