Skip to content

Daily Notification

Send a push notification to a mobile device at a configurable time each day. Drop this in to get a morning greeting, a reminder, or any fixed-schedule alert without touching Home Assistant automations.

The Code

from pydantic_settings import SettingsConfigDict

from hassette import App, AppConfig


class DailyNotificationConfig(AppConfig):
    model_config = SettingsConfigDict(env_prefix="DAILY_NOTIFICATION_")

    notify_time: str = "08:00"
    """Wall-clock time for the daily notification in HH:MM format. Default: 08:00."""

    notify_service: str = "mobile_app_phone"
    """Home Assistant notify service name (the part after `notify.`). Default: mobile_app_phone."""

    message: str = "Good morning! Have a great day."
    """Message body sent with the notification."""


class DailyNotificationApp(App[DailyNotificationConfig]):
    async def on_initialize(self) -> None:
        await self.scheduler.run_daily(
            self.send_notification,
            at=self.app_config.notify_time,
        )
        self.logger.info(
            "Daily notification scheduled at %s via notify.%s",
            self.app_config.notify_time,
            self.app_config.notify_service,
        )

    async def send_notification(self) -> None:
        await self.api.call_service(
            "notify",
            self.app_config.notify_service,
            message=self.app_config.message,
            title="Daily Reminder",
        )
        self.logger.info("Daily notification sent.")

How It Works

  • DailyNotificationConfig defines three env-backed fields: the time as a "HH:MM" string, the notify service name, and the message body — all overridable without changing code.
  • on_initialize calls self.scheduler.run_daily(...) with at=self.app_config.notify_time, scheduling a wall-clock-aligned daily job. The Daily trigger is cron-backed and handles DST transitions correctly.
  • send_notification calls self.api.call_service("notify", <service>, ...) — the domain is notify and the service name is the part after notify. in your Home Assistant instance (e.g., mobile_app_phone).
  • Extra keyword arguments to call_service (message, title) become service_data fields forwarded to Home Assistant.

Variations

Different time — Change notify_time in your config:

# apps.yaml
daily_notification:
  module: daily_notification
  class: DailyNotificationApp
  notify_time: "20:30"   # 8:30 PM
  notify_service: mobile_app_tablet
  message: "Time to wind down."

Include sensor data — Fetch a sensor value before sending:

async def send_notification(self) -> None:
    temp_state = await self.api.get_state("sensor.outdoor_temperature")
    message = f"Good morning! It's {temp_state.value}° outside."
    await self.api.call_service(
        "notify",
        self.app_config.notify_service,
        message=message,
        title="Daily Reminder",
    )

Weekdays only — Swap run_daily for run_cron to skip weekends:

h, m = self.app_config.notify_time.split(":")
await self.scheduler.run_cron(self.send_notification, f"{m} {h} * * 1-5")

See Also