Using Home Assistant to calculate my energy bill using data from my Solar Inverter

power bill guide. Already added solcast solar forecast (although it is not being maintained right now)

Hi @yousaf465, I was not aware this was possible. What is your source for this information?


Integration - Riemann sum integral - Home Assistant
I was talking about helpers e.g Riemann sum integral and Utility Meter - Home Assistant

Ah right, I see.
I have learned something new today.

I may update this in the future to include GUI instructions, but am also hesitant as my setup is working just the way I like it at the moment.

The thought of spending the time with the possibility of breaking my already perfect working setup just to update a guide is a bit daunting.

Was there anything with in particular that was hardest for newbies?

for e.g if my peak cost is Pkr 16 is this how I should setup my sensor

 - sensor:
      - name: Tariff Price
        unit_of_measurement: Pkr/kWh
        state: >
            {{ 16}}
  - sensor:
      - name: Energy Cost
        device_class: monetary
        state_class: measurement
        unit_of_measurement: Pkr
        state: >
          {{ (states('sensor.daily_energy_Peak') | float * 16 | round(2) }}  

Hi @del13r,
Thanks for sharing your cool and elaborate dashboard. I am inspired by it.

I am with Ausgrid and their rates are based on ‘working’ weekdays. So public holidays on Mon-Fri are shoulder during what would otherwise be peak. So the code I have used for a template sensor to get applicable rates are as below.

{#
Australian Ausgrid NSW Peak-shoulder-offpeak sensor defined
Peak rates:
From 2pm to 8 pm on working weekdays during 1 November and 31 March;
From 5pm to 9pm on working weekdays during 1 June to 31 August
Off-peak:
10pm to 7am
sholder: all other times 
#}
{% set output = 'shoulder'%}
{% if ((now().month <= 3 or now().month >=11) 
       and (14 <= now().hour <= 19)) or 
      ((6 <= now().month <= 8 ) 
       and (17 <= now().hour <= 20)) and (now().weekday()<6) %}
    {%set output = 'peak'%}
{%else %}
  {%if now().hour>= 22 or now().hour < 7 %}
    {% set output = 'offpeak' %}
  {%endif %}
{%endif %}
{#if public holiday when peak does not apply #}
{# define public holidays falling on weekdays as a list of lists ['yyyy','mm','dd']#}
{% set holidays = 
  [['2022','06','13'],['2022','10','03'],['2022','12','26'],['2022','12','27'],
   ['2023','01','02'],['2023','01','26'],['2023','04','07'],['2023','04','10'],
   ['2023','04','25'],['2023','06','12'],['2023','10','02'],['2023','12','25'],
   ['2023','12','26']]%}

{% set today_list = (now()|string)[0:10].split('-') %}
{# of peak rate time but public holiday, then shoulder rates apply #}
{% if output == 'peak' and today_list in holidays %}
  {% set output = 'shoulder' %}
{%endif%}
{{output}}
1 Like

Please correct me if I’m wrong here but don’t these automations to change the tariff only occur if home assistant is active at the time of the automation. I noticed this as we had a (rare) power outage that covered the transition from peak > shoulder, and the tariff didn’t change.

Is there a way to set the automation to trigger during a time window, instead of at the start of the time period?

Hi,

Right off the top of my head, I’m thinking that maybe a solution involving an if statement might be able to help in that case.

This link seems to be on the right track

I’ll be giving it some thought and research, however I’m still really only learning the basics of yaml syntax and homeassistant. This is currently week 1!

1 Like

Do you think we could use this feature in the helper UI?

In the meantime I’ll get my head around the post you just linked.

The TOD integration would only help if every day was the same. Where it becomes less desirable is when you have different times for summer/winter peak. The if statement appears to be the best solution albeit I have not used it myself yet

that makes sense. I’ll include something along the lines of that if statement.

Just going through your code for my own uses (thanks!) - maybe I’m wrong here but it looks like you’re trying to test if it is Mon - Fri (where 0 = Mon and 6 = Sunday). This statement would be true for Saturday as well. Thought I’d point that out in case it’s still in your code (or I’m missing something).

I changed the if statement to be much simpler for my tariff at the moment (no seasonal conditions yet)

{% set output = 'shoulder'%}
{% if (17 <= now().hour <= 19) and (now().weekday()<5) %}
    {%set output = 'peak'%}    
{%else %}  
  {%if (now().hour>= 22 or now().hour < 7) or (now().weekday()>=5)%}
    {% set output = 'offpeak' %}
  {%endif %}
{%endif %}
{{output}}

I know I need to use this template to update the value of utility_meter.daily_energy however that’s where I’ve hit a wall. The automations I have just change the tariff under separate conditions. Any hints?

Hi @alexeiw123,
Yes, you are right. I noticed that recently and fixed my code. ‘0’ is Monday, not Sunday as i had thought before.

1 Like

The quick and lazy way would be to have just 1 tariff in utility meter and then use the if statement logic to continually evaluate and update the price of the tariff price template sensor depending on time of day. Sorry, on mobile. Will do better reply when I get time

Well, with my basic HA skills, I gave up on changing the state of select.daily_energy using the template above. Even though this seems like a basic task, I couldn’t find a neat way.

I did find that automations can be triggered at time intervals and also have before and after conditions, so I created a bunch of automations which seems to be working and will update a tariff if it is wrong for at least 30 seconds. It’s a lot more lines of code but it works.

- id: '1655331243871'
  alias: Tariff Select Peak
  description: Change tariff during peak times
  trigger:
  - platform: time_pattern
    minutes: '*'
    hours: '*'
    seconds: /30
  - platform: time
    at: '17:00:01'
  condition:
  - condition: template
    value_template: '{{(17 <= now().hour <= 19) and (now().weekday()<5)}}'
  action:
  - service: utility_meter.select_tariff
    data:
      tariff: peak
    target:
      entity_id: utility_meter.daily_energy
  mode: single
- id: '1655331713299'
  alias: Tariff Select Shoulder
  description: Change tariff during shoulder times
  trigger:
  - platform: time_pattern
    minutes: '*'
    hours: '*'
    seconds: /30
  - platform: time
    at: 07:00:01
  - platform: time
    at: '20:00:01'
  condition:
  - condition: template
    value_template: '{{(now().hour >= 7 and now().hour < 17) or (now().hour >= 20
      and now().hour < 22) and (now().weekday() <5)}}'
  action:
  - service: utility_meter.select_tariff
    data:
      tariff: shoulder
    target:
      entity_id: utility_meter.daily_energy
  mode: single
- id: '1655333102052'
  alias: Tariff Select Offpeak
  description: Change tariff during off peak times
  trigger:
  - platform: time_pattern
    minutes: '*'
    hours: '*'
    seconds: /30
  - platform: time
    at: '22:00:01'
  - platform: time
    at: 00:00:01
  condition:
  - condition: template
    value_template: '{{(now().hour >= 22 or now().hour < 7) or (now().weekday() >=5)}}'
  action:
  - service: utility_meter.select_tariff
    data:
      tariff: offpeak
    target:
      entity_id: utility_meter.daily_energy
  mode: single

edit:

It also looks like you can set month conditions e.g.

- condition: template
  value_template: '{{ now().month >= 10 or now().month <= 4 }}'

edit 2: single automations per tariff using template

yep, you will find there are ‘many ways to skin a cat’ with home assistant.
My solution is vulnerable to home assistant outage at tariff changeover.

1 Like

Absolutely. I’m sure there’s a tidier or more efficient way but I think this will work. I’ll watch the tariff history over the next week to confirm.

I updated the code block above as I realised I could use the template to avoid having multiple automations for tariffs with multiple windows.

This would be quite simple to include logic for months, I’m just not sure if having an automation trigger every 30 seconds should be avoided for any reason.

I would exclude the history of that automation in the recorder so it doesnt fill up the database

1 Like