Custom Component: Cover Time Based

I’m having a problem here because my covers are not a Device, they are an Entity.
How can I get around this?

Entities are correct. You say you are having problems, what’s not working are there any relevant errors in home-assistant.log?

I always try to fix things by my self because I like to know how they work. As I’m new to HA sometimes it’s not easy.

For example, I have my covers like this "“switch.persiana_do_escritorio”. I don’t have any idea on what to place in “script.office_cover_ up” for my “switch.persiana_do_escritorio”.

Same with “office_cover”…

I know that the example above it’s all I need, but I don’t understand where “script.office_cover_up” comes from…

Sorry about my English. My mother language it’s Portuguese.

Lets see if we can get you over the line by going back to the start :blush:

The device you are trying to control is a shutter, and you want to control it through a Broadlink controller. I’m guessing you want a nice button on Home Assistant front end that you can click on and the shutter opens/closes. To do that we:

Add an entity or a button to the front end selecting a Cover entity, the cover is called ‘cover.office_cover’, that cover entity is created by using the ‘cover_rf_time_based’ platform.

- platform: cover_rf_time_based
  devices:
      office_cover_time_based:
        name: Office Cover
        travelling_time_up: 17
        travelling_time_down: 17
        close_script_entity_id: script.office_cover_down
        stop_script_entity_id: script.office_cover_stop
        open_script_entity_id: script.office_cover_up

You want the cover to open so when you click on the open or up arrow on the front end it will call ‘script.office_cover_up’.

office_cover_up:
  sequence:
    - service: remote.send_command
      data:
        entity_id: remote.office_broadlink
        device: office_cover
        command: open

You can see that script is using the service ‘remote.send_command’, that’s how HA communicates with the Broadlink device. In particular it’s communicating with the broadlink device called ‘remote.office_broadlink’. It’s sending that device a command to ‘open’ the ‘office_cover’.

Well not quite, first it goes and looks up the broadlink codes file, it works out what the RF code it needs to use for command ‘open’.

{
    "version": 1,
    "key": "broadlink_remote_780f77634fbf_codes",
    "data": {
        "office_cover": {
            "close": "sgD4AZ4yDBgXDRcNFg0XDQwYCxkXDQwYFw0LGQsYDBgXDQwYFw4LGAwYDBgXDRcNCxkXDQsZFw0XDBcOCxgMGAwYCxgYDQsZDBkLGRYNDBgMGAsZFwABIZ0yDBgXDRcNFg0XDQwYDBgXDQwYFw0LGQsZCxgXDQwYFw0NGQsYDBgXDRcNCxkX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QwYFw0XDRcNDBgLGQsYDBgYDAwYFw0MGBcNCxgYDAwYFwABIp0yCxgYDRcNFw0XDQwXDBgYDQwXGA0LGAwYDBgXDQwYFw0MGAsZCxgXDRgMDBgXDQwYFw0XDRcNDBgLGQsYDBgXDgsYFw0MGBcNDBgXDA0YFwAF3A=="
        }
    }
}

NOTE: there are different ways you can setup RF codes for the Broadlink platform in HA, it’s possible yours is slightly different and you don’t have the broadlink codes file, you might need to pass the code directly from within the ‘office_cover_up’ script.

You might want to review Broadlink - Home Assistant if our still struggling with this last part.

Hope this helps!

2 Likes

First of all I would like to thank you @Eoin Eoin for the time you spent writing this post!! AWESOME!!
This is one of the reasons I moved from Homebridge to HA. Great community!!!

I appologise if I was not clear about what I need. I already have all my covers working, what I would like to implement its the time based and “Stop” functions…

As you can see I already have the “Entity button” for my office cover (Persiana do Escritório).
What I don’t get (I understood your explanation) is where I should replace your “office_cover” for my “persiana_do_escritorio”… (dumb me)!!!

Here’s my config:

configuration.yaml

# Includes
group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
switch: !include switches.yaml
cover: !include cover.yaml

cover.yaml:

- platform: cover_rf_time_based
  devices:
      persiana_do_escritorio_time_based:
        name: Persiana do Escritório
        travelling_time_up: 20
        travelling_time_down: 20
        close_script_entity_id: script.persiana_do_escritorio_down
        stop_script_entity_id: script.persiana_do_escritorio_stop
        open_script_entity_id: script.persiana_do_escritorio_up

scripts.yaml

office_cover_up:
  sequence:
    - service: remote.send_command
      data:
        entity_id: remote.rm_pro_remote
        device: persiana_do_escritorio
        command: open
office_cover_down:
  sequence:
    - service: remote.send_command
      data:
        entity_id: remote.rm_pro_remote
        device: persiana_do_escritorio
        command: close
office_cover_stop:
  sequence:
    - service: remote.send_command
      data:
        entity_id: remote.rm_pro_remote
        device: persiana_do_escritorio
        command: stop

and broadlink_remote_XXXXXXXXX_codes

{
    "version": 1,
    "key": "broadlink_remote_XXXXXXXXX_codes",
    "data": {
        "persiana_do_escritorio": {
            "close": "sgB4AC8RMRIxETISMhIOMDESMhIPLw8vDy8PLzESDy8yEg8wDi8yEjMRDzAyEg8wDzAOMA4AAcoxETISMhIyEjMSEDAyEjMSDzAPMA8wDjAyEg8xMhIPMA8wMhIiIw8xMhMPMA8wDzAOAAHNMRIyEhQEBCwzEjMdDwAF3A=="
            "open": "sgB4AC8RMRIxETISMhIOMDESMhIPLw8vDy8PLzESDy8yEg8wDi8yEjMRDzAyEg8wDzAOMA4AAcoxETISMhIyEjMSEDAyEjMSDzAPMA8wDjAyEg8xMhIPMA8wMhIiIw8xMhMPMA8wDzAOAAHNMRIyEhQEBCwzEjMdDwAF3A=="
            "stop": "sgCKAA4uDi8OLjESDi8xEw4wDi8xEjISDzAPLzISDzAOMA4AAcoxEjETMhIyEzITDzAyEzMSDzEOMQ4wDzAyEw4xMhMOMQ8wMhMzEg8xDzAzEg8xDzAPAAHOMRMyEjITMxMzEw8xMxIwFg8xDzEOMQ8wMxIQMDMTDzAPMTMSNBIPMRAwMxIPMg8wDwAF3AAAAAAAAAAAAAAAAAAA"
        }
    }
}

For some reason nothing happens when I click the cover buttons.
The ones I have as switches are working just fine!

I’m using HA for about a month. I have a LOT to learn…

The good news is I think were nearly there! Try changing your scripts.yaml to this:

persiana_do_escritorio_up:
  sequence:
    - service: remote.send_command
      data:
        entity_id: remote.rm_pro_remote
        device: persiana_do_escritorio
        command: open
persiana_do_escritorio_down:
  sequence:
    - service: remote.send_command
      data:
        entity_id: remote.rm_pro_remote
        device: persiana_do_escritorio
        command: close
persiana_do_escritorio_stop:
  sequence:
    - service: remote.send_command
      data:
        entity_id: remote.rm_pro_remote
        device: persiana_do_escritorio
        command: stop
1 Like

Not yet… :frowning:



Logger: homeassistant.components.script.persiana_do_escritorio_down
Source: components/broadlink/remote.py:194
Integration: Script (documentation, issues)
First occurred: 14:23:19 (2 occurrences)
Last logged: 14:23:27
persiana_do_escritorio_down: Error executing script. Unexpected error for call_service at pos 1: Command not found: 'close'

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/broadlink/remote.py", line 192, in _extract_codes
    codes = self._codes[device][cmd]
KeyError: 'persiana_do_escritorio'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 363, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 563, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1481, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1516, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 213, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 658, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 726, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 695, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/broadlink/remote.py", line 275, in async_send_command
    code_list = self._extract_codes(commands, device)
  File "/usr/src/homeassistant/homeassistant/components/broadlink/remote.py", line 194, in _extract_codes
    raise ValueError(f"Command not found: {repr(cmd)}") from err
ValueError: Command not found: 'close'


Logger: homeassistant.components.broadlink.remote
Source: components/broadlink/remote.py:277
Integration: Broadlink (documentation, issues)
First occurred: 14:23:10 (5 occurrences)
Last logged: 14:23:27

Failed to call remote.send_command: Command not found: 'open'
Failed to call remote.send_command: Command not found: 'close'
Failed to call remote.send_command: Command not found: 'stop'

Damn! What am I missing?
Sorry to be waisting your time!|

Whre’s my saviour @Eoin ??

Can you paste in your full scripts.yaml file again?
The error is suggestion the script ‘persiana_do_escritorio_down’ does not have the command ‘close’ set.

Sure…


persiana_do_escritorio_up:
  sequence:
    - service: remote.send_command
      data:
        entity_id: remote.rm_pro_remote
        device: persiana_do_escritorio
        command: open
persiana_do_escritorio_down:
  sequence:
    - service: remote.send_command
      data:
        entity_id: remote.rm_pro_remote
        device: persiana_do_escritorio
        command: close
persiana_do_escritorio_stop:
  sequence:
    - service: remote.send_command
      data:
        entity_id: remote.rm_pro_remote
        device: persiana_do_escritorio
        command: stop

That code for the script looks perfect. I’m confused! :confused:
Anyone else have any suggestions?

Did I mention that “persiana_do_escritorio” it’s an entity and not a device on my HA?

This is what I get after pressing a button:

Logger: homeassistant
Source: components/broadlink/remote.py:194
First occurred: 20:59:36 (6 occurrences)
Last logged: 23:42:23

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/broadlink/remote.py", line 192, in _extract_codes
    codes = self._codes[device][cmd]
KeyError: 'persiana_do_escritorio'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 404, in _async_run
    return await self.script.async_run(variables, context)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1209, in async_run
    await asyncio.shield(run.async_run())
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 345, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 363, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 563, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1481, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1516, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 213, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 658, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 726, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 695, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/broadlink/remote.py", line 275, in async_send_command
    code_list = self._extract_codes(commands, device)
  File "/usr/src/homeassistant/homeassistant/components/broadlink/remote.py", line 194, in _extract_codes
    raise ValueError(f"Command not found: {repr(cmd)}") from err
ValueError: Command not found: 'open'

I see at the end…

ValueError: Command not found: 'open'

Does it help?..

Anyone? I’m stuck in here! :frowning:

Nice custom component, i ‘am using it with my somfy covers which i control met rfxtrx.

Is there a way to restore the State after a restart of home assistant?

Hi, thanks for your Great work! It was working great for me until i made latest Update.
I hade a Register called cover and all covers was inside. In total I have 4. Now all are gone and i can t add new card.
When i search the entitys i only can find 1 of 4 covers… only the first one can be found. Her is my Config:

# Rolladen Schalter
cover:
   - platform: cover_rf_time_based
     devices:
        my_room_cover_time_based:
           name: Laura Rolladen
           travelling_time_up: 20
           travelling_time_down: 19
           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
   - platform: cover_rf_time_based
     devices:
        my_room_cover_time_based:
           name: Lina Rolladen
           travelling_time_up: 20
           travelling_time_down: 19
           close_script_entity_id: script.lina_rolladen_runter
           stop_script_entity_id: script.lina_rolladen_stop
           open_script_entity_id: script.lina_rolladen_hoch
           aliases:
              - my_room_cover_time_based           
   - platform: cover_rf_time_based
     devices:
        my_room_cover_time_based:
           name: Wohnzimmer Links Rolladen
           travelling_time_up: 36
           travelling_time_down: 24
           close_script_entity_id: script.wohnzimmer_links_runter
           stop_script_entity_id: script.wohnzimmer_links_stop
           open_script_entity_id: script.wohnzimmer_links_hoch
           aliases:
              - my_room_cover_time_based           
   - platform: cover_rf_time_based
     devices:
        my_room_cover_time_based:
           name: Wohnzimmer Rechts Rolladen
           travelling_time_up: 34
           travelling_time_down: 24
           close_script_entity_id: script.wohnzimmer_rechts_runter
           stop_script_entity_id: script.wohnzimmer_rechts_stop
           open_script_entity_id: script.wohnzimmer_rechts_hoch
           aliases:
              - my_room_cover_time_based           

I’m still trying to find why it doesn’t work with my HA… :frowning:
Someone could please help me?

It should be:

# Rolladen Schalter
cover:
   - platform: cover_rf_time_based
     devices:
        my_room_cover_time_based_1:
           name: Laura Rolladen
           travelling_time_up: 20
           travelling_time_down: 19
           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

        my_room_cover_time_based_2:
           name: Lina Rolladen
           travelling_time_up: 20
           travelling_time_down: 19
           close_script_entity_id: script.lina_rolladen_runter
           stop_script_entity_id: script.lina_rolladen_stop
           open_script_entity_id: script.lina_rolladen_hoch

        my_room_cover_time_based_3:
           name: Wohnzimmer Links Rolladen
           travelling_time_up: 36
           travelling_time_down: 24
           close_script_entity_id: script.wohnzimmer_links_runter
           stop_script_entity_id: script.wohnzimmer_links_stop
           open_script_entity_id: script.wohnzimmer_links_hoch

        my_room_cover_time_based_4:
           name: Wohnzimmer Rechts Rolladen
           travelling_time_up: 34
           travelling_time_down: 24
           close_script_entity_id: script.wohnzimmer_rechts_runter
           stop_script_entity_id: script.wohnzimmer_rechts_stop
           open_script_entity_id: script.wohnzimmer_rechts_hoch

Thanks it is working again!!

Am I the only one that cannot make this run? :frowning: