Skip to content

Commit

Permalink
Merge pull request #79 from grimmpp/feature-branch
Browse files Browse the repository at this point in the history
Feature branch
  • Loading branch information
grimmpp authored Mar 15, 2024
2 parents 01177e5 + 8cd766c commit 0a3dd55
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 29 deletions.
4 changes: 4 additions & 0 deletions changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
* Added additional values (battery voltage, illumination, temperature) for A5-08-01 as sensor
* Occupancy Sensor of A5-08-01 added as binary sensor
* Improved ESP3 adapter for USB300 support. Sending telegrams works now but actuators are not accepting commands for e.g. lights - EEP: A5-38-08
* Teach-In buttons for lights, covers, and climate are available.
* Static 'Event Id' of switches (EEP: F6-02-01 and F6-02-02) added.
* Docs about how to use logging added.
* Updated docs about how to trigger automations with wall-mounted switches.

## Version 1.3.7 Restore Device States after HA Restart
* Trial to remove import warnings
Expand Down
34 changes: 22 additions & 12 deletions custom_components/eltako/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
from . import get_gateway_from_hass, get_device_config_for_gateway

EEP_WITH_TEACH_IN_BUTTONS = {
A5_10_06: b'\x40\x30\x0D\x85'
A5_10_06: b'\x40\x30\x0D\x85', # climate
A5_38_08: b'\xE0\x40\x0D\x80', # light
H5_3F_7F: b'\xFF\xF8\x0D\x80', # cover
# F6_02_01 # What button to take?
# F6_02_02
}

async def async_setup_entry(
Expand Down Expand Up @@ -55,8 +59,8 @@ async def async_setup_entry(
dev_config = config_helpers.DeviceConf(entity_config)
sender_config = config_helpers.get_device_conf(entity_config, CONF_SENDER)

if dev_config.eep in EEP_WITH_TEACH_IN_BUTTONS.keys():
entities.append(TemperatureControllerTeachInButton(platform, gateway, dev_config.id, dev_config.name, dev_config.eep, sender_config.id))
if sender_config.eep in EEP_WITH_TEACH_IN_BUTTONS.keys():
entities.append(TeachInButton(platform, gateway, dev_config.id, dev_config.name, dev_config.eep, sender_config.id, sender_config.eep))
except Exception as e:
LOGGER.warning("[%s] Could not load configuration", platform)
LOGGER.critical(e, exc_info=True)
Expand All @@ -69,35 +73,41 @@ async def async_setup_entry(
async_add_entities(entities)


class AbstractButton(EltakoEntity, ButtonEntity):

class TemperatureControllerTeachInButton(EltakoEntity, ButtonEntity):
"""Button which sends teach-in telegram for temperature controller."""
def load_value_initially(self, latest_state:State):
pass

def __init__(self, platform: str, gateway: EnOceanGateway, dev_id: AddressExpression, dev_name: str, dev_eep: EEP, sender_id: AddressExpression):

class TeachInButton(AbstractButton):
"""Button which sends teach-in telegram."""

def __init__(self, platform: str, gateway: EnOceanGateway, dev_id: AddressExpression, dev_name: str, dev_eep: EEP, sender_id: AddressExpression, sender_eep: EEP):
_dev_name = dev_name
if _dev_name == "":
_dev_name = "temperature-controller-teach-in-button"
_dev_name = "teach-in-button"
self.entity_description = ButtonEntityDescription(
key="teach_in_button",
name="Send teach-in telegram from "+sender_id.plain_address().hex(),
icon="mdi:button-cursor",
icon="mdi:button-pointer",
device_class=ButtonDeviceClass.UPDATE,
)
self.sender_id = sender_id
self.sender_eep = sender_eep

super().__init__(platform, gateway, dev_id, _dev_name, dev_eep)

async def async_press(self) -> None:
"""
Handle the button press.
Send teach-in command for A5-10-06 e.g. FUTH
Send teach-in command
"""

controller_address, _ = self.sender_id
# msg = Regular4BSMessage(address=controller_address, data=b'\x40\x30\x0D\x85', outgoing=True, status=0x80)
msg = Regular4BSMessage(address=controller_address, data=EEP_WITH_TEACH_IN_BUTTONS[self.dev_eep], outgoing=True, status=0x80)
msg = Regular4BSMessage(address=controller_address, data=EEP_WITH_TEACH_IN_BUTTONS[self.sender_eep], outgoing=True, status=0x80)
self.send_message(msg)

class GatewayReconnectButton(EltakoEntity, ButtonEntity):
class GatewayReconnectButton(AbstractButton):
"""Button for reconnecting serial bus"""

def __init__(self, platform: str, gateway: EnOceanGateway):
Expand Down
2 changes: 1 addition & 1 deletion custom_components/eltako/eltako_integration_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
if gateway_device_type is None:
LOGGER.error(f"[{LOG_PREFIX}] USB device {gateway_config[CONF_DEVICE_TYPE]} is not supported!!!")
return False
general_settings[CONF_ENABLE_TEACH_IN_BUTTONS] = GatewayDeviceType.is_transceiver(gateway_device_type)
general_settings[CONF_ENABLE_TEACH_IN_BUTTONS] = True # GatewayDeviceType.is_transceiver(gateway_device_type) # should only be disabled for decentral gateways

LOGGER.info(f"[{LOG_PREFIX}] Initializes Gateway Device '{gateway_description}'")
gateway_name = gateway_config.get(CONF_NAME, None) # from configuration
Expand Down
2 changes: 2 additions & 0 deletions custom_components/eltako/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,8 @@ def convert_event(event):

event_id = config_helpers.get_bus_event_type(gateway.dev_id, EVENT_BUTTON_PRESSED, dev_conf.id)
entities.append(EventListenerInfoField(platform, gateway, dev_conf.id, dev_conf.name, dev_conf.eep, event_id, "Pushed Buttons", convert_event, "mdi:gesture-tap-button"))

entities.append(StaticInfoField(platform, gateway, dev_conf.id, dev_conf.name, dev_conf.eep, "Event Id", event_id, "mdi:form-textbox"))

except Exception as e:
LOGGER.warning("[%s] Could not load configuration", Platform.BINARY_SENSOR)
Expand Down
32 changes: 32 additions & 0 deletions docs/logging/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Logging

This part is about how to get access to the logs of Home Assistant Eltako Integration to e.g. check
* what telegrams have been received
* what events have been sent
* if there have been any problems occurred
* to under how the automation behaves and see what have been done.

<img src="screenshot_logging.png" alt="Exemplary screenshot about logging." height="300" />

## Log level
By default log level `INFO` is activated which means only important information like be displayed in the logs. This comprises e.g. error and superficial information.
If you want to get more detailed information you need to change the log level which can be done inside the Home assistant Configuration file `/config/configuration.yaml`.


## Change log level to get detailed information
To chang the configuration I can recommend to install and use the addon [File Editor](https://github.com/home-assistant/addons/tree/master/configurator). With File Editor you can read and edit any file in Home Assistant via your browser.

Extend or change the following part of the confguration file:
```
logger:
default: info # default log level of all components of Home Assistant
logs:
eltako: debug # enables detailed information for Home Assistant Eltako Integration
eltakobus.serial: info # enables detailed information of the communication library for enocean devices based on ESP2 protocol
enocean.communicators.SerialCommunicator: info # enables detailed information of the communication library for enocean devices based on ESP2 protocol
```

## Read logs
To get the logs nicely displayed I can recommend to install and use the addon [log-viewer](https://github.com/hassio-addons/addon-log-viewer).

Logs can also be found in `/config/home-assistant.log` and displayed by using [File Editor](https://github.com/home-assistant/addons/tree/master/configurator).
Binary file added docs/logging/screenshot_logging.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/rocker_switch/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 19 additions & 16 deletions docs/rocker_switch/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,10 @@ This example is about how to trigger complex automations in home assistant by wa
<img src="./rocker_switch_automation_config.png" height="300px">
<img src="./Eltako-F4T55E-wg.jpg" alt="Home Assistant Automation" height="100"/>

First of all you need to register your switch in the Home assistant Configuration ``/config/configuration.yaml``. Those switches are declared as binary sensors and their eep is "F6-02-01". You can find the identifiers of your switches on a sticker at the back.
## Register switch and check incomging telegrams and events in logs

<div style="border: 2px dotted darkgrey; padding: 12px; margin-top:20px; margin-bottom: 20px; ">
📝 <b>Note:</b> <br />
You can <b>enable debug logs</b> to easily test which switch was pressed. Therefore I've installed the addon <a href="https://github.com/hassio-addons/addon-log-viewer">log-viewer</a> and extended the home assistant config with:
<code><pre>
logger:
default: info
logs:
eltako: debug
</pre></code>
<b>To modify the Home Assistant configuration</b> I use <a href="https://github.com/home-assistant/addons/tree/master/configurator">File Editor</a>. After doing changes don't forget to restart Home Assistant what you can easily do in the menu of File Editor.

</div>
First of all you need to register your switch in the Home assistant Configuration ``/config/configuration.yaml``. Those switches are declared as `binary_sensor` and their EEP is `F6-02-01`. For more details about how to define the Home Assistant Eltako Integration configuration check out the [documentation how to write the configuration](../update_home_assistant_configuration.md) or if you are interested in auto-generating your configuration check out [enocean-device-manager](https://github.com/grimmpp/enocean-device-manager).
The the declaration in the configuration you need to know the id or enocean address of your switch. You can find the address of your switches on a sticker at the back or you can just push a button and check the incoming telegrams in the logs. ([Here](../logging/readme.md) you can find how to use logging. debugging must be enabled for eltako to see the incoming telegram: `etlako: debug`)

See example snipped to declare your switch:
```
Expand All @@ -29,12 +19,25 @@ See example snipped to declare your switch:
eep: "F6-02-01"
```

After you have registered the switch in Home Assistant configuration and after you have restarted Home Assistant you can see messages in the logger view.
After you have registered the switch in Home Assistant configuration and after you have restarted Home Assistant you can see messages in the logger view. (Debugging must be enabled.)

<img src="screenshot_logging.png" alt="Exemplary screenshot about logging." height="300" />

To create an automation go in Home Assistant to ``Settings > Automation & Scenes > Create Automation``.
## Create automatin listening on switch events

To create an automation which reacts on switch events go in Home Assistant to ``Settings > Automation & Scenes > Create Automation``.
As trigger choose ``Manual Event`` and enter ``eltako.gw_[GATEWAY_BASE_ID].func_button_pressed.sid_[SWITCH_ID].d_[BUTTONS]`` as event id. Replace brackets `[GATEWAY_BASE_ID]` by the base_id of your gateway, `[SWITCH_ID]` by the switch id, and `[BUTTONS]` by the button positions. Gateway base id and switch id can be found in your configuration. Ids must be entered in the following format and in upper letters: `FF-AA-80-00`. Valid values for button positions are LT, LB, RT, RB (L = left, r = richt, T = top, B = bottom). Combinations are also possible. It always starts with left and then right. Valid values are: `LT-RT`, `LT-RB`, `LB-RT`, `LB-RB`.

Choose your action you would like to trigger in the action section. In the following examples I change the state of light (toggle mode).
You can find the button independent event id of the switch on the entity page as well. You can copy this event id and if you want to distinguish between different buttons pushed you need to add `.d_[BUTTONS]` like described above.

<img src="screenshot_switch_page.png" alt="" height="300" />

If you push two buttons at the same time it looks like the following:

<img src="screenshot_switch_page_2buttons_pushed.png" alt="" height="300" />


Choose your action you would like to trigger in the action section. In the screenshot at the beginning I change the state of light (toggle mode).


## Advanced usage
Expand Down
Binary file added docs/rocker_switch/screenshot_logging.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/rocker_switch/screenshot_switch_page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0a3dd55

Please sign in to comment.