Skip to content

Commit 1a5c37c

Browse files
committed
feat: added basic integration
1 parent 67c1a19 commit 1a5c37c

17 files changed

Lines changed: 2267 additions & 2 deletions

File tree

.github/workflows/hassfest.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Validate with hassfest
2+
3+
on:
4+
push:
5+
pull_request:
6+
# schedule:
7+
# - cron: "0 0 * * *"
8+
9+
jobs:
10+
validate:
11+
runs-on: "ubuntu-latest"
12+
steps:
13+
- uses: "actions/checkout@v3"
14+
- uses: home-assistant/actions/hassfest@master

.github/workflows/validate.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Validate
2+
3+
on:
4+
push:
5+
pull_request:
6+
# schedule:
7+
# - cron: "0 0 * * *"
8+
workflow_dispatch:
9+
10+
jobs:
11+
validate:
12+
runs-on: "ubuntu-latest"
13+
steps:
14+
- uses: "actions/checkout@v4"
15+
- name: HACS validation
16+
uses: "hacs/action@main"
17+
with:
18+
category: "integration"

README.md

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,49 @@
1-
# Boiler Controller HA integration
1+
# Boiler Controller HA Integration
22

3-
[TODO]
3+
A Home Assistant integration for automatically controlling a Shelly Dimmer 0/1-10V PM Gen3 based on P1 smart meter data.
4+
5+
## Features
6+
7+
This integration:
8+
- Reads data from a P1 smart meter via an existing Home Assistant device
9+
- Controls a Shelly Dimmer 0/1-10V PM Gen3 based on live net consumption
10+
- Automatically switches between different dimmer percentages depending on consumption
11+
- Provides Shelly telemetry sensors (voltage, current, power, temperature, energy)
12+
- Exposes manual override entities so you can switch between automatic logic and a fixed brightness when needed
13+
14+
## Installation
15+
16+
1. Install via HACS or copy the `custom_components/boiler_controller` folder to your Home Assistant configuration
17+
2. Restart Home Assistant
18+
3. Go to Settings > Devices & Services
19+
4. Click "Add Integration" and search for "Boiler Controller"
20+
5. Follow the configuration steps:
21+
- Select your P1 smart meter device
22+
- Choose the correct power entity from the P1 meter
23+
- Select your Shelly Dimmer device
24+
25+
## Configuration
26+
27+
The integration requires:
28+
- A working P1 smart meter integration in Home Assistant
29+
- A Shelly Dimmer 0/1-10V PM Gen3 device connected to Home Assistant
30+
31+
## Advanced Settings & Manual Override
32+
33+
Via the integration options you can adjust the minimum and maximum dimmer bounds that the automatic logic uses.
34+
35+
For ad-hoc control you also get two helper entities once the integration is set up:
36+
37+
- `Select`**{Integration Name} Dimmer Mode**: choose `auto` to let the controller react to power usage, or `manual` to override the Shelly brightness yourself.
38+
- `Number`**{Integration Name} Manual Brightness**: specify the brightness percentage (0–100). This value is only applied when the mode select is in `manual`.
39+
40+
Switching back to `auto` immediately returns control to the P1-driven logic.
41+
42+
## Logic
43+
44+
The default logic:
45+
- At 0W consumption: dimmer at minimum
46+
- At 3000W+ consumption: dimmer at maximum
47+
- In between: linearly scaled between min and max
48+
49+
This logic can be customized in the `controller.py` file.

custom_components/.DS_Store

6 KB
Binary file not shown.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import logging
2+
3+
from homeassistant.core import HomeAssistant
4+
from homeassistant.config_entries import ConfigEntry
5+
from homeassistant.loader import async_get_integration
6+
7+
from .const import DOMAIN, PLATFORMS
8+
from .controller import BoilerController
9+
10+
_LOGGER = logging.getLogger(__name__)
11+
12+
13+
# Set up the component
14+
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
15+
"""Set up Boiler Controller from a config entry."""
16+
_LOGGER.info("Setting up Boiler Controller")
17+
18+
integration = await async_get_integration(hass, DOMAIN)
19+
integration_version = integration.version
20+
21+
# Create the controller
22+
controller = BoilerController(hass, entry, integration_version)
23+
24+
# Start the controller (now handles missing entities gracefully)
25+
success = await controller.async_start()
26+
if not success:
27+
_LOGGER.error("Failed to start Boiler Controller")
28+
# Don't raise ConfigEntryNotReady anymore - let it start and wait for entities
29+
_LOGGER.warning("Boiler Controller will continue running and wait for entities to become available")
30+
31+
# Store the controller
32+
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = {
33+
"controller": controller,
34+
}
35+
36+
# Set up platforms
37+
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
38+
39+
_LOGGER.info("Boiler Controller setup completed")
40+
return True
41+
42+
# Implement unloading and reloading of the config entry
43+
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
44+
"""Unload a config entry."""
45+
_LOGGER.info("Unloading Boiler Controller")
46+
47+
# Unload platforms
48+
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
49+
50+
# Stop the controller
51+
controller_data = hass.data.get(DOMAIN, {}).get(entry.entry_id)
52+
if controller_data:
53+
controller = controller_data.get("controller")
54+
if controller:
55+
await controller.async_stop()
56+
57+
# Remove from hass.data
58+
if DOMAIN in hass.data and entry.entry_id in hass.data[DOMAIN]:
59+
hass.data[DOMAIN].pop(entry.entry_id)
60+
61+
return unload_ok
62+
63+
64+
async def async_reload_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
65+
"""Reload config entry."""
66+
await async_unload_entry(hass, entry)
67+
await async_setup_entry(hass, entry)

0 commit comments

Comments
 (0)