Custom Component: Cover Time Based

Cover Time Based Component

Cover Time Based Component for your Home-Assistant (http://www.home-assistant.io)

With this component you can add a time-based cover. You can set a switch to open and another to close the cover.
For example, you can use an Aqara Wall Switch Double Key and standard 4 wire motor roller shutters to do this.

Buy me a coffee

Download from GitHub

Installation

  • Copy all files in custom_components/cover_time_based to your /custom_components/cover_time_based/ directory.
  • Restart Home-Assistant.
  • Add the configuration to your configuration.yaml file.

Usage

To use this component in your installation, add the following to your configuration.yaml file:

Example configuration.yaml entry

cover:
  - platform: cover_time_based
	devices:
	  room_rolling_shutter:
	   name: Room Rolling Shutter
	   travelling_time_down: 23
	   travelling_time_up: 25
	   open_switch_entity_id: switch.wall_switch_right
	   close_switch_entity_id: switch.wall_switch_left
	   aliases:
	    - room_rolling_shutter
4 Likes

This is excellent. And what is best, that it remembers state between HA restarts.

Now the problem is that my covers are RF based, and there are 3 separate RF codes needed for each cover: one for up, one for down and one for stop (the RF codes can be sent out through MQTT via an RF bridge running Tasmota). I tried making mqtt switch with ON state or up code and OFF state for stop code, and respectively for down/stop code, but it doesn’t work because when I hit up arrow in lovelace it just moves a bit then stops.

But looking through your code this can be modified easily.

And here is my fork, modified for RF covers: download from GitHub

Edit: also available in HACS:
hacs_badge

You have to set RF-sending scripts to open, close and stop the cover.
For example, you can use an RF-Bridge running Tasmota firmware to send out RF codes, with RF-based motor roller shutters to do this.

Example configuration.yaml entry

cover:
  - platform: cover_rf_time_based
    devices:
        my_room_cover_time_based:
        name: My Room Cover
        travelling_time_up: 36
        travelling_time_down: 34
        close_script_entity_id: script.rf_myroom_cover_down
        stop_script_entity_id: script.rf_myroom_cover_stop
        open_script_entity_id: script.rf_myroom_cover_up
        aliases:
          - my_room_cover_time_based

Example scripts.yaml entry

'rf_myroom_cover_down':
  alias: 'RF send MyRoom Cover DOWN'
  sequence:
  - service: mqtt.publish
    data:
      topic: 'cmnd/rf-bridge-1/backlog'
      payload: 'rfraw XXXXXXXXX....XXXXXXXXXX;rfraw 0'

'rf_myroom_cover_stop':
  alias: 'RF send MyRoom Cover STOP'
  sequence:
  - service: mqtt.publish
    data:
      topic: 'cmnd/rf-bridge-1/backlog'
      payload: 'rfraw XXXXXXXXX....XXXXXXXXXX;rfraw 0'

 'rf_myroom_cover_up':
  alias: 'RF send MyRoom Cover UP'
  sequence:
  - service: mqtt.publish
    data:
      topic: 'cmnd/rf-bridge-1/backlog'
      payload: 'rfraw XXXXXXXXX....XXXXXXXXXX;rfraw 0'

David, million thanks for your work which made this possible!

4 Likes

For proper icon display (opened/closed) customization can be added to configuration.yaml based of what type of covers you have, either one by one, or for all covers at once:

homeassistant:
  customize:
    cover.my_room_cover_time_based:
      device_class: shutter
  customize_domain:
     cover:
      device_class: shutter

More details: https://www.home-assistant.io/docs/configuration/customizing-devices/#device-class

Thanks to you :smiley:

Great work everyone. Finally we are starting to see a complete timed cover component. One thing: I use broadlink component to open, close and stop my covers. Is there a way to incorporate these either by making the cover_time_based have a stop switch or for cover_rf_time_based to call services so that a switch can be called without creating scripts for each action.
Thank you.

edit: After some testing with the cover_rf_time_based component I must say that this is a great addition to homeassistant. The cover state changes only after the curtains are fully opened or closed. The slider moves accordingly in real time. Both down and up buttons are always available during an ascend or descend. This is just perfect. Thank you @robi and @davidramosweb

I also thought that it would be great to be able to specify some services directly.

But going through Davis’s code made me realize that the requirement to create the scripts is a way to stimulate people to adapt the component to their custom requirements straight in Home Assistant, without the need to learn programming in Py. One can create a script for anything. You can have any customly developed thing over there to move your curtains which easily embed in your script and then hook it into the time based cover component. You can even embed automations into scripts etc. this gives best flexibility.

There are literally dozens of cover-moving systems out there which weren’t designed originally to be integrated into a smart home system, it’s nearly impossible to create a custom component for each type. Now this is a more universal solution for such cases.

1 Like

A bit of update on the rf version: removed (commented out) stopping in auto_stop_if_necessary because that prevents sending out the trigger again if needed. Sometimes it may happen that due to RF interference the signal is not received by the cover, and since there’s no feedback from the cover itself, HA will assume the cover changed state while this might not be true. In such cases the user wishes to send out the trigger again, this was followed by a stop until now.
(this came from the double-switch approach, there it was required, here it is not).

1 Like

Hello.

First, I want to thank you both for your custom_component.

I’m trying to install it, I need RF version because I have 3 switchs. I write the example configuration, but I receive this error. I’ve tried to change indentation, but doesn’t work.

Thank you in advance again.

I was just about to ask for this and thank you for the quick fix.

There should be one more tab on the configuration:

cover:
  - platform: cover_rf_time_based
    devices:
        my_room_cover_time_based:
          name: My Room Cover
          travelling_time_up: 36
          travelling_time_down: 34
          close_script_entity_id: script.rf_myroom_cover_down
          stop_script_entity_id: script.rf_myroom_cover_stop
          open_script_entity_id: script.rf_myroom_cover_up
          aliases:
            - my_room_cover_time_based

Thank you so much. :sweat_smile:

One question, whats the meaning for “aliases”?

Hi all
Can someone explain a bit more what this component does? I just tried to go to github but it is not working right now.
I have an awning which is working with a tuya wifi gang. It only reports open and close status though and if it is half opened the state is known. What I am missing is to know how much the awning is opened, as a percentage or even as seconds. For example if the awning is completely open then to report 100% or 30 seconds and if it is half opened 50% or 15 seconds.
Except from the above is there anything else that this component would offer in my setup?

It is intended for covers which do not report back anything. Their status is assumed by the last commands which were issued. One has to measure the time the cover needs to open and close respectively, thus Home Assistant can assume based on the time passed between the commands (say open and then stop) the percentage the cover is opened. And vice-versa, setting a position through Home Assistant will do nothing else than send a stop command after the corresponding percentage of time has passed since the open command.

As long as you can control your awning with open/close or open/stop/close commands, you can use this component. But it won’t take in account the real state reported by your switches.

1 Like

Aliases is optional. If you don’t want to let Home Assistant name the entity_ids of your covers by your friendly name, but want to enforce your own entity_id name.

The fix broke positioning, so I made a different approach. Update cover.py, delete __pycache__ folder and restart HA (RF version).
Also added to debug logging the cover names so we can differentiate in the log which cover does what.

Did as instructed. Thank you.

Thank you for this.
I’ve been struggeling with cover templates the last few days and just couldn’t find a way to make the cover aware of it’s position.

Is it possible with your custom component to set the cover to a specific position?
I use it to control my shades and sometimes I would like them to go down for about 50%.
If so, could you give an example on how to do this?

Edit:
Okay, just tried it out and it’s worting great so far!
And I noticed the slider when clicking the entity.
Now I have to figur out how to get the slider on the dashboard, below the cover buttons…
(Any pointers apreciated!)

1 Like

you should add this RF covers plugin to HACS, that would make installation super easy.

anyone know of a way to make the slider appear vertically?

You should add some indicators to the position, maybe shut/open or 0% and 100%
Screenshot 2020-04-27 at 14.32.55