Skip to content

Commit

Permalink
fix(device): Convert entity registry id into entity id to fix device …
Browse files Browse the repository at this point in the history
…action
  • Loading branch information
zachowj committed Aug 16, 2024
1 parent 1bb18b2 commit 78e854a
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 34 deletions.
86 changes: 52 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,29 @@

[![BuyMeCoffee][buymecoffeebadge]][buymecoffee]

_Companion Component to [node-red-contrib-home-assistant-websocket](https://github.com/zachowj/node-red-contrib-home-assistant-websocket) to integrate Node-RED with Home Assistant._

## Features

- Create and update entities from Node-RED
- binary sensor
- button
- number
- select
- sensor
- switch
- text
- Disable and enable Node-RED flows from Home Assistant UI
- Create Home Assistant webhooks and handle them in Node-RED
- Use Device triggers and action from Node-RED
_Companion Component to [node-red-contrib-home-assistant-websocket](https://github.com/zachowj/node-red-contrib-home-assistant-websocket) for seamless integration of Node-RED with Home Assistant._

## Overview

The Node-RED Companion Integration bridges Node-RED and Home Assistant, allowing you to manage Home Assistant entities and automations directly from Node-RED. This integration enhances your smart home automation setup by enabling dynamic interaction between these two powerful tools.

## Key Features

- **Entity Management:**
- Create and update Home Assistant entities from Node-RED, including:
- Binary Sensors
- Buttons
- Numbers
- Selects
- Sensors
- Switches
- Text fields
- **Flow Control:**
- Enable or disable Node-RED flows directly from the Home Assistant UI.
- **Webhooks:**
- Create and manage Home Assistant webhooks, with handling in Node-RED.
- **Device Automation:**
- Utilize device triggers and actions within Node-RED for advanced automation capabilities.

## Minimum Requirements

Expand All @@ -27,34 +35,44 @@ _Companion Component to [node-red-contrib-home-assistant-websocket](https://gith

## Installation

### HACS
### Option 1: HACS (Home Assistant Community Store)

Install via [HACS](https://hacs.xyz) (Home Assistant Community Store)
To install via HACS:

1. Go to HACS -> Integrations -> "+ Explore & Download Repos"
1. Find "Node-RED Companion".
1. Open the search result and click "Download this Repository with HACS".
1. Refresh your browser window (bug in HA where it doesn't update the integration list after a reboot)
1. From "Settings" in the Home Assistant sidebar, select "Devices and Services", click the blue [+ Add integration] button (in bottom right of the page) and search for "Node-RED", and install it. [![Open your Home Assistant instance and start setting up a new integration.](https://my.home-assistant.io/badges/config_flow_start.svg)](https://my.home-assistant.io/redirect/config_flow_start/?domain=nodered)
1. Navigate to HACS -> Integrations -> "+ Explore & Download Repos".
2. Search for "Node-RED Companion".
3. Click on the result and select "Download this Repository with HACS".
4. Refresh your browser (due to a known HA bug that may not update the integration list immediately).
5. Go to "Settings" in the Home Assistant sidebar, then select "Devices and Services".
6. Click the blue [+ Add Integration] button at the bottom right, search for "Node-RED", and install it.
[![Set up a new integration in Home Assistant](https://my.home-assistant.io/badges/config_flow_start.svg)](https://my.home-assistant.io/redirect/config_flow_start/?domain=nodered)

### Manual
### Option 2: Manual Installation

1. Using your tool of choice open the directory (folder) for your HA configuration (where you find `configuration.yaml`).
1. If you do not have a `custom_components` directory (folder) there, you need to create it.
1. In the `custom_components` directory (folder) create a new folder called `nodered`.
1. Download _all_ the files from the `custom_components/nodered/` directory (folder) in this repository.
1. Place the files you downloaded in the new directory (folder) you created.
1. Restart Home Assistant
1. Refresh your browser window (bug in HA where it doesn't update the integration list after a reboot)
1. From "Settings" in the Home Assistant sidebar, select "Devices and Services", click the blue [+ Add integration] button (in bottom right of the page) and search for "Node-RED", and install it. [![Open your Home Assistant instance and start setting up a new integration.](https://my.home-assistant.io/badges/config_flow_start.svg)](https://my.home-assistant.io/redirect/config_flow_start/?domain=nodered)
For manual installation:

1. Access your Home Assistant configuration directory (`configuration.yaml` location).
2. If it doesn’t already exist, create a `custom_components` directory.
3. Within `custom_components`, create a new folder named `nodered`.
4. Download all files from the `custom_components/nodered/` directory in this repository.
5. Place these files in the newly created `nodered` directory.
6. Restart Home Assistant.
7. Refresh your browser window.
8. From "Settings" in the Home Assistant sidebar, select "Devices and Services", click the blue [+ Add Integration] button, search for "Node-RED", and install it.
[![Set up a new integration in Home Assistant](https://my.home-assistant.io/badges/config_flow_start.svg)](https://my.home-assistant.io/redirect/config_flow_start/?domain=nodered)

## Configuration

Once installed and added via Home-Assistant Integrations all configuration is done from within Node-RED.
Once the Node-RED Companion Integration is installed and added via Home Assistant Integrations, all further configuration is managed from within Node-RED.

## Contributing

Contributions are welcome! If you're interested in contributing, please review our [Contribution Guidelines](CONTRIBUTING.md) before submitting a pull request or issue.

## Contributions are welcome!
## Support

If you want to contribute please read the [Contribution guidelines](CONTRIBUTING.md)
If you find this project helpful and want to support its development, consider buying me a coffee!
[![Buy Me a Coffee][buymecoffeebadge]][buymecoffee]

---

Expand Down
6 changes: 6 additions & 0 deletions custom_components/nodered/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,18 @@ async def websocket_device_action(
hass: HomeAssistant, connection: ActiveConnection, msg: dict[str, Any]
) -> None:
"""Sensor command."""

context = connection.context(msg)
platform = await device_automation.async_get_device_automation_platform(
hass, msg["action"][CONF_DOMAIN], DeviceAutomationType.ACTION
)

try:
if "entity_id" in msg["action"]:
entity_registry = async_get(hass)
entity_id = entity_registry.async_get(msg["action"]["entity_id"]).entity_id
msg["action"]["entity_id"] = entity_id

await platform.async_call_action_from_config(hass, msg["action"], {}, context)
connection.send_message(result_message(msg[CONF_ID]))
except InvalidDeviceAutomationConfig as err:
Expand Down

0 comments on commit 78e854a

Please sign in to comment.