This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a Homey app (smart home platform) that provides intelligent heating control with utility price optimization. The app allows users to manage heating schedules based on time, occupancy modes (Home/Away, Night/Day, At work), and dynamic electricity pricing from Nordpool markets.
# Build the TypeScript project
npm run build
# Run Homey validate
homey app validate
# Build and install on local Homey device
homey app install
# Run app on Homey device
homey app runMain App (app.ts)
- Extends
Homey.App - Initializes flow cards (triggers, conditions, actions)
- Manages holiday checking logic using
@balmli/homey-public-holidays - Provides
UtilityBillApiinstance to devices for price fetching - Uses
moment-timezonefor date/time handling with Homey's configured timezone
Device (drivers/HeatingController/device.ts)
- Main device logic for heating control
- Manages multiple capabilities:
onoff,home_override,night,at_work,heating,price_*,price_ratio - Uses
PriceFetcherto fetch prices from either Nordpool or Utility Bill app - Uses
PriceComparerfor price-based condition evaluation - Implements mode transitions (Comfort/ECO) based on occupancy and schedule
- Handles capability migrations for app updates
Driver (drivers/HeatingController/driver.ts)
- Basic driver implementation for device pairing
@balmli/homey-utility-prices
- Local dependency (symlinked via
node-homey-utility-prices) - Provides price fetching, comparison, and heating logic
- Key exports:
PriceFetcher,PriceComparer,PriceApi,heatingmodule - Path alias configured in
tsconfig.json
@balmli/homey-utility-prices-client
- Client for communicating with Utility Bill Homey app
@balmli/homey-public-holidays
- Holiday data for multiple European countries
@balmli/homey-logger
- Logging utility with log levels
The app uses Homey Compose (.homeycompose/) to define flow cards:
- Triggers: Events like
comfort_mode,eco_mode,price_changed,high_x_hours_of_day,low_x_hours_of_day - Conditions: Price comparisons, schedule checks, holiday checks
- Actions: Mode changes like
set_at_home_on,set_home_override_on,fetch_prices
Flow card definitions in .homeycompose/flow/ are compiled into app.json by Homey CLI.
Comfort Mode: Enabled when Home AND Day AND (Not at work OR Home override) ECO Mode: All other conditions
The app calculates these modes based on:
- Time-based schedules (configurable start/end hours for workdays/weekends)
- Occupancy states (home/away, at work)
- Overrides (home override flag)
- Holiday calendar integration
The device supports multiple price-based features:
- Current price tracking with multiple currencies (EUR, NOK, SEK, DKK)
- High/low price detection for X hours of day
- Price comparison to daily average
- Consecutive hours with lowest/highest total price
- Price among X lowest/highest in time periods
- Integration with Nordpool spot prices or Utility Bill app
Device settings control:
- Schedule hours (workday/non-workday start/end, work hours)
- Price area (Nordpool regions)
- Currency
- Country for holidays
- Price source (Nordpool or Utility Bill app)
Price Fetching
- Each device has a random sync offset (0-3600 seconds) to avoid simultaneous API calls
- Stored in device store as
syncTime - Prices are cached and refetched at appropriate intervals
Capability Management
- Dynamic capability management based on selected currency (only shows relevant price capability)
- Migration logic in
migrate()andfixPrice()methods to add/remove capabilities on app updates
Time Checking
- Scheduled checks via
scheduleCheckTime()to update modes - Triggers events when modes change (night/day, at work, heating on/off)
Store Values
syncTime: Random offset for price fetching_holidayToday: Manual holiday override
Tests are located in test2/ directory and focus on Nordpool price fetching for different regions.
This app uses Homey SDK v3 (configured in app.json). Minimum Homey firmware version is 5.0.0.
Node.js 18.20.8 (specified in .nvmrc)
- Extends
@tsconfig/node12 - Outputs to
build/directory - Allows JavaScript files
- Path alias for local
@balmli/homey-utility-pricesdependency