Skip to content

DanielBryars/Kronos.Service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Kronos.Service

A .NET service for scheduling and automating time-based activities with Home Assistant integration.

Overview

Kronos.Service is a hosted service application built on .NET that provides reactive scheduling capabilities. It's designed to control and automate devices connected to Home Assistant based on time-based schedules.

Features

  • Reactive Scheduling: Built on System.Reactive (Rx.NET) for efficient event-driven scheduling
  • Home Assistant Integration: Direct control of Home Assistant entities and automation
  • Hosted Service Architecture: Runs as a console-hosted service with proper lifecycle management
  • Configurable Schedules: Define time-based Boolean schedules for automation tasks
  • Tick-based Processing: Regular interval-based checking and execution of scheduled items

Architecture

The service consists of several key components:

  • SchedulerHostedService: Core service that processes scheduled items on regular intervals
  • IScheduleProvider: Provides collection of scheduled items to execute
  • ITimeProvider: Reactive time provider for schedule evaluation
  • IHomeAssistantControl: Interface for controlling Home Assistant devices
  • ScheduledBoolean: Framework for defining time-based Boolean states

Technologies

  • .NET Core: Cross-platform service framework
  • Reactive Extensions (Rx.NET): For reactive, event-driven scheduling
  • Microsoft.Extensions.Hosting: Hosted service infrastructure
  • Microsoft.Extensions.DependencyInjection: Dependency injection container
  • Microsoft.Extensions.Logging: Structured logging

Project Structure

src/
├── Kronos.Service/           # Main hosted service application
├── Kronos.Framework.Schedule/ # Scheduling framework and abstractions
└── Kronos.Scratch/           # Development and testing playground

Configuration

The service uses appsettings.json for configuration:

{
  "Logging": {
    "LogLevel": {
      "Default": "Information"
    }
  }
}

Building

dotnet build Kronos.Service.sln

Running

cd src/Kronos.Service
dotnet run

How It Works

  1. Service initializes with dependency injection container
  2. Schedule provider loads configured scheduled items
  3. Hosted service starts with 1-second tick interval
  4. On each tick, scheduled items are evaluated against current time
  5. When schedule conditions are met, Home Assistant control actions execute
  6. Service continues until stopped

Use Cases

  • Automated heating/cooling schedules
  • Light automation based on time of day
  • Timed device control
  • Smart home scheduling
  • Energy management automation

Dependencies

  • System.Reactive
  • Microsoft.Extensions.Hosting
  • Microsoft.Extensions.Logging
  • Microsoft.Extensions.DependencyInjection
  • Microsoft.Extensions.Configuration

Development

This project follows clean architecture principles with clear separation between:

  • Service hosting (Kronos.Service)
  • Business logic (SchedulerHostedService)
  • Domain framework (Kronos.Framework.Schedule)
  • External integrations (IHomeAssistantControl)

About

Service which Schedules activities

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages