Skip to content
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
30 changes: 21 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@

**Custom Generac integration component with support for generators and propane tank monitors. It will set up the following platforms.**

| Platform | Entities created for each generator |
| --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `binary_sensor` | `is_connected`, `is_connecting`, `has_maintenance_alert`, `has_warning`, `missed_exercise` |
| `button` | `reset_service_timer`, `boost_polling` |
| `sensor` | `status`, `run_time`, `protection_time`, `activation_date`, `last_seen`, `connection_time`, `battery_voltage`, `device_type`, `dealer_email`, `dealer_name`, `dealer_phone`, `address`, `status_text`, `status_label`, `serial_number`, `model_number`, `device_ssid`, `panel_id`, `hours_until_service` |
| Platform | Entities created for each generator |
| --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `binary_sensor` | `is_connected`, `is_connecting`, `has_maintenance_alert`, `has_warning`, `missed_exercise`, plus conditional `enrolled_in_vpp`, `active_vpp_event`, `subscription_dunning` |
| `button` | `reset_service_timer`, `boost_polling` |
| `sensor` | `status`, `run_time`, `protection_time`, `activation_date`, `last_seen`, `connection_time`, `battery_voltage`, `device_type`, `dealer_email`, `dealer_name`, `dealer_phone`, `address`, `status_text`, `status_label`, `error_code`, `serial_number`, `model_number`, `device_ssid`, `panel_id`, `signal_strength`, `hours_until_service`, optional `exercise_minutes`, `outdoor_temperature`, `device_battery_level` |

| Platform | Entities created for each propane tank monitor |
| --------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| `binary_sensor` | `is_connected`, `is_connecting`, `has_maintenance_alert`, `has_warning` |
| `sensor` | `status`, `capacity`, `fuel_level`, `fuel_type`, `orientation`, `last_reading_date`, `battery_level`, `address`, `device_type` |
| Platform | Entities created for each propane tank monitor |
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `binary_sensor` | `is_connected`, `is_connecting`, `has_maintenance_alert`, `has_warning`, plus conditional `subscription_dunning` |
| `sensor` | `status`, `capacity`, `fuel_level`, `remaining_fuel`, `estimated_runtime`, `fuel_type`, `orientation`, `last_reading_date`, `battery_level`, `address`, `device_type`, optional `signal_strength`, `device_battery_level`, `outdoor_temperature` |

![example][exampleimg]

Expand Down Expand Up @@ -66,6 +66,12 @@ Click this button to skip steps 1 and 2 below: [![Open your Home Assistant insta

## Configuration is done in the UI

### Options (`Configure`)

Open **Settings → Devices & services → Generac MobileLink → Configure** to adjust enabled platforms, polling intervals, readiness thresholds, and fuel autonomy calculation:

- **Estimated fuel burn rate (gal/h)** (`fuel_burn_rate`, default `2.2` gal/h LP at typical 50% load): Used by the propane monitor `Estimated Runtime Remaining` (`estimated_runtime`) sensor to convert `Remaining Fuel` (`remaining_fuel`, in gallons) into hours of generator runtime remaining (`remaining_fuel / fuel_burn_rate`).

### Adaptive Polling & Outage Boost

To stay gentle on Generac's rate-limited cloud API during normal standby while reacting quickly during exercises, outages, and warnings, polling adapts automatically between two configurable intervals (both clamped to at least `10` seconds):
Expand All @@ -80,6 +86,12 @@ You can also trigger fast polling manually (for example, from an automation trig
- **Outage Boost Poll button (`button.<device>_outage_boost_poll`)**: Created for each generator; pressing it immediately refreshes data and enables boost polling for `30` minutes.
- **`generac.boost_polling` action (service)**: Switches loaded entries into boost polling and triggers an immediate refresh. Accepts optional `duration_minutes` (`1`–`120`, default `30`) and optional `entry_id` (targets all loaded Generac entries if omitted).

### Telemetry, Long-Term Statistics & Diagnostics

- **Long-Term Statistics (LTS)**: Operational numeric sensors expose Home Assistant `state_class` (`total_increasing` on `run_time` and `protection_time`; `measurement` on `battery_voltage`, `exercise_minutes`, `outdoor_temperature`, `capacity`, `fuel_level`, `remaining_fuel`, `estimated_runtime`, `signal_strength`, `device_battery_level`, and `hours_until_service`) for history graphs and long-term recorder statistics.
- **Fault, VPP & Subscription Telemetry**: Generators expose active fault codes via `Error Code` (`error_code`), and—when present in the MobileLink payload—Virtual Power Plant status (`enrolled_in_vpp`, `active_vpp_event`) and subscription billing alerts (`subscription_dunning`).
- **Diagnostic Categorization**: Static metadata and diagnostic entities (serial/model/panel ID, device SSID/type, address, dealer contact info, activation/last-seen/connection timestamps, fuel type, tank orientation, signal strength, VPP enrollment, and subscription billing alert) are grouped under Home Assistant's **Diagnostic** entity category to keep primary dashboards uncluttered.

### Readiness Tracking, Maintenance Timer & Repairs Alerts

Each generator automatically tracks exercise activity and maintenance runtime baselines using Home Assistant storage (persisting cleanly across restarts without reloading the integration):
Expand Down
56 changes: 55 additions & 1 deletion custom_components/generac/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from homeassistant.components.binary_sensor import BinarySensorDeviceClass
from homeassistant.components.binary_sensor import BinarySensorEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import EntityCategory
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback

Expand Down Expand Up @@ -38,8 +39,17 @@ def sensors(item: Item | None = None) -> list[Type[GeneracEntity]]:
GeneracMaintenanceAlertSensor,
GeneracWarningSensor,
]
if item is not None and item.apparatus.type == DEVICE_TYPE_GENERATOR:
if item is None:
return lst
if item.apparatus.type == DEVICE_TYPE_GENERATOR:
lst.append(GeneracMissedExerciseSensor)
if (
item.apparatusDetail.enrolledInVpp is not None
or item.apparatusDetail.hasActiveVppEvent is not None
):
lst.extend([GeneracVppEnrolledSensor, GeneracActiveVppEventSensor])
if item.apparatusDetail.subscription is not None:
lst.append(GeneracSubscriptionDunningSensor)
return lst


Expand Down Expand Up @@ -123,3 +133,47 @@ class GeneracMissedExerciseSensor(GeneracEntity, BinarySensorEntity):
def is_on(self) -> bool:
"""Return True if the generator has missed its exercise window."""
return bool(self.coordinator.is_missed_exercise(self.device_id))


class GeneracVppEnrolledSensor(GeneracEntity, BinarySensorEntity):
"""Whether the generator is enrolled in a Virtual Power Plant program."""

entity_key = "enrolled_in_vpp"
entity_label = "VPP Enrolled"

_attr_entity_category = EntityCategory.DIAGNOSTIC

@property
def is_on(self):
"""Return true if the generator is enrolled in VPP."""
return bool(self.aparatus_detail.enrolledInVpp)


class GeneracActiveVppEventSensor(GeneracEntity, BinarySensorEntity):
"""Whether a Virtual Power Plant dispatch event is currently active."""

entity_key = "active_vpp_event"
entity_label = "Active VPP Event"

@property
def is_on(self):
"""Return true if a VPP event is active."""
return bool(self.aparatus_detail.hasActiveVppEvent)


class GeneracSubscriptionDunningSensor(GeneracEntity, BinarySensorEntity):
"""Whether the Mobile Link subscription is in billing dunning."""

entity_key = "subscription_dunning"
entity_label = "Subscription Billing Alert"

_attr_device_class = BinarySensorDeviceClass.PROBLEM
_attr_entity_category = EntityCategory.DIAGNOSTIC

@property
def is_on(self):
"""Return true if subscription billing is in dunning."""
return bool(
self.aparatus_detail.subscription
and self.aparatus_detail.subscription.isDunning
)
21 changes: 20 additions & 1 deletion custom_components/generac/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"""
import asyncio
import logging
import math
import time

import aiohttp
Expand All @@ -39,6 +40,7 @@
from .const import CONF_ACTIVE_SCAN_INTERVAL
from .const import CONF_DPOP_PEM
from .const import CONF_EXERCISE_INTERVAL_DAYS
from .const import CONF_FUEL_BURN_RATE
from .const import CONF_MFA_CODE
from .const import CONF_OPTIONS
from .const import CONF_PASSWORD
Expand All @@ -49,6 +51,7 @@
from .const import CONF_TOKEN_ISSUED_AT
from .const import CONF_USERNAME
from .const import DEFAULT_ACTIVE_SCAN_INTERVAL
from .const import DEFAULT_FUEL_BURN_RATE
from .const import DEFAULT_SCAN_INTERVAL
from .const import DOMAIN
from .utils import async_client_session
Expand Down Expand Up @@ -483,6 +486,8 @@ def async_get_options_flow(config_entry):

def _option_validator(key: str, option_type: type):
"""Build a Voluptuous validator for an integration option."""
if key == CONF_FUEL_BURN_RATE:
return vol.All(vol.Coerce(float), vol.Range(min=0.0, min_included=False))
if option_type is float:
return vol.All(vol.Coerce(float), vol.Range(min=0.0))
if key in (CONF_SERVICE_INTERVAL_HOURS, CONF_EXERCISE_INTERVAL_DAYS):
Expand All @@ -496,6 +501,20 @@ class GeneracOptionsFlowHandler(config_entries.OptionsFlow):
def __init__(self, config_entry):
self.options = dict(entry_options(config_entry))

@staticmethod
def _option_default(key: str, opt: dict, current: dict):
"""Return a safe form default for an option key."""
default = current.get(key, opt["default"])
if key == CONF_FUEL_BURN_RATE:
if isinstance(default, bool):
return DEFAULT_FUEL_BURN_RATE
try:
rate = float(default)
except (TypeError, ValueError):
return DEFAULT_FUEL_BURN_RATE
return rate if math.isfinite(rate) and rate > 0 else DEFAULT_FUEL_BURN_RATE
return default

async def async_step_init(self, user_input=None): # pylint: disable=unused-argument
return await self.async_step_user()

Expand All @@ -509,7 +528,7 @@ async def async_step_user(self, user_input=None):
data_schema=vol.Schema(
{
vol.Required(
k, default=self.options.get(k, v["default"])
k, default=self._option_default(k, v, self.options)
): _option_validator(k, v["type"])
for k, v in CONF_OPTIONS.items()
}
Expand Down
3 changes: 3 additions & 0 deletions custom_components/generac/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
DEFAULT_ACTIVE_SCAN_INTERVAL = 120
ACTIVE_COOLDOWN_SECONDS = 300
DEFAULT_BOOST_DURATION_MINUTES = 30
DEFAULT_FUEL_BURN_RATE = 2.2
SERVICE_BOOST_POLLING = "boost_polling"

# Platforms
Expand Down Expand Up @@ -65,6 +66,7 @@
CONF_DPOP_PEM = "dpop_pem"
CONF_SCAN_INTERVAL = "scan_interval"
CONF_ACTIVE_SCAN_INTERVAL = "active_scan_interval"
CONF_FUEL_BURN_RATE = "fuel_burn_rate"
CONF_SERVICE_INTERVAL_HOURS = "service_interval_hours"
CONF_EXERCISE_INTERVAL_DAYS = "exercise_interval_days"
CONF_LOW_BATTERY_THRESHOLD = "low_battery_threshold"
Expand All @@ -90,6 +92,7 @@
**bool_opts,
CONF_SCAN_INTERVAL: {"type": int, "default": DEFAULT_SCAN_INTERVAL},
CONF_ACTIVE_SCAN_INTERVAL: {"type": int, "default": DEFAULT_ACTIVE_SCAN_INTERVAL},
CONF_FUEL_BURN_RATE: {"type": float, "default": DEFAULT_FUEL_BURN_RATE},
CONF_SERVICE_INTERVAL_HOURS: {
"type": int,
"default": DEFAULT_SERVICE_INTERVAL_HOURS,
Expand Down
Loading
Loading