Can you see the code when Home Assistant makes a Cover from a Hubitat Device?

Hi - Been getting up to speed on Home Assistant over the last few months as I plan to migrate everything from Hubitat to it very slowly.

I have HA setup on a dedicated mini pc with Zigbee, Bluetooth, Zwave, and Matter all working fine for a few devices. Among a bunch of integrations, I also have the Hubitat integration setup to share some devices over to HA.

Where I am stuck overall is truly understanding how to create covers, and the variety of options that exist. Setting up my garage doors in Hubitat was all GUI driven where you pick the relays, contact sensors, delay times, etc - and it does the work for you. HA doesn’t seem the same, but it did automatically create a cover for my two Hubitat garage doors that use Z-wave relays and Zigbee tilt sensors.

I was wondering if I dug through the file explorer could I see the code that it used to create those covers? I looked, but I didn’t see anything like I was expecting.

I have a variety of other covers to make - some template (I believe) and some passive, and I have struggled. I have one that happens to be all ESPHome based (a ESP32 board, a 4 channel relay, and a single contact sensor) where 2 of the relays open / close my chicken coop door and the contact sensor confirms it is closed. That cover seems to function just fine, but it does not do the typical ā€œopen, opening, closed, closingā€ and merely says ā€œclosed, open 100%ā€. The code is from snippets I have found on here, perhaps a bit older as HA says the format is deprecated and suggests new formatting.

I figured a good way to learn that would be to just see what it did from Hubitat, if possible.

Then I’ll try working on some of my other covers that mix Z-wave and Zigbee devices, mostly.

Thanks!

Define ā€˜create a cover’ what are you actually trying to accomplish. Then we tackle that problem. Told us a lot of what you looked at but it’s unclear what you’re trying to accomplish.

Also, no what you would be looking at is almost certainly not what you need right now .

1 Like

Hi Nathan - Thanks for posting.

I will admit I may not know the terms yet, but I have been trying to learn.

Effectively - I was very happy my garage doors -which are setup in Hubitat - showed up in HA and function as expected. I thought I could learn from there to make more covers, cobbling together other things I learned from reading the forums.

First try was to make my chicken coop door work natively with HA, just as it did with Hubitat (not using the Hubitat integration). It has one relay to open the door and another relay to close the door, with a single contact sensor to confirm it is closed.

My relevant esphome code…

switch:

  - platform: gpio
    name: "Coop Door Open Relay"
    pin: 02
    id: relay_open
    # Use 'True' if your relay activates on a LOW signal
    inverted: True
    # Set the default state on boot (e.g., always off)
    restore_mode: ALWAYS_OFF
    on_turn_on:
      - delay: 8000ms
      - switch.turn_off: relay_open

  - platform: gpio
    name: "Coop Door Close Relay"
    pin: 25
    id: relay_close
    # Use 'True' if your relay activates on a LOW signal
    inverted: True
    # Set the default state on boot (e.g., always off)
    restore_mode: ALWAYS_OFF    
    on_turn_on:
      - delay: 8000ms
      - switch.turn_off: relay_close

binary_sensor:

  - platform: gpio
    pin:
      number: GPIO5  # Replace with your GPIO pin
      mode: INPUT_PULLUP
      inverted: False  # Typically True for reed switches
    name: "Coop Door Sensor"
    device_class: door # Helps Home Assistant show open/closed icons
    id: coopdoor_sensor

Then there is the code that HA suggested when I tried to make a cover inside the configuration.yaml using older formatting…

template:
- cover:
  - device_class: door
    unique_id: coop_door_1
    open_cover:
    - target:
        entity_id:
        - switch.coop_open_relay
      action: switch.turn_on
    close_cover:
    - target:
        entity_id:
        - switch.coop_close_relay
      action: switch.turn_on
    default_entity_id: cover.coop_door
    icon: "{% if is_state('binary_sensor.coop_door_sensor', 'off')
      %}\n  mdi:door\n{% else %}\n  mdi:door-open\n{% endif %}"
    name: Coop Door
    state: '{{ is_state(''binary_sensor.coop_door_sensor'', ''on'')
      }}'      

And the Mushroom card code:

type: custom:mushroom-cover-card
entity: cover.coop_door
show_buttons_control: true
grid_options:
  columns: 6
  rows: 2
show_position_control: false
fill_container: false
card_mod:
  style: |
    ha-card {
      {% if is_state('cover.coop_door', 'open') %}
        --card-mod-icon-color: green;
        border: 2px solid green;
      {% elif is_state('cover.coop_door', 'closed') %}
        --card-mod-icon-color: red;
      {% endif %}
    }
    .icon {
      {% if is_state('cover.coop_door', 'opening') %}
        animation: pulse 1s infinite;
      {% endif %}
    }
    @keyframes pulse {
      0% { opacity: 0.5; }
      100% { opacity: 1; }
    }

So, all functions in this one work fine, except I can not figure out how to make the status track as I’d like: open, opening, closed, closing. I assume that is in my configuration.yaml, and even as I follow others leads, I always get: opened 100% or closed only.

Once I get rolling, I do have zigbee relays that control roller shades I want to recreate in HA, as well as what seems like a passive cover where the open / close state of my HVAC dampers is indicated using contact sensors in esphome to make sure they are in sync with the calls for heating / cooling (one damper controller broke, so for a few months one zone was always open and wasting energy). Then one day, the garage doors natively in HA.

Thanks again.

1 Like

Ahh ok I gget it now. Yeah can he weird sometimes.

So the biggest thing you’ll find out in HA there are multiple ways to do things and most of them work. Some of them are easier than others and some are. Well. They work. :sunglasses:

When you’re doing things like this what I like to do is find the most complete ā€˜thing’ as close to the hw as possible…

Set that up correctly and instead of a couple relays the device exposes as a cover. Then everything else upstream just uses standard cover controls…

Im doing a hot tub cover lifter right now and I’m building everything including the safety lockout into the esp32. It will expose two buttons (the momentary Deadman, and e-stop) and the cover control itself. This also meets my requirement that the safety is in the hardware as close to the actual actor as possible…

I’ve got no custom code behind those buttons it’s all in the esp logic with that cover. Maybe that helps?

1 Like

Okay sounds good I will dig into this. So basically it seems like inside the ESPhome code it’s possible to put the cover functions and then HA doesn’t require any cover functionality in the configuration file?

1 Like

Bingo then esphome brings the entity in AS a cover and it behaves like one.

Your other option (remember I said there were many) is a template cover which is basically the same as above one layer up the cake.

Orrr you could roll your own scripts and make a button on the interface… (see where I’m going) you have tons of options of varying complexity. Some people do it differently for various reasons. My personal solution. As close to he hw as possible and let the system do the hard parts for me. (I’m lazy that way)

1 Like