diff --git a/custom_components/tibber_prices/binary_sensor/core.py b/custom_components/tibber_prices/binary_sensor/core.py index 0233bb8..1b1beb2 100644 --- a/custom_components/tibber_prices/binary_sensor/core.py +++ b/custom_components/tibber_prices/binary_sensor/core.py @@ -207,11 +207,8 @@ class TibberPricesBinarySensor(TibberPricesEntity, BinarySensorEntity, RestoreEn # Get expected intervals for tomorrow (handles DST) expected_intervals = self.coordinator.time.get_expected_intervals_for_day(tomorrow_date) - if interval_count == expected_intervals: - return True - if interval_count == 0: - return False - return False + # True only when ALL intervals are available (partial = not available) + return interval_count == expected_intervals @property def available(self) -> bool: diff --git a/custom_components/tibber_prices/sensor/calculators/timing.py b/custom_components/tibber_prices/sensor/calculators/timing.py index fd7431a..78b7f92 100644 --- a/custom_components/tibber_prices/sensor/calculators/timing.py +++ b/custom_components/tibber_prices/sensor/calculators/timing.py @@ -183,9 +183,7 @@ class TibberPricesTimingCalculator(TibberPricesBaseCalculator): return future_periods[1] # Default: return first future period - return future_periods[0] if future_periods else None - - return None + return future_periods[0] def _calc_remaining_minutes(self, period: dict) -> int: """ diff --git a/custom_components/tibber_prices/services/get_price.py b/custom_components/tibber_prices/services/get_price.py index 31ccc1f..43d193e 100644 --- a/custom_components/tibber_prices/services/get_price.py +++ b/custom_components/tibber_prices/services/get_price.py @@ -1,18 +1,13 @@ """ Service handler for get_price service. -This service provides direct access to the interval pool for testing and development -purposes. It uses intelligent caching to minimize API calls by fetching only missing -intervals from the API. +This service fetches raw price interval data for any time range using the +interval pool's intelligent caching. Only intervals not already cached are +fetched from the Tibber API. Functions: handle_get_price: Service handler for fetching price data -Used for: - - Testing interval pool caching logic - - Development and debugging of historical data queries - - Verifying gap detection and cache hit/miss behavior - """ from __future__ import annotations diff --git a/docs/user/docs/actions.md b/docs/user/docs/actions.md index 13e4b37..acd6995 100644 --- a/docs/user/docs/actions.md +++ b/docs/user/docs/actions.md @@ -303,6 +303,57 @@ data: --- +### tibber_prices.get_price + +**Purpose:** Fetches raw price interval data for any time range. Uses intelligent caching — only intervals not already cached are fetched from the Tibber API. + +**Parameters:** + +| Parameter | Description | Required | +|-----------|-------------|----------| +| `entry_id` | Integration entry ID | Yes | +| `start_time` | Start of the time range | Yes | +| `end_time` | End of the time range | Yes | + +**Example:** + +```yaml +service: tibber_prices.get_price +data: + entry_id: YOUR_CONFIG_ENTRY_ID + start_time: "2025-11-01T00:00:00" + end_time: "2025-11-02T00:00:00" +response_variable: price_data +``` + +**Response Format:** + +```json +{ + "home_id": "abc-123", + "start_time": "2025-11-01T00:00:00+01:00", + "end_time": "2025-11-02T00:00:00+01:00", + "interval_count": 96, + "price_info": [ + { + "startsAt": "2025-11-01T00:00:00+01:00", + "total": 0.2534, + "energy": 0.1218, + "tax": 0.1316 + } + ] +} +``` + +**Use cases:** +- Fetching historical price data for analysis +- Comparing prices across arbitrary date ranges +- Building custom charts with historical data + +**Note:** Times are automatically converted to your Tibber home's timezone. The interval pool caches previously fetched intervals, so repeated calls for the same range are fast. + +--- + ## Migration from Chart Data Export Sensor If you're still using the `sensor._chart_data_export` sensor, consider migrating to the `tibber_prices.get_chartdata` action: diff --git a/docs/user/docs/configuration.md b/docs/user/docs/configuration.md index 1cff410..1946772 100644 --- a/docs/user/docs/configuration.md +++ b/docs/user/docs/configuration.md @@ -91,7 +91,7 @@ Configure the Coefficient of Variation (CV) boundaries: Configure detection of favorable price windows. Three collapsible sections: **Period Settings:** -- Minimum period length (default: 30 min) +- Minimum period length (default: 60 min) - Maximum price level to include (default: CHEAP) - Gap tolerance: how many expensive intervals to bridge (default: 1) @@ -131,7 +131,7 @@ Information page for the legacy chart data export sensor. For new setups, use th ### Average Sensor Display Settings -**Location:** Settings → Devices & Services → Tibber Prices → Configure → Step 6 +**Location:** Settings → Devices & Services → Tibber Prices → Configure → **General Settings** The integration allows you to choose how average price sensors display their values. This setting affects all average sensors (daily, 24h rolling, hourly smoothed, and future forecasts). diff --git a/docs/user/docs/sensors-trends.md b/docs/user/docs/sensors-trends.md index 752c27c..ec62562 100644 --- a/docs/user/docs/sensors-trends.md +++ b/docs/user/docs/sensors-trends.md @@ -176,6 +176,35 @@ A change from `rising` to `strongly_rising` (same direction) is **not** reported --- +## Next Price Trend Change In (Countdown) + +**Entity ID:** `sensor._next_price_trend_change_in` + +A **countdown timer** companion to the Next Price Trend Change sensor above. Instead of a timestamp, it shows **how many minutes** remain until the trend changes direction. + +**State:** Duration in minutes until the next trend change (displayed in hours via HA unit conversion). Unavailable if no change is predicted. + +**Use cases:** +- Dashboard countdown: "Trend changes in 1.5 h" +- Automation trigger: "If trend change is less than 15 minutes away, prepare for price direction change" + +**Example automation:** + +```yaml +trigger: + - platform: numeric_state + entity_id: sensor._next_price_trend_change_in + below: 0.25 # 15 minutes (displayed in hours) +action: + - service: notify.mobile_app + data: + message: "Price trend is about to change direction!" +``` + +**Tip:** Use this sensor for "HOW LONG" and the Next Price Trend Change sensor (timestamp) for "WHEN". + +--- + ## How to Use Trend Sensors for Decisions :::danger Common Misconception — Don't "Wait for Stable"! diff --git a/docs/user/docs/sensors-volatility.md b/docs/user/docs/sensors-volatility.md index 92c094b..51d1452 100644 --- a/docs/user/docs/sensors-volatility.md +++ b/docs/user/docs/sensors-volatility.md @@ -39,6 +39,7 @@ All volatility sensors provide these attributes: | Attribute | Description | Example | |---|---|---| +| `price_volatility` | Volatility level (language-independent, always English) | `"moderate"` | | `price_coefficient_variation_%` | The calculated Coefficient of Variation | `23.5` | | `price_spread` | The difference between the highest and lowest price | `12.3` | | `price_min` | The lowest price in the period | `10.2` |