I’m trying to make some sensors for returning the current electricity rates. I’ve read a bunch of posts on here and tried to form them into something that I think should be correct. I’ve added the following to configuration.yaml
and reloaded and I don’t get any of these entities showing up however, even in the states page. I haven’t configured anything else through the YAML before so forgive my ignorance here.
This is all that I’m placing in the configuration.yaml
file at the root level.
utility_meter:
daily_energy:
name: Daily Energy
source: sensor.home_grid_imported
cycle: daily
tariffs:
- summer_on-peak
- summer_off-peak
- summer_discount
- winter_on-peak
- winter_off-peak
- winter_discount
binary_sensor:
- platform: workday
country: US
workdays: [mon, tue, wed, thu, fri]
excludes: [sat, sun, holiday]
template:
- trigger:
- platform: time_pattern
minutes: 0
# update every hour on the hour
sensor:
- name: "Electricity Rate"
state: >-
{% set summer_months = [5,6,7,8,9] %}
{% set month = now().month %}
{% set hour = now().hour %}
{%- if month in summer_months -%}
{%- if hour >= 1 and hour <= 6 -%}
summer_discount
{%- else -%}
{%- if is_state('binary_sensor.workday_sensor', 'on') and (hour >= 18 and hour <= 21) -%}
summer_on-peak
{%- else -%}
summer_off-peak
{%- endif -%}
{%- endif -%}
{%- else -%}
{%- if (hour >= 1 and hour <= 3) or (hour >= 11 and hour <= 16) -%}
winter_discount
{%- else -%}
{%- if is_state('binary_sensor.workday_sensor', 'on') and (hour >= 6 and hour <= 9) -%}
winter_on-peak
{%- else -%}
winter_off-peak
{%- endif -%}
{%- endif -%}
{%- endif -%}
unique_id: electricity_rate
- name: "Current Electricity Rate Cost"
state: >-
{% set rate = states('sensor.electricity_rate') %}
{%- if rate == 'summer_on-peak' -%}0.28821
{%- elif rate == 'summer_off-peak' -%}0.10911
{%- elif rate == 'summer_discount' -%}0.07105
{%- elif rate == 'winter_on-peak' -%}0.28821
{%- elif rate == 'winter_off-peak' -%}0.10911
{%- else -%}0.07105
{%- endif -%}
unit_of_measurement: $/kWh
unique_id: electricity_rate_cost