Tariff Management in OpenHAB

This how-to Tariff Management in OpenHAB will show you how to automatically manage and display your electricity tariff status (off-peak or peak) using OpenHAB. You’ll set up time-based rules, a visual indicator in your sitemap, and a string item to clearly reflect the current tariff with color-coding for easy reading.

Tariff Management in OpenHAB

Tariff Management in OpenHAB

Index: Tariff Management in OpenHAB

Background of Tariff Management in OpenHAB

Electricity providers often use time-based pricing—charging more during the day (peak/standard tariff) and less at night or weekends (off-peak). If you’re using OpenHAB for home automation, you can automate tracking and display of the current rate period right in your smart home interface. Here’s how.

Step-by-Step Setup

1. Define Items

Switch Tarif "Tariff Switch"
Switch PeakTariff "Peak Switch"
String Tarif_String "Current Electricity Tariff"

2. Add to Your Sitemap

Text item=Tarif_String label="Current Tariff" valuecolor=[PeakTariff="red", OffPeakTariff="green"]

3. Rules File

This rules file controls when the system switches between Peak and Off-Peak based on your energy provider’s schedule. It also updates the `Tarif_String` display item accordingly—every 15 minutes, on system reboot, and whenever the switch changes.

// 
// Automatic switching between Peak and Off-Peak periods
// Schedule reflects typical utility rates (adjust times as needed)
//
// Tariff Schedule:
// ----------------
// Peak       Mon–Fri: 07:00–20:00, Sat: 07:00–13:00
// Off-Peak   All other times
//

rule "Enable Peak Tariff (Mon–Sat, mornings)"
when
    Time cron "0 0 7 ? * MON,TUE,WED,THU,FRI,SAT *"
then
    logInfo("tariff.rules", "Rule: Switching to Peak tariff")
    Tarif.sendCommand(OFF)
    PeakTariff.sendCommand(ON)
end

rule "Enable Off-Peak Tariff (Mon–Fri, evenings)"
when
    Time cron "0 0 20 ? * MON,TUE,WED,THU,FRI *"
then
    logInfo("tariff.rules", "Rule: Switching to Off-Peak tariff (Mon–Fri)")
    Tarif.sendCommand(ON)
    PeakTariff.sendCommand(OFF)
end

rule "Enable Off-Peak Tariff (Saturday, afternoon)"
when
    Time cron "0 0 13 ? * SAT *"
then
    logInfo("tariff.rules", "Rule: Switching to Off-Peak tariff (Saturday)")
    Tarif.sendCommand(ON)
    PeakTariff.sendCommand(OFF)
end

// Update the visible tariff text regularly
rule "Tarif_String updater (on change, every 15 min, and at startup)"
when
    Item Tarif changed or
    Time cron "0 0/15 * * * ?" or
    System started
then
    if (Tarif.state == ON) {
        Tarif_String.postUpdate("Off-Peak")
    } else if (Tarif.state == OFF) {
        Tarif_String.postUpdate("Peak")
    } else {
        Tarif_String.postUpdate("Unknown Status")
    }
end

Additional Information

This guide is based on a use case where tariffs switch on set daily schedules. You can integrate it with a smart meter in the future for live detection. For persistent storage or graphing tariff history, consider adding persistence strategies in your setup.

Follow Me

If you enjoyed this guide, I’d love it if you followed my work at myhowto.blog:

  • Follow on X
  • Bookmark the blog and come back regularly for more automation tips

Questions & Feedback

Found a better approach? Ran into an issue? I’d love to hear from you. Whether it’s corrections or ideas for improvement, feel free to drop me a message.

Share or Recommend this Tutorial

If this guide helped you, feel free to share it or link it from your own blog or site. The more people automate smartly, the better! You can also link to the full site: myhowto.blog