Skip to content
PN Scripts

Development

Heating water on the Bulgarian night tariff with Home Assistant, without missing a night

  • PN Scripts
  • 9 min read

An electric water heater is the easiest load in a Bulgarian home to move into the night tariff: it stores its heat, and nobody minds when it runs. Most people do it with a mechanical timer set to 22:00 or 23:00. The timer is right for part of the year and wrong for the rest, because the night zone moves by an hour twice a year and the timer either does not move at all or moves on a different day. A smart plug or a Home Assistant automation copied from a forum usually repeats the same mistake. This guide shows when the night zone really starts, how to compute it in code, how much heating a tank needs, and how to build a controller that keeps to the cheap hours even when the Wi-Fi is down. The Python sample was run on Python 3.12, as printed.

#When the night zone starts

Bulgarian household meters with two scales have two zones a day. Energo-Pro's page for household customers publishes them by month: from November to March the night zone runs from 22:00 to 06:00, and from April to October from 23:00 to 07:00. So the switch falls on 1 April and 1 November, not on the nights the clocks change at the end of March and October. Other distributors may word it differently, and your bill or your distributor's page is the authority for your meter; check it before you set anything up.

The price difference is worth the trouble. On the regulated household prices in force from 1 July 2026, a night kWh with its network charges costs about 60 % of a day kWh at both Energo-Pro and EVN, before and after VAT.

Three ways a simple schedule goes wrong:

  • A timer fixed at 22:00 to 06:00 heats in the day zone from 22:00 to 23:00 for seven months, and misses the cheap hour from 06:00 to 07:00.
  • A timer or automation that follows the clock change switches on the last Sunday of March and of October, a few days before the table does, and heats at the day price in between.
  • An automation in Home Assistant runs only while Home Assistant does. A reboot at 22:59 or a broken Wi-Fi link means a cold shower in the morning.

#Computing the zone

The rule fits in a few lines. The sample below computes the night window for a day either by the months or by the clock change, lists the days of 2026 on which the two disagree, checks one evening and works out how long a tank takes to heat:

from datetime import date, datetime, time, timedelta
from zoneinfo import ZoneInfo

SOFIA = ZoneInfo("Europe/Sofia")


def night_window(day: date, by: str = "months") -> tuple[time, time]:
    """The night zone for a day: 22:00-06:00 in winter, 23:00-07:00 in summer.

    by="months": summer from 1 April to 31 October, as a distributor's table by month.
    by="clock":  summer while the clocks are on summer time.
    """
    if by == "months":
        summer = 4 <= day.month <= 10
    else:
        summer = bool(datetime.combine(day, time(12), SOFIA).dst())
    return (time(23), time(7)) if summer else (time(22), time(6))


def is_night(moment: datetime, by: str = "months") -> bool:
    local = moment.astimezone(SOFIA)
    start, end = night_window(local.date(), by)
    t = local.time()
    if t >= start:
        return True
    # before the end of the night that started the evening before
    _, yesterday_end = night_window(local.date() - timedelta(days=1), by)
    return t < yesterday_end


def heating_hours(litres: float, cold_c: float, target_c: float, heater_kw: float) -> tuple[float, float]:
    kwh = litres * 4.186 * (target_c - cold_c) / 3600  # water: 4.186 kJ per kg and degree
    return round(kwh, 2), round(kwh / heater_kw, 2)


day = date(2026, 1, 1)
while day.year == 2026:
    if night_window(day, "months") != night_window(day, "clock"):
        print(day, "months:", night_window(day, "months")[0], "clock:", night_window(day, "clock")[0])
    day += timedelta(days=1)

print(is_night(datetime(2026, 10, 27, 22, 30, tzinfo=SOFIA)))           # a distributor's table
print(is_night(datetime(2026, 10, 27, 22, 30, tzinfo=SOFIA), "clock"))  # the clock change
print(heating_hours(80, 15, 60, 2.0))

In 2026 the two schedules disagree on ten days: from 29 to 31 March, when the clocks are already on summer time but the table still says 22:00, and from 25 to 31 October, when the clocks are back on winter time but the table still says 23:00. At 22:30 on 27 October the table says day and the clock says night; a heater that follows the clock pays the day price for that half hour every evening of the week. The times are worked out in Europe/Sofia with zoneinfo, so the code also gives the right answer on a server that runs on UTC.

#How long the tank needs

Heating water takes about 4.186 kJ per litre and degree. An 80-litre tank heated from 15 °C to 60 °C needs 4.19 kWh, which a 2 kW element delivers in 2.09 hours, so the eight hours of the night zone are plenty for a full tank and leave room for the losses of the day. A larger tank or colder water in winter still fits; a tank that cannot reach its target in one night usually has a failing element or a thermostat set too low.

Do not save on temperature. The WHO's fact sheet on legionellosis says the bacteria grow in water between 20 and 50 °C, and that keeping hot water above 50 °C requires the water leaving the heater to be at or above 60 °C. Heat to 60 °C at night and let the heater's own thermostat stay as a backstop.

#A controller that keeps to the night

The reliable setup splits the job in two. Home Assistant knows the tariff, the prices and the calendar, so it publishes one on and off sensor for the night zone. A small controller next to the heater, an ESP32 with a temperature probe in the thermostat pocket and a contactor, follows that sensor while it can see it, and keeps its own clock with the same rule for when it cannot. It heats only when three things agree: the zone is night, the water is below its restart point, and the probe gives a sane reading. Some rules worth copying:

  • Hysteresis. Heat to the target and start again only a few degrees below it, so the contactor does not chatter around one temperature.
  • Fail safe. No reading from the probe means off, and a hard cut-off well above the target means off, whatever any automation says.
  • Size the switch for the heater. A 3 kW element draws about 13 A at 230 V; a relay module on a development board drives the coil of a contactor rated for that load, never the heater itself. Mains wiring belongs in a closed box and in qualified hands.
  • A boost button. Guests arrive, the tank is cold at 18:00: a timed boost that returns to the night schedule by itself is better than a mode someone forgets to switch back.

#Two products that do this together

We made Tokomer, a Home Assistant integration for Bulgarian day and night tariffs. It shows the zone in force, an on and off night tariff sensor, the price per kWh now for the Energy dashboard and the time of the next change, splits a meter's energy into day and night kWh with the cost, and has an action that finds the cheapest start for a run of a given length. You enter the prices from your bill; nothing is fetched from distributors' websites. By default its season follows the zones by month, switching on 1 April and 1 November as Energo-Pro publishes them, and a "With the clock change" option covers a meter that follows the clocks instead. Its tests ran inside a real Home Assistant 2026.10.0 core.

For the heater itself we made Wirefold, a set of ESPHome packages whose water heater package does what the section above describes: it follows Home Assistant's night tariff sensor while connected, its own clock otherwise, with Night only, Always, Boost and Off modes, hysteresis, a safety cut-off at 80 °C and an estimated energy sensor. Its own clock uses the same zones by month by default, with a setting for meters that follow the clock change, so on the days in March and October when the two rules differ it keeps to the night even when Home Assistant cannot be reached. Every example device validates with ESPHome 2026.9.1 and the heater logic was compiled for Linux and driven by tests; no firmware was flashed to a real board. Both are listed as Coming soon.

#Frequently asked questions

When does the night tariff start in Bulgaria?

Energo-Pro publishes 22:00 to 06:00 from November to March and 23:00 to 07:00 from April to October. Check your own distributor's page or your bill, because that is what your meter follows.

Why is my water heater on a timer running at the day price?

Because the night zone moves by an hour twice a year. A timer set once is wrong for months; a timer that follows the clock change is wrong for a few days each spring and autumn.

How long does a water heater need to heat at night?

About 4.19 kWh for 80 litres from 15 to 60 °C, a little over two hours at 2 kW. The eight hours of the night zone are enough for a full tank.

Is it safe to keep the water at a lower temperature to save money?

Not below 60 °C at the heater. The WHO says Legionella grows between 20 and 50 °C and recommends water leaving the heater at or above 60 °C.

#Sources

Keep reading

Keep reading

Comments

Comments

No comments yet. Ask a question or share what worked for you.

Leave a comment

shown with your comment; a nickname is fine
optional; only for reply notifications, never shown
Plain text with **bold**, *italic*, `code`, > quotes and links.

Next step

pnscripts.com/contact

Talk to the team

Ask about an article, or tell us about a project you want built. We reply within one business day.

Write to us

The PN Scripts family

Other PN Scripts sites

Hosting, games and the blog each have their own site, run by the same company.

  • pnscripts.com

    PN Scripts

    Software engineering

    Custom web, mobile and API development, plus our open-source products and plugins.

  • games.pnscripts.com

    Games

    Games and game servers

    The home for PN Scripts games: free browser games you can play right now, with game servers coming soon.

  • hosting.pnscripts.com

    Hosting

    Hosting and infrastructure

    Shared hosting, KVM VPS, dedicated servers and domains, from the same company that builds your project.

  • blog.pnscripts.com

    Blog

    Articles and field notes

    Practical articles on software development, hosting, open source and games, written with AI assistance and checked by the people who build them.

    You are here