9 Commits
0.1.0 ... 0.1.2

6 changed files with 130 additions and 39 deletions

View File

@@ -31,3 +31,32 @@ action: whatsapp_bridge_integration.send_message
data: data:
number: "491701234567" number: "491701234567"
message: "The washing machine is finished! 🧺" message: "The washing machine is finished! 🧺"
```
### Use in Node-RED
Add a Call Service (or Action) node.
Domain: whatsapp_bridge_integration
Service: send_message
Data:
```JSON
{
"number": "491701234567",
"message": "{{payload}}"
}
```
## 👥 Multi-Account Support (Coming Soon)
We are currently working on a UI-based configuration flow so you can save "Account Aliases" (like "Dad", "Work", "Security") and select them from a dropdown menu without typing the phone number every time.
##⚠️ Important Notes
Phone Numbers: Always use the international format without + or 00 (e.g., 49... for Germany).
Local Network: The integration communicates locally with the Add-on on port 3000.
Developed by Bahmcloud
---

View File

@@ -1,47 +1,50 @@
import logging import logging
import requests import requests
import voluptuous as vol from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.helpers import config_validation as cv from .const import DOMAIN, CONF_PHONE_NUMBER, CONF_ACCOUNT_NAME
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
DOMAIN = "whatsapp_bridge_custom" async def async_setup_entry(hass: HomeAssistant, entry):
"""Set up a profile from a config entry."""
# Definition der Service-Parameter if not hass.services.has_service(DOMAIN, "send_message"):
SERVICE_SEND_MESSAGE = "send_message"
ATTR_NUMBER = "number"
ATTR_MESSAGE = "message"
SERVICE_SCHEMA = vol.Schema({ async def handle_send_message(call: ServiceCall):
vol.Required(ATTR_NUMBER): cv.string, message = call.data.get("message")
vol.Required(ATTR_MESSAGE): cv.string, target_account = call.data.get("account")
}) target_number = call.data.get("number")
all_accounts = call.data.get("all_accounts", False)
async def async_setup(hass, config): entries = hass.config_entries.async_entries(DOMAIN)
"""Set up the WhatsApp Bridge integration.""" targets = []
def send_whatsapp_msg(call): if all_accounts:
"""Dienst-Funktion: Nachricht an das Add-on senden.""" for e in entries:
number = call.data.get(ATTR_NUMBER) targets.append(e.data.get(CONF_PHONE_NUMBER))
message = call.data.get(ATTR_MESSAGE) elif target_number:
targets.append(target_number)
elif target_account:
for e in entries:
if e.title.lower() == target_account.lower():
targets.append(e.data.get(CONF_PHONE_NUMBER))
# Die interne URL zum Add-on (standardmäßig local-whatsapp-bridge) for num in targets:
# Port 3000 haben wir im Dockerfile definiert url = "http://866fd2eb-whatsapp-bridge:3000/send"
url = "http://866fd2eb-whatsapp-bridge:3000/send" try:
await hass.async_add_executor_job(
lambda: requests.post(url, json={
"number": num,
"message": message
}, timeout=10)
)
_LOGGER.info("WhatsApp sent to %s", num)
except Exception as e:
_LOGGER.error("Failed to send to %s: %s", num, str(e))
try: hass.services.async_register(DOMAIN, "send_message", handle_send_message)
response = requests.post(url, json={
"number": number,
"message": message
}, timeout=10)
if response.status_code != 200:
_LOGGER.error("Fehler beim Senden: %s", response.text)
except Exception as e:
_LOGGER.error("Verbindung zum Add-on fehlgeschlagen: %s", str(e))
hass.services.async_register(
DOMAIN, SERVICE_SEND_MESSAGE, send_whatsapp_msg, schema=SERVICE_SCHEMA
)
return True return True
async def async_unload_entry(hass, entry):
return True

View File

@@ -0,0 +1,25 @@
from homeassistant import config_entries
import voluptuous as vol
from .const import DOMAIN, CONF_PHONE_NUMBER, CONF_ACCOUNT_NAME
class WhatsAppBridgeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""Handle a config flow for WhatsApp Bridge."""
VERSION = 1
async def async_step_user(self, user_input=None):
"""First step when adding the integration via UI."""
errors = {}
if user_input is not None:
return self.async_create_entry(
title=user_input[CONF_ACCOUNT_NAME],
data=user_input
)
return self.async_show_form(
step_id="user",
data_schema=vol.Schema({
vol.Required(CONF_ACCOUNT_NAME, default="John Doe"): str,
vol.Required(CONF_PHONE_NUMBER, default="491701234567"): str,
}),
errors=errors,
)

View File

@@ -0,0 +1,3 @@
DOMAIN = "whatsapp_bridge_integration"
CONF_PHONE_NUMBER = "phone_number"
CONF_ACCOUNT_NAME = "account_name"

View File

@@ -4,6 +4,7 @@
"documentation": "https://git.bahmcloud.de/bahmcloud/Whatsapp-Bridge-Integration", "documentation": "https://git.bahmcloud.de/bahmcloud/Whatsapp-Bridge-Integration",
"dependencies": [], "dependencies": [],
"codeowners": ["@bahmcloud"], "codeowners": ["@bahmcloud"],
"version": "0.1.0", "version": "0.1.2",
"iot_class": "local_polling" "iot_class": "local_polling",
"config_flow": true
} }

View File

@@ -0,0 +1,30 @@
send_message:
name: Send Message
description: Sends a WhatsApp message via the Bahmcloud Bridge.
fields:
account:
name: Account Profile
description: The name of a saved profile (e.g., Max). Leave empty if using a manual number.
example: "Max"
selector:
text:
number:
name: Manual Number
description: "Direct phone number (Format: 491701234567). Overwrites the Account field."
example: "491701234567"
selector:
text:
message:
name: Message
description: The content of your WhatsApp message.
required: true
example: "The garage door is open!"
selector:
text:
multiline: true
all_accounts:
name: Send to All
description: If enabled, the message is sent to all registered profiles.
default: false
selector:
boolean: