Tutorial : set the TOU(time of use) bill mode in the Home Assistant

Abstract: use one energy meter (brand IAMMETER) to show how to set the TOU(Time Of Use) billing mode in the Home assistant.

Video tutorial:https://youtu.be/7uTE4NAqF_E

Please note: this is a universal tutorial about setting the time of use billing template in the Home Assistant. It does not ask to use a specific brand of energy meter.

 

This is the effect of display the TOU(time of use) billing information in the dashboard.

20221209100302

20221209100357

 

Integrate Energy meter

In this chapter, we use IAMMETER`s energy meter as the example hardware. This tutorial is not related to a specific brand, you can use your own energy meter in your hand.

Add the repository of IAMMETER from the HACS

Click HACS, search "IAMMETER".

image-20221104114959701

image-20221104115111335

image-20221104115145017

 

Add Energy meter

Setting->"Device & Service"

image-20221104115335568

image-20221104115920426

image-20221104120238430

image-20221209160914651

 

image-20221209160952222

image-20221209161015246

 

Add the TOU (Time of Use) billing template from a Yaml file.

click "File editor"

image-20221209161145643

add a new YAML, named "peak.yaml"

image-20221209161436459

Add the following configuration in "peak.yaml"

You can also download the "peak.yaml" from the github here





# Example configuration entry
sensor:
  - platform: template
    sensors:
      #----peak----# 
      ## https://community.home-assistant.io/t/scraping-alectra-utilities-power-website/304234
      energy_price_offpeak:
        friendly_name: "Off-peak Price"
        value_template: "0.3"
        icon_template: mdi:speedometer-slow
        unit_of_measurement: "$"
      energy_price_midpeak:
        friendly_name: "Mid-peak Price"
        value_template: "0.48"
        icon_template: mdi:speedometer-medium
        unit_of_measurement: '$'
      energy_price_onpeak:
        friendly_name: "On-peak Price"
        value_template: "0.6"
        icon_template: mdi:speedometer
        unit_of_measurement: '$'
      # Looks at scraped string and finds the three values that are "0.###" and picks the right one for the current peak. This block is under platform: template
      energy_price_current: 
        friendly_name: "Current peak Price"
        value_template: >-
          {% if is_state('select.daily_energy', 'offpeak') %}
            {{(states('sensor.energy_price_offpeak'))}}
          {% elif is_state('select.daily_energy', 'midpeak') %}
            {{(states('sensor.energy_price_midpeak'))}}
          {% elif is_state('select.daily_energy', 'peak') %}
            {{(states('sensor.energy_price_onpeak'))}}
          {% else %}
            0
          {% endif %}
        icon_template: >-
          {% if is_state('select.daily_energy', 'offpeak') %}
            mdi:speedometer-slow
          {% elif is_state('select.daily_energy', 'midpeak') %}
            mdi:speedometer-medium
          {% elif is_state('select.daily_energy', 'peak') %}
            mdi:speedometer
          {% else %}
            mdi:exclamation-thick
          {% endif %}
        unit_of_measurement: '$'
      daily_energy_peak_money:
        unit_of_measurement: '$'
        value_template: "{{ ( states('sensor.daily_energy_peak')|float * states('sensor.energy_price_current')|float ) | round(2) }}"
      daily_energy_midpeak_money:
        unit_of_measurement: '$'
        value_template: "{{ ( states('sensor.daily_energy_midpeak')|float * states('sensor.energy_price_current')|float ) | round(2) }}"
      daily_energy_offpeak_money:
        unit_of_measurement: '$'
        value_template: "{{ ( states('sensor.daily_energy_offpeak')|float * states('sensor.energy_price_current')|float ) | round(2) }}"
      monthly_energy_peak_money:
        unit_of_measurement: '$'
        value_template: "{{ ( states('sensor.monthly_energy_peak')|float * states('sensor.energy_price_current')|float ) | round(2) }}"
      monthly_energy_midpeak_money:
        unit_of_measurement: '$'
        value_template: "{{ ( states('sensor.monthly_energy_midpeak')|float * states('sensor.energy_price_current')|float ) | round(2) }}"
      monthly_energy_offpeak_money:
        unit_of_measurement: '$'
        value_template: "{{ ( states('sensor.monthly_energy_offpeak')|float * states('sensor.energy_price_current')|float ) | round(2) }}"
      meter_energy_daily_money:
        unit_of_measurement: '$'
        value_template: "{{ (states('sensor.daily_energy_peak_money')) + (states('sensor.daily_energy_midpeak_money')) + (states('sensor.daily_energy_offpeak_money')) }}"
      meter_energy_monthly_money:
        unit_of_measurement: '$'
        value_template: "{{ (states('sensor.monthly_energy_peak_money')) + (states('sensor.monthly_energy_midpeak_money')) + (states('sensor.monthly_energy_offpeak_money')) }}"
utility_meter:
  meter_energy_daily:
    source: sensor.meter_importenergy
    cycle: daily
  meter_energy_monthly:
    source: sensor.meter_importenergy
    cycle: monthly
  daily_energy:
    source: sensor.meter_importenergy
    name: Daily Energy
    cycle: daily
    tariffs:
      - peak
      - offpeak
      - midpeak
  monthly_energy:
    source: sensor.meter_importenergy
    name: Monthly Energy
    cycle: monthly
    tariffs:
      - peak
      - offpeak
      - midpeak
## time:
## peak(9:00—11:30、14:00—16:30、19:00—21:00)、
## midpeak(7:00—9:00、11:30—14:00、16:30—19:00、21:00—23:00)、
## offpeak(23:00—Tomorrow7:00)。
automation:
  trigger:
    - platform: time
      at: "07:00:00"
      variables:
        tariff: "midpeak"
    - platform: time
      at: "09:00:00"
      variables:
        tariff: "peak"
    - platform: time
      at: "11:30:00"
      variables:
        tariff: "midpeak"
    - platform: time
      at: "14:00:00"
      variables:
        tariff: "peak"
    - platform: time
      at: "16:30:00"
      variables:
        tariff: "midpeak"
    - platform: time
      at: "19:00:00"
      variables:
        tariff: "peak"
    - platform: time
      at: "21:00:00"
      variables:
        tariff: "midpeak"
    - platform: time
      at: "23:00:00"
      variables:
        tariff: "offpeak"
#  condition:
#      condition: time
#      weekday:
#      - mon
#      - tue
#      - wed
#      - thu
#      - fri
  action:
    - service: select.select_option
      target:
        entity_id: select.daily_energy
      data:
        option: "{{ tariff }}"
    - service: select.select_option
      target:
        entity_id: select.monthly_energy
      data:
        option: "{{ tariff }}"


CHECK CONFIGURATION, RESTART

image-20221209162317735

Configure the Dashboard(optional)

This chapter just gives a dashboard example to show the TOU billing effect. It is not a necessary step for the TOU billing, you can also use your own dashboard to display the TOU effect.

image-20221209162357474

Add the following cards to Lovelace

Card1

image-20221209162434974





cards:
  - cards:
      - entity: sensor.meter_voltage
        max: 300
        min: 100
        name: voltage
        theme: default
        type: gauge
        needle: false
      - entity: sensor.meter_power
        max: 5000
        min: 0
        name: power
        theme: default
        type: gauge
        needle: false
    type: horizontal-stack
  - type: custom:apexcharts-card
    apex_config:
      chart:
        height: 300
    experimental:
      color_threshold: true
    graph_span: 8h
    show:
      last_updated: true
    header:
      standard_format: false
      show: true
      show_states: true
      colorize_states: true
    now:
      show: true
      color: red
      label: Now
    span:
      end: hour
    series:
      - entity: sensor.meter_power
        name: Power
        type: line
        group_by:
          func: avg
          duration: 1m
        stroke_width: 2
        show:
          extremas: true
          header_color_threshold: true
        color_threshold:
          - value: 100
            color: steelblue
          - value: 800
            color: midnightblue
          - value: 1500
            color: orange
          - value: 2000
            color: orangered
          - value: 3000
            color: red
  - type: custom:apexcharts-card
    apex_config:
      chart:
        height: 300
    experimental:
      color_threshold: true
    graph_span: 8h
    show:
      last_updated: true
    header:
      standard_format: false
      show: true
      show_states: true
      colorize_states: true
    now:
      show: true
      color: red
      label: Now
    span:
      end: hour
    series:
      - entity: sensor.meter_voltage
        name: Voltage
        stroke_width: 2
        group_by:
          func: avg
          duration: 1min
title: Home Energy Peak Off-peak Demo
type: vertical-stack


Card2

image-20221209162627931





cards:
  - type: custom:apexcharts-card
    apex_config:
      chart:
        height: 230
        stacked: true
    graph_span: 7d
    span:
      end: day
    show:
      last_updated: true
    header:
      show: true
      show_states: true
      colorize_states: true
    series:
      - entity: sensor.daily_energy_peak
        name: peak
        type: column
        color: darkviolet
        group_by:
          func: max
          duration: 1d
      - entity: sensor.daily_energy_midpeak
        name: midpeak
        type: column
        color: slateblue
        group_by:
          func: max
          duration: 1d
      - entity: sensor.daily_energy_offpeak
        name: offpeak
        type: column
        color: orangered
        group_by:
          func: max
          duration: 1d
  - type: custom:apexcharts-card
    apex_config:
      chart:
        height: 230
        stacked: true
    graph_span: 7d
    span:
      end: day
    show:
      last_updated: true
    header:
      show: true
      show_states: true
      colorize_states: true
    series:
      - entity: sensor.daily_energy_peak_money
        name: peak
        type: column
        color: darkviolet
        group_by:
          func: max
          duration: 1d
      - entity: sensor.daily_energy_midpeak_money
        name: midpeak
        type: column
        color: slateblue
        group_by:
          func: max
          duration: 1d
      - entity: sensor.daily_energy_offpeak_money
        name: offpeak
        type: column
        color: orangered
        group_by:
          func: max
          duration: 1d
  - type: custom:apexcharts-card
    apex_config:
      chart:
        height: 230
        stacked: true
    graph_span: 7d
    span:
      end: day
    show:
      last_updated: true
    header:
      show: true
      show_states: true
      colorize_states: true
    series:
      - entity: sensor.meter_energy_daily
        name: total
        type: column
        color: darkviolet
        group_by:
          func: max
          duration: 1d
      - entity: sensor.meter_energy_daily_money
        name: total
        type: column
        color: darkviolet
        group_by:
          func: max
          duration: 1d
title: Daily Energy
type: vertical-stack


Card3

image-20221209162944641





type: vertical-stack
cards:
  - type: horizontal-stack
    cards:
      - type: entity
        entity: select.daily_energy
        state_color: false
        name: Current peak
      - hours_to_show: 24
        graph: none
        type: sensor
        entity: sensor.energy_price_current
        detail: 1
    title: Current
  - type: horizontal-stack
    cards:
      - type: sensor
        entity: sensor.daily_energy_peak
        name: peak
      - type: sensor
        entity: sensor.daily_energy_midpeak
        name: midpeak
      - type: sensor
        entity: sensor.daily_energy_offpeak
        name: offpeak
    title: Daily
  - type: horizontal-stack
    cards:
      - hours_to_show: 24
        graph: none
        type: sensor
        entity: sensor.daily_energy_peak_money
        name: peak
        detail: 1
      - type: sensor
        entity: sensor.daily_energy_midpeak_money
        name: midpeak
      - type: sensor
        entity: sensor.daily_energy_offpeak_money
        name: offpeak
  - type: horizontal-stack
    cards:
      - type: sensor
        entity: sensor.monthly_energy_peak
        name: peak
      - type: sensor
        entity: sensor.monthly_energy_midpeak
        name: midpeak
      - type: sensor
        entity: sensor.monthly_energy_offpeak
        name: offpeak
    title: Monthly
  - type: horizontal-stack
    cards:
      - type: sensor
        entity: sensor.monthly_energy_peak_money
        name: peak
      - type: sensor
        entity: sensor.monthly_energy_midpeak_money
        name: midpeak
      - type: sensor
        entity: sensor.monthly_energy_offpeak_money
        name: offpeak
  - type: horizontal-stack
    cards:
      - type: sensor
        entity: sensor.energy_price_onpeak
        name: peak
      - type: sensor
        entity: sensor.energy_price_midpeak
        name: midpeak
      - type: sensor
        entity: sensor.energy_price_offpeak
        name: offpeak
    title: Price list
  - type: markdown
    content: |-
      peak: (9:00-11:30,14:00-16:30,19:00-21:00)
      midpeak: (7:00-9:00,11:30-14:00,16:30-19:00,21:00-23:00)
      offpeak: (23:00:Tomorrow7:00)


20221209100302

 

effect2:

peak3, Sidebar

image-20221209163110044

Card

image-20221209163302693





type: vertical-stack
cards:
  - type: horizontal-stack
    cards:
      - type: vertical-stack
        cards:
          - type: custom:history-explorer-card
            header: Home Energy Peak Off-peak Demo
            uiLayout:
              invertZoom: true
            graphs:
              - type: line
                entities:
                  - entity: sensor.meter_power
                    color: '#3e95cd'
                    fill: rgba(151,187,205,0.15)
              - type: line
                entities:
                  - entity: sensor.meter_voltage
                    color: '#3ecd95'
                    fill: rgba(151,205,187,0.15)
              - type: timeline
                title: Non-numerical sensors
                entities:
                  - entity: select.daily_energy
                    name: Mode
                  - entity: sensor.energy_price_current
                    name: Price
                  - entity: sensor.energy_price_onpeak
                    name: Peak
                  - entity: sensor.energy_price_midpeak
                    name: Midpeak
                  - entity: sensor.energy_price_offpeak
                    name: Offpeak
      - type: vertical-stack
        cards:
          - type: custom:history-explorer-card
            defaultTimeRange: 1w
            header: Daily Energy history
            uiLayout:
              invertZoom: true
            graphs:
              - type: bar
                title: Energy
                options:
                  interval: daily
                entities:
                  - entity: sensor.meter_energy_daily
                    scale: 0.5
                  - entity: sensor.daily_energy_peak
                    scale: 0.5
                  - entity: sensor.daily_energy_midpeak
                    scale: 0.5
                  - entity: sensor.daily_energy_offpeak
                    scale: 0.5
          - type: horizontal-stack
            cards:
              - type: sensor
                entity: sensor.daily_energy_peak
              - type: sensor
                entity: sensor.daily_energy_midpeak
              - type: sensor
                entity: sensor.daily_energy_offpeak
          - type: horizontal-stack
            cards:
              - type: sensor
                entity: sensor.daily_energy_peak_money
              - type: sensor
                entity: sensor.daily_energy_midpeak_money
              - type: sensor
                entity: sensor.daily_energy_offpeak_money
          - type: horizontal-stack
            cards:
              - type: sensor
                entity: sensor.monthly_energy_peak
              - type: sensor
                entity: sensor.monthly_energy_midpeak
              - type: sensor
                entity: sensor.monthly_energy_offpeak
          - type: horizontal-stack
            cards:
              - type: sensor
                entity: sensor.monthly_energy_peak_money
              - type: sensor
                entity: sensor.monthly_energy_midpeak_money
              - type: sensor
                entity: sensor.monthly_energy_offpeak_money
          - type: horizontal-stack
            cards:
              - type: entity
                entity: select.daily_energy
                state_color: false
                name: Current peak
              - hours_to_show: 24
                graph: none
                type: sensor
                entity: sensor.energy_price_current
                detail: 1
          - type: markdown
            content: |-
              peak: (9:00-11:30,14:00-16:30,19:00-21:00)
              midpeak: (7:00-9:00,11:30-14:00,16:30-19:00,21:00-23:00)
              offpeak: (23:00:Tomorrow7:00)


20221209100357

 

Reference

How to use IAMMETER`s energy meter into the home assistant

IAMMETER supports more power tariff templates(fixed, tiered,time of use etc...)

Thread Status
0
1849
1
0
0

Sort replies by:
Looks like you are new here. Register for free, learn and contribute.