Skip to content
This repository has been archived by the owner on Mar 9, 2023. It is now read-only.

Commit

Permalink
Availability template added
Browse files Browse the repository at this point in the history
  • Loading branch information
nagyrobi committed Jul 20, 2022
1 parent 5d9b7af commit 512a23d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ cover:
send_stop_at_ends: False #optional
always_confident: False #optional
device_class: garage #optional
availability_template: "{{ is_state('binary_sensor.rfbridge_status', 'on') }}" #optional
```
**OR**:
Expand All @@ -65,6 +66,7 @@ Optional settings:
- `send_stop_at_ends` defaults to `False`. If set to `True`, the Stop script will be run after the cover reaches to 0 or 100 (closes or opens completely). This is for people who use interlocked relays in the scripts to drive the covers, which need to be released when the covers reach the end positions.
- `always_confident` defaults to `False`. If set to `True`, the calculated state will always be assumed to be accurate. This mainly affects UI components - for example, if the cover is fully opened, the open button will be disabled. Make sure to [set](#cover_rf_time_basedset_known_position) the current state after first setup and only use this entity to control the covers. Not recommended to be `True` for RF-based covers.
- `device_class` defaults to `shutter` if not specified. See the docs for availale [cover device classes](http://dev-docs.home-assistant.io/en/master/api/components.html#homeassistant.components.cover.CoverDeviceClass).
- `availability_template` if not specified will make the cover always available. You can use a template returning `True` or `False` in order to toggle availability of the cover based on other elements. Useful to link with the connection status of your RF Bridge or relays device.

### Example scripts.yaml entry
#### RF covers
Expand Down
43 changes: 40 additions & 3 deletions custom_components/cover_rf_time_based/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
SERVICE_CLOSE_COVER,
SERVICE_OPEN_COVER,
SERVICE_STOP_COVER,
STATE_UNAVAILABLE,
)

import homeassistant.helpers.config_validation as cv
Expand All @@ -45,6 +46,7 @@
CONF_CLOSE_SCRIPT_ENTITY_ID = 'close_script_entity_id'
CONF_STOP_SCRIPT_ENTITY_ID = 'stop_script_entity_id'
CONF_COVER_ENTITY_ID = 'cover_entity_id'
CONF_AVAILABILITY_TPL = 'availability_template'
ATTR_CONFIDENT = 'confident'
ATTR_ACTION = 'action'
ATTR_POSITION_TYPE = 'position_type'
Expand All @@ -63,6 +65,7 @@
vol.Optional(CONF_SEND_STOP_AT_ENDS, default=DEFAULT_SEND_STOP_AT_ENDS): cv.boolean,
vol.Optional(CONF_ALWAYS_CONFIDENT, default=DEFAULT_ALWAYS_CONFIDENT): cv.boolean,
vol.Optional(CONF_DEVICE_CLASS, default=DEFAULT_DEVICE_CLASS): DEVICE_CLASSES_SCHEMA,
vol.Optional(CONF_AVAILABILITY_TPL): cv.template,
}
)

Expand Down Expand Up @@ -125,7 +128,19 @@ def devices_from_config(domain_config):
send_stop_at_ends = config.pop(CONF_SEND_STOP_AT_ENDS)
always_confident = config.pop(CONF_ALWAYS_CONFIDENT)
device_class = config.pop(CONF_DEVICE_CLASS)
device = CoverTimeBased(device_id, name, travel_time_down, travel_time_up, open_script_entity_id, close_script_entity_id, stop_script_entity_id, cover_entity_id, send_stop_at_ends, always_confident, device_class)
availability_template = config.pop(CONF_AVAILABILITY_TPL, None)
device = CoverTimeBased(device_id,
name,
travel_time_down,
travel_time_up,
open_script_entity_id,
close_script_entity_id,
stop_script_entity_id,
cover_entity_id,
send_stop_at_ends,
always_confident,
device_class,
availability_template)
devices.append(device)
return devices

Expand All @@ -146,7 +161,19 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=


class CoverTimeBased(CoverEntity, RestoreEntity):
def __init__(self, device_id, name, travel_time_down, travel_time_up, open_script_entity_id, close_script_entity_id, stop_script_entity_id, cover_entity_id, send_stop_at_ends, always_confident, device_class):
def __init__(self,
device_id,
name,
travel_time_down,
travel_time_up,
open_script_entity_id,
close_script_entity_id,
stop_script_entity_id,
cover_entity_id,
send_stop_at_ends,
always_confident,
device_class,
availability_template):
"""Initialize the cover."""
from xknx.devices import TravelCalculator
self._travel_time_down = travel_time_down
Expand All @@ -162,6 +189,7 @@ def __init__(self, device_id, name, travel_time_down, travel_time_up, open_scrip
self._target_position = 0
self._processing_known_position = False
self._unique_id = device_id
self._availability_template = availability_template

if name:
self._name = name
Expand Down Expand Up @@ -195,9 +223,18 @@ def _handle_stop(self):

@property
def unconfirmed_state(self):
"""Return the assume state as a string to persist through restarts ."""
"""Return the assume state as a string to persist through restarts."""
return str(self._assume_uncertain_position)

@property
def available(self):
"""Return availability based on external template. Always available if no template specified."""
if self._availability_template is None:
return True
else:
self._availability_template.hass = self.hass
return self._availability_template.async_render()

@property
def name(self):
"""Return the name of the cover."""
Expand Down
2 changes: 1 addition & 1 deletion custom_components/cover_rf_time_based/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"domain": "cover_rf_time_based",
"name": "Cover Time Based RF (trigger script)",
"version": "1.0.8",
"version": "1.1.2",
"documentation": "https://github.com/nagyrobi/home-assistant-custom-components-cover-rf-time-based",
"iot_class": "assumed_state",
"requirements": [
Expand Down
2 changes: 1 addition & 1 deletion info.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ With this component you can add a time-based cover. You have to set triggering s
- State can be updated based on independent, external sensors (for example a contact or reed sensor at closed or opened state)
- State can mimic the operation based on external sensors (for example by monitoring the air for closing or opening RF codes) so usage in parrallel with controllers outside HA is possible
- Ability to take care care of queuing the transmission of the codes and keeping an appropriate delay between them to minimize 'missed' commands
- Can be used on top of any existing cover integration, or directly with Tasmota or ESPHome firmwares running on various ESP-based modules.
- Can be used on top of any existing cover integration, or directly with ESPHome or Tasmota firmwares running on various ESP-based modules.

## Component authors & contributors
"@davidramosweb",
Expand Down

0 comments on commit 512a23d

Please sign in to comment.