Crazy Solar Automation help

Huge ask. I have no idea how to do this

I’m wanting an automation that can do the below.

Based on how much solar I sell back to grid during the day, will determine how much power I can use at night for my Ducted AC as that’s the major power consumption when we go to bed.

Do for Example
Sold 32kWh
Bought: 15kWh
Left over: 17kwh

So when I press my Automation called Going to Bed, it turns on my Ducted AC script for sleeping.

I also have my Ducted AC turning off when Temp reachs 20, and on when above 23, so I would like the automation to factor in that.

So basically the AC can turn and off based on the temp, but when I consumer 17kwh from say 9pm to 6am that the AC can no longer turn on???

I would be happy to pay for this or even have it turned into a blueprint as I can’t see why something like this wouldn’t be usefully.

I figure I’ll need to create a templates to calculate
Left over: 17kwh

Do you have these as entities now?

What are their entity ids?

Hi Tom

I have the below

sensor.energy_real_produced
sensor.power_consumed

The HA energy dashboard does what I need, wish it produced entities :thinking:

So produced - consumed will give you the amount sold.

template:
  - sensor:
      - name: "Energy sold"
        state: "{{ states('sensor.energy_real_produced')|float(0) - states('sensor.power_consumed')|float(0) 
        unit_of_measurement: kWh
        device_class: energy

You could use that a numeric state condition in your automations.

That simple?? I’ll give it ago!

Man I thought this was complicated lol

hey im getting an error

Invalid config for [template]: invalid template (TemplateSyntaxError: unexpected end of template, expected 'end of print statement'.) for dictionary value @ data['sensor'][8]['state']. Got "{{ states('sensor.energy_real_produced')|float(0) - states('sensor.power_consumed')|float(0)". (See /config/configuration.yaml, line 443).

When i go and check the template
its saying

TemplateSyntaxError: unexpected char '"' at 100

what does this mean?

Oops. I didn’t finish my template. Should be:

state: "{{ states('sensor.energy_real_produced')|float(0) - states('sensor.power_consumed')|float(0) }}"

how do i now divided that to get kWh as im getting Wh Total
state: “160903.02”

You don’t. I’m guessing that these are not daily totals but ever increasing numbers instead?

In which case you will have to feed the Energy Sold sensor to a utility meter with a daily cycle.

You are also going to have to add a bit to your sensor:

template:
  - sensor:
      - name: "Energy sold"
        state: "{{ states('sensor.energy_real_produced')|float(0) - states('sensor.power_consumed')|float(0) }}"
        unit_of_measurement: kWh
        device_class: energy
        state_class: total_increasing
        availability: "{{ states('sensor.energy_real_produced')|float(0) != 0 and states('sensor.power_consumed')|float(0) != 0 }}"

Thank you for this so far!

am i on the right thinking with this sort of automation and logic??

I also just realised that when we buy back power it cost mroe than what we sell back!! this is getting to complicated lol

You can add that to the template if you want.

mmm i need to think about this

Though the number im getting does look like it matches the Grid Total on the energy dashboard

What the new sensor is showing
image

The Grid Total is the amount i want, i only just saw this lol

It is in kWh as your sensors are in kWh. It’s just that the value is for all time. Not daily. Read what I wrote. I told you how to fix it.

hey Tom, i have added what you provided, im just checking my utility integration

OK i have followed what you provided, below is my code

Template

      - name: "Energy sold"
        state: "{{ states('sensor.energy_real_produced')|float(0) - states('sensor.power_consumed')|float(0) }}"
        unit_of_measurement: kWh
        device_class: energy
        state_class: total_increasing
        availability: "{{ states('sensor.energy_real_produced')|float(0) != 0 and states('sensor.power_consumed')|float(0) != 0 }}"

Utility Integration

utility_meter:
  energy:
    source: sensor.energy_sold
    cycle: daily
    name: Daily Energy Sold

This is end result.
Daily Energy Sold Sensor Entity
905.29 kWh

This figure is no where near right,

Question: do i need to first create a Daily Utility Sensor for the below entities?

  • sensor.energy_real_produced
  • sensor.power_consumed

Hey To,

Just wanted to say thank you! i dont understand the template you created as coding is somehting i ahvent never done, but i finally got my Grid Total entity :slight_smile: Learnt alot!

My next stage is to try create tariffs based on my electricity contract

I have one more favour
Below is my solar feed it tarriffs. Any idea how to create these?

AGL Retailer Feed-in Tariff for the first 14kWh per day (<14kWh per day)
10 cents/kWh exported
AGL Retailer Feed-in Tariff Thereafter (>14kWh per day)
5 cents/kWh exported

For that calculation, I’d just create an if else template. Check the dev tools and template section for an example. The logic I’m thinking here if the following (psudeo code):

If (solar feed <= 14) then
{{ states(‘sensor.energy_real_produced’)|float(0) * .1) }}
Else
{{ (14 * .1) + ((states(‘sensor.energy_real_produced’)|float(0) - 14) * .05)}}

Keep in mind I haven’t tried this so you may have to fix the syntax. I would also suggest creating numeric helper entities for your tariff values and using those entity IDs in the above logic. This would allow you to adjust the tariff values from the UI

ow wow thank you! ill give it a try, i dont really understand this, but ill give it a crack