YET another time controlled cover (RFLink)

I think so. Has it been working in my installation for the last years.
RFLink haven’t changed much so neither the custom component.

I will try to help you if you have any problem.

It was on my roadmap for a while but not sure when/why i forgot it.

That’s good news already. Thank you.

Does that mean you’re doing something here again?
(Otherwise I would wait for it).

I’m sorry to say that, but not in the short/middle time.

Hey Javicalle,

An integration with HACS would be great even if RTS_RFLINK works without this integration

@javicalle If I add a cover with your code, then I get the following error:

Logger: homeassistant.setup
Source: setup.py:213
First occurred: 09:02:59 (1 occurrences)
Last logged: 09:02:59

Setup failed for knx: Unable to import component: cannot import name 'XknxConnectionState' from 'xknx.core' (/usr/local/lib/python3.10/site-packages/xknx/core/__init__.py)

Probably the same topic like this?
https://github.com/nagyrobi/home-assistant-custom-components-cover-rf-time-based/issues/50

See also https://community.home-assistant.io/t/hass-somfy-rts-blinds-and-rflink/124156/12

@javicalle
I did the same changes which are described in the links above on my own (and also other like is_opening) and now it worked.
Probably you could update your files?

1 Like

Thanks for reporting.
I’ll take a look later.

1 Like

Hey,
I have no operating problem with an RFLINK installed on Arduino Mega and SOMFY RTS covers.

The problem comes if you have a RFLink integration and the Knx integration too.
My custom component fixed the xknx dependency version and that creates all the trouble. I have removed the pinned version from the requirements and added it like a dependency (without a version).

Checking now in my environment. :crossed_fingers:

Checked and working without issues.
I don’t have the Knx integration settled but with the current version there’s no reason to generate any errors.

Hi :wave:!

Please don’t do that. Copy that one travelcalculator.py module you need for your thing (maybe attach xknx’ licence on top) and ship it with your custom component. You really only need that 160 lines of its 16k lines of knx code (and neither do you need its dependency tree).

It will save some headache for you and the xknx developers.

Sincerely Matthias, maintainer of xknx

Hi @farmio,
I want to apologize for any problem that my ignorance may have caused you. Nothing further from my will.

I followed your advice and included the travelcalculator module inside my custom_component.
I’m not sure how ‘attach xknx’ license on top’ would be appropriate. I’ve created a travelcalculator.readme file, but feel free to tell me the best way to include your credit in my component.

Kind regards.

Don’t worry, I had no troubles with that. There has been a similar custom_component - and I was quite surprised to find the reason for the knx integration not working for users of it back then. I’m just trying to prevent this from happening again.

For the licence thing, I’m no expert, but I’d just copy it on top as module docstring.

"""
license
"""
from __future__ import annotations

from enum import Enum
import time

class TravelCalculator:

https://github.com/XKNX/xknx/blob/78d71a62cbb67f5903c5088065bd79734a093579/LICENSE

Yes, your code use has spread a bit :sweat_smile:

Done!

2 Likes

Hello and thank you for your great work!

I have a Somfy RTS electric awning at which i’m not able to program the my-Position. Dont know why but also i dont need it.
So if i press the my-Position Button, the Somfy RTS just stops and dont goes further.

Is it possible to disable the my-Position e.g. by yaml-configuration?
If i just delete the rts_my_position doesnt works.

Hi, not sure what do you mean.
If you don’t configure the rts_my_position the stop button in HA should behave just as stop button. Isn’t that in your instalation?

If you want to alter the behavior of the physical remote it is not possible.

If i delete rts_my_position in my config, the cover wont work anymore in Homeassistant.
Leaving empty like

rts_my_position: []

or

rts_my_position: 

doesn’t work also.

The problem is when i press on the physical remote the my-button while the cover is not moving, the rflink integration sets the state curent_position in HomeAssistant to the rts_my_position’ from the config, which is wrong

edit:
I reached my goals by editing the cover.py
From

    def _handle_my_button(self):
        """Handle the MY button press"""
        self._require_stop_cover = False
        if self.tc.is_traveling():
            _LOGGER.debug('_handle_my_button :: button stops cover')
            self.tc.stop()
            self.stop_auto_updater()
        elif self._rts_my_position is not None:
            _LOGGER.debug('_handle_my_button :: button sends to MY')
            self.tc.start_travel(self.shift_position(self._rts_my_position))
            self.start_auto_updater()

to

    def _handle_my_button(self):
        """Handle the MY button press"""
        self._require_stop_cover = False
        if self.tc.is_traveling():
            _LOGGER.debug('_handle_my_button :: button stops cover')
            self.tc.stop()
            self.stop_auto_updater()
        elif self._rts_my_position is not None:
            _LOGGER.debug('_handle_my_button :: button sends to MY')
            self.tc.stop()
            self.stop_auto_updater()

and comment out the my_position attribute

    @property
    def device_state_attributes(self):
        """Return the device state attributes."""
        attr = {}
        super_attr = super().device_state_attributes
        if super_attr is not None:
            attr.update(super_attr)
#        if self._rts_my_position is not None:
#            attr[CONF_MY_POSITION] = self._rts_my_position
        if self._travel_time_down is not None:
            attr[CONF_TRAVELLING_TIME_DOWN] = self._travel_time_down
        if self._travel_time_up is not None:
            attr[CONF_TRAVELLING_TIME_UP] = self._travel_time_up
        return attr

I would prefer to figure out why isn’t working if you don’t configure the rts_my_position attribute.

The attribute is optional:

The code that you proposed is the same that would execute if cover is_traveling

            _LOGGER.debug('_handle_my_button :: button stops cover')
            self.tc.stop()
            self.stop_auto_updater()

So let’s fix the issue and then see if something else must fixed.
Can you check if there are any errors in the HA start when you remove the attribute? Or when you press any button (with the attribute removed)?

Yes of course we can.
When i comment out rts_my_position the logs say:

Nr 1.:

Logger: homeassistant.components.cover
Source: custom_components/rts_rflink/cover.py:110
Integration: Abdeckung (documentation, issues)
First occurred: 22:54:01 (1 occurrences)
Last logged: 22:54:01
Error while setting up rts_rflink platform for cover

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 293, in _async_setup_platform
    await asyncio.shield(task)
  File "/config/custom_components/rts_rflink/cover.py", line 124, in async_setup_platform
    async_add_entities(devices_from_config(config))
  File "/config/custom_components/rts_rflink/cover.py", line 110, in devices_from_config
    rts_my_position = config.pop(CONF_MY_POSITION)
KeyError: 'rts_my_position'

Nr. 2:

2023-04-01 22:54:00.681 INFO (MainThread) [homeassistant.components.rflink] Initiating Rflink connection
2023-04-01 22:54:00.684 INFO (MainThread) [homeassistant.components.rflink] Connected to Rflink
2023-04-01 22:54:01.355 ERROR (MainThread) [homeassistant.components.cover] Error while setting up rts_rflink platform for cover
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 293, in _async_setup_platform
await asyncio.shield(task)
File "/config/custom_components/rts_rflink/cover.py", line 124, in async_setup_platform
async_add_entities(devices_from_config(config))
File "/config/custom_components/rts_rflink/cover.py", line 110, in devices_from_config
rts_my_position = config.pop(CONF_MY_POSITION)
KeyError: 'rts_my_position'

It seems that will need a few fixes, but could you try with that version (default None in the pop function)

def devices_from_config(domain_config):
    """Parse configuration and add RFLink cover devices."""
    devices = []
    for entity_id, config in domain_config[CONF_DEVICES].items():
        entity_type = config.pop(CONF_TYPE)
        entity_class = entity_class_for_type(entity_type)
        rts_my_position = config.pop(CONF_MY_POSITION, None)
        travel_time_down = config.pop(CONF_TRAVELLING_TIME_DOWN)
        travel_time_up = config.pop(CONF_TRAVELLING_TIME_UP)
        device_config = dict(domain_config[CONF_DEVICE_DEFAULTS], **config)
        device = entity_class(
            entity_id, rts_my_position, travel_time_down,
            travel_time_up, **device_config)
        devices.append(device)
    return devices