Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ZHA zigbee IR remotes as controller #15

Merged
merged 1 commit into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions custom_components/smartir/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
MQTT_CONTROLLER = "MQTT"
LOOKIN_CONTROLLER = "LOOKin"
ESPHOME_CONTROLLER = "ESPHome"
ZHA_CONTROLLER = "ZHA"

ENC_BASE64 = "Base64"
ENC_HEX = "Hex"
Expand All @@ -23,6 +24,7 @@
MQTT_COMMANDS_ENCODING = [ENC_RAW]
LOOKIN_COMMANDS_ENCODING = [ENC_PRONTO, ENC_RAW]
ESPHOME_COMMANDS_ENCODING = [ENC_RAW]
ZHA_COMMANDS_ENCODING = [ENC_RAW]


def get_controller(hass, controller, encoding, controller_data, delay):
Expand All @@ -33,6 +35,7 @@ def get_controller(hass, controller, encoding, controller_data, delay):
MQTT_CONTROLLER: MQTTController,
LOOKIN_CONTROLLER: LookinController,
ESPHOME_CONTROLLER: ESPHomeController,
ZHA_CONTROLLER: ZHAController,
}
try:
return controllers[controller](
Expand Down Expand Up @@ -182,6 +185,34 @@ async def send(self, command):
)


class ZHAController(AbstractController):
"""Controls a ZHA device."""

def check_encoding(self, encoding):
"""Check if the encoding is supported by the controller."""
if encoding not in ZHA_COMMANDS_ENCODING:
raise Exception(
"The encoding is not supported " "by the ESPHome controller."

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must be ZHA not ESPhome

)

async def send(self, command):
"""Send a command."""
service_data = json.loads(self._controller_data)
if not isinstance(service_data, dict):
raise Exception("Wrong json config for ZHA controller")
for key in ["ieee", "endpoint_id", "cluster_id", "cluster_type", "command"]:
if not service_data.get(key):
raise Exception(
"Missing '%s' parameter in config for ZHA controller", key
)
service_data["params"] = {
"code": command,
}
await self.hass.services.async_call(
"zha", "issue_zigbee_cluster_command", service_data
)


class Helper:
"""Static shared functions."""

Expand Down
22 changes: 21 additions & 1 deletion docs/CLIMATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Find your device's brand code [here](CLIMATE.md#available-codes-for-climate-devi
| `name` | string | optional | The name of the device |
| `unique_id` | string | optional | An ID that uniquely identifies this device. If two devices have the same unique ID, Home Assistant will raise an exception. |
| `device_code` | number | required | (Accepts only positive numbers) |
| `controller_data` | string | required | The data required for the controller to function. Enter the entity_id of the Broadlink remote **(must be an already configured device)**, or the entity id of the Xiaomi IR controller, or the MQTT topic on which to send commands. |
| `controller_data` | string | required | The data required for the controller to function. Enter the entity_id of the Broadlink remote **(must be an already configured device)**, or the entity id of the Xiaomi IR controller, or the MQTT topic on which to send commands, or the ZHA zigbee cluster to send commands to. |
| `delay` | number | optional | Adjusts the delay in seconds between multiple commands. The default is 0.5 |
| `temperature_sensor` | string | optional | *entity_id* for a temperature sensor |
| `humidity_sensor` | string | optional | *entity_id* for a humidity sensor |
Expand Down Expand Up @@ -76,6 +76,26 @@ climate:
power_sensor: binary_sensor.ac_power
```

## Example (using ZHA controller and a TuYa ZS06):
```yaml
climate:
- platform: smartir
name: Office AC
unique_id: office_ac
device_code: 9000
controller_data: '{
"ieee":"XX:XX:XX:XX:XX:XX:XX:XX",
"endpoint_id": 1,
"cluster_id": 57348,
"cluster_type": "in",
"command": 2,
"command_type": "server"
}'
temperature_sensor: sensor.temperature
humidity_sensor: sensor.humidity
power_sensor: binary_sensor.ac_power
```

## Example (using ESPHome):
ESPHome configuration example:
```yaml
Expand Down
21 changes: 20 additions & 1 deletion docs/FAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Find your device's brand code [here](FAN.md#available-codes-for-fan-devices) and
| `name` | string | optional | The name of the device |
| `unique_id` | string | optional | An ID that uniquely identifies this device. If two devices have the same unique ID, Home Assistant will raise an exception. |
| `device_code` | number | required | (Accepts only positive numbers) |
| `controller_data` | string | required | The data required for the controller to function. Enter the entity_id of the Broadlink remote **(must be an already configured device)**, or the entity id of the Xiaomi IR controller, or the MQTT topic on which to send commands. |
| `controller_data` | string | required | The data required for the controller to function. Enter the entity_id of the Broadlink remote **(must be an already configured device)**, or the entity id of the Xiaomi IR controller, or the MQTT topic on which to send commands, or the ZHA zigbee cluster to send commands to. |
| `delay` | number | optional | Adjusts the delay in seconds between multiple commands. The default is 0.5 |
| `power_sensor` | string | optional | *entity_id* for a sensor that monitors whether your device is actually `on` or `off`. This may be a power monitor sensor. (Accepts only on/off states) |
| `power_sensor_restore_state` | boolean | optional | If `power_sensor` is set, and the device is likely to decrease power consumption bellow `power_sensors` threshold (for instance, a fan with speed in auto fluctuating mode), setting this to `true` will cause the entity fan state to update dynamically between OFF and last known ON speed, following the state of the `power_sensor`. |
Expand Down Expand Up @@ -104,6 +104,25 @@ fan:
power_sensor: binary_sensor.fan_power
```

## Example (using ZHA controller and a TuYa ZS06):

```yaml
fan:
- platform: smartir
name: Bedroom fan
unique_id: bedroom_fan
device_code: 5000
controller_data: '{
"ieee":"XX:XX:XX:XX:XX:XX:XX:XX",
"endpoint_id": 1,
"cluster_id": 57348,
"cluster_type": "in",
"command": 2,
"command_type": "server"
}'
power_sensor: binary_sensor.fan_power
```

## Available codes for Fan devices

The following are the code files created by the amazing people in the community. Before you start creating your own code file, try if one of them works for your device. **Please open an issue if your device is working and not included in the supported models.**
Expand Down
36 changes: 27 additions & 9 deletions docs/MEDIA_PLAYER.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ For this platform to work, we need a .json file containing all the necessary IR
Find your device's brand code [here](MEDIA_PLAYER.md#available-codes-for-tv-devices) and add the number in the `device_code` field. If your device is not working, you will need to learn your own codes and place the .json file in `smartir/custom_codes/media_player/` subfolders. Please note that the `device_code` field only accepts positive numbers. The .json extension is not required.

## Configuration variables:
| Name | Type | Default | Description |
| ----------------- | :----: | :------: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `name` | string | optional | The name of the device |
| `unique_id` | string | optional | An ID that uniquely identifies this device. If two devices have the same unique ID, Home Assistant will raise an exception. |
| `device_code` | number | required | (Accepts only positive numbers) |
| `controller_data` | string | required | The data required for the controller to function. Enter the entity_id of the Broadlink remote **(must be an already configured device)**, or the entity id of the Xiaomi IR controller, or the MQTT topic on which to send commands. |
| `delay` | number | optional | Adjusts the delay in seconds between multiple commands. The default is 0.5 |
| `power_sensor` | string | optional | *entity_id* for a sensor that monitors whether your device is actually `on` or `off`. This may be a power monitor sensor. (Accepts only on/off states) |
| `source_names` | dict | optional | Override the names of sources as displayed in HomeAssistant (see below) |
| Name | Type | Default | Description |
| ----------------- | :----: | :------: | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `name` | string | optional | The name of the device |
| `unique_id` | string | optional | An ID that uniquely identifies this device. If two devices have the same unique ID, Home Assistant will raise an exception. |
| `device_code` | number | required | (Accepts only positive numbers) |
| `controller_data` | string | required | The data required for the controller to function. Enter the entity_id of the Broadlink remote **(must be an already configured device)**, or the entity id of the Xiaomi IR controller, or the MQTT topic on which to send commands, or the ZHA zigbee cluster to send commands to. |
| `delay` | number | optional | Adjusts the delay in seconds between multiple commands. The default is 0.5 |
| `power_sensor` | string | optional | *entity_id* for a sensor that monitors whether your device is actually `on` or `off`. This may be a power monitor sensor. (Accepts only on/off states) |
| `source_names` | dict | optional | Override the names of sources as displayed in HomeAssistant (see below) |

## Example (using broadlink controller):
Add a Broadlink RM device named "Bedroom" via config flow (read the [docs](https://www.home-assistant.io/integrations/broadlink/)).
Expand Down Expand Up @@ -97,6 +97,24 @@ media_player:
power_sensor: binary_sensor.tv_power
```

## Example (using ZHA controller and a TuYa ZS06):
```yaml
media_player:
- platform: smartir
name: Living room TV
unique_id: living_room_tv
device_code: 5000
controller_data: '{
"ieee":"XX:XX:XX:XX:XX:XX:XX:XX",
"endpoint_id": 1,
"cluster_id": 57348,
"cluster_type": "in",
"command": 2,
"command_type": "server"
}'
power_sensor: binary_sensor.tv_power
```

### Overriding Source Names
Source names in device files are usually set to the name that the media player uses. These often aren't very descriptive, so you can override these names in the configuration file. You can also remove a source by setting its name to `null`.

Expand Down
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ SmartIR currently supports the following controllers:
* [LOOK.in Remote](http://look-in.club/devices/remote)
* [ESPHome User-defined service for remote transmitter](https://esphome.io/components/api.html#user-defined-services)
* [MQTT Publish service](https://www.home-assistant.io/docs/mqtt/service/)
* [ZHA Zigbee IR remote](https://www.home-assistant.io/integrations/zha/) (May require custom zha quirk for given controller)

More than 120 climate devices are currently supported out-of-the-box, mainly for the Broadlink controller, thanks to our awesome community.

Expand Down
1 change: 1 addition & 0 deletions info.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ SmartIR currently supports the following controllers:
* [LOOK.in Remote](http://look-in.club/devices/remote)
* [ESPHome User-defined service for remote transmitter](https://esphome.io/components/api.html#user-defined-services)
* [MQTT Publish service](https://www.home-assistant.io/docs/mqtt/service/)
* [ZHA Zigbee IR remote](https://www.home-assistant.io/integrations/zha/) (May require custom zha quirk for given controller)

More than 120 climate devices are currently supported out-of-the-box, mainly for the Broadlink controller, thanks to our awesome community.<br>
Please don't forget to [**star**](https://github.com/smartHomeHub/SmartIR/) the repository if you had fun! [**"Buy Me A Coffee**"](https://www.buymeacoffee.com/vassilis) is also welcome. It will help in further development.<br>
Expand Down
Loading