#so with your amazing dashboard some of

1 messages · Page 1 of 1 (latest)

hexed elm
#

Just a sec, in standup

minor osprey
#

no prob

#

no rush - i should be working and not staring at this stuff 🙂

hexed elm
#

The big flow diagram is from card called Sankey. You need to build yaml to say what flows into what.

#

The daily charge is just an input-number

#

And I have some utility meters to calculate today cost (per the tldr)

#

Plus a bunch of template sensors to add things up, etc sec will paste

minor osprey
#

ok, let me have a look through that. I think I understand this stuff a lot more now. just have to get my head around how to put it together

#

thanks!

hexed elm
#

nw

minor osprey
#

Hmm - so my sensor that determines state seems to work, but my automation is not doing the triggering properly

#

so the energy meter state is not changing.

#
  • id: '1691571544169'
    alias: Automate Tariff Selection
    description: ''
    trigger:

    • platform: state
      entity_id:
      • sensor.electricity_import_tariff
        condition: []
        action:
    • service: select.select_option
      data:
      option: "{{ trigger.to_state.state if 'to_state' in trigger else 'offpeak'}}"
      mode: single
      target:
      entity_id: select.daily_grid_energy
      mode: single
  • name: "Electricity Import Tariff"
    unique_id: 541d7af3-7518-42b4-ad78-7fba858c7770
    state: "{{ 'shoulder' if today_at('10:00') < now() < today_at('15:00') else ('offpeak' if today_at('01:00') < now() < today_at('06:00') else 'peak') }}"

#

so the sensor.electricity_import_tarriff is correctly setting state, but that's not flowing through to the energy meter

#

so I see:

hexed elm
#

Did you create the automation in the UI or in an editor?

minor osprey
#

UI - but went back and tried to fix manually to match your stuff.

Issue seems to be elsewhere:

Invalid config for [template]: [unit_of_measure] is an invalid option for [template]. Check: template->sensor->6->unit_of_measure. (See /config/configuration.yaml, line 17).
11:00:19 AM – (ERROR) config.py - message first occurred at 10:58:21 AM and shows up 2 times

#

something I have changed elsewhere has a fall down though the whole config

hexed elm
#

You need to set the energy-meter tariff explicitly. If you're getting an error that won't be happenening.

#

what's around line 17 of your configuration.yaml

minor osprey
hexed elm
#

there's decent debugging in the automation traces. list of all the state, triggers, variables changed etc

minor osprey
#

at the moment the issue is the tarriff sensor is broken

hexed elm
#

you restarted HA after changing yaml I assume?

minor osprey
#

yeah

#

I did remove some stuff before - removed the washing machine thing as well.

#

gimme a tick, maybe reverse something else

hexed elm
#

It doesn't like the gco2 as a unit of mesure

#

comment out that sensor for now

minor osprey
#

yeah

#

just figured that

hexed elm
#

I'm guessing "sensor->6" is the 7th (starting from 0). And I haven't seen that unit before

minor osprey
#

yeah

#

ok - this is why I am not a developer - I hate compilers

hexed elm
#

I'm not (really) a developer anymore. But I used to, and still have to sometimes.

minor osprey
#

yeah - I did CS about 30 years ago, but went into Network Engineering so very low coding. Now I'm a commerical guy who occasionally pokes the engineers

#

so a lot of this is just "recalling how to debug"

#

I'm starting to get a handle on how HA "works"

#

thanks for your help

hexed elm
#

yeah, I did CS... yeah, 30 years ago, and was a programmer for a while; but now I'm cloud/devops, so still in the ballpark

#

these templates are just Jinja with some HA extensions.

#

python is my go-to now for little things, so that kind of thing is OK. writing integrations etc is still too hard though.

#

so with gco2 commented out, is the automation working?

minor osprey
#

yeah - and I've fixed the GCO2 thing by removing the units.

#

My kids are better at python than me now - eldest (17yo) is keen to do cybersecurity stuff - so already doing CTFs etc. It's the family business (my Dad was IT, Uncle, cousin etc).

#

thanks for your help - only thing I need to check is that at 3pm my time the automation triggers the rate change

hexed elm
#

You can fire it manually. And test the code in a loop. So it should pretty-likely work.

minor osprey
#

ok

minor osprey
#

trying to figure out how to roughly calculate CO2g from imported power. (If this is beyond what you want to help with just let me know)

Did the dumb thing of multiplying current figure of CO2g/kwh by total kwh but of course this doesn't work. I need to, for each time period, get the CO2 number, multiply it by the units used in that time period and keep those added for the day.

Where would I start with this? I guess - let's assume I do this each hour, where/how would I grab the last hours usage figure?

Does it make sense to use statistics and do soemthing like this for each usage from the grid

sensor:

  • platform: statistics
    name: “Power Usage Last Hour Shoulder”
    entity_id: sensor.daily_grid_energy_shoulder
    state_characteristic: sum
    max_age:
    hours: 1

then everyhour add that to another sensor?

#

then multiply by the CO2 number each hour?

hexed elm
#

Doesn't your energy dashboard have that already? And integration makes it ... just happen?

#

using co2signal service

#

Sensors
CO2 intensity 464 gCO2eq/kWh
Grid fossil fuel percentage 55.18%

#

I assume a statistic is generated from it

minor osprey
#

yep - got those but they're the grid, but I'm trying to add up how many actual grams I'm responsible for.

hexed elm
#

isn't the grid your import?

minor osprey
#

grid is the grid in general not specifically mine and it changes by hour

#

not across the day

hexed elm
#

The % is from the state level, which is per kWh

minor osprey
#

yes

hexed elm
#

don't you integrate that vs your grid consumption

minor osprey
#

yeah - effectively what I'm trying to do

hexed elm
#

i'm sure that's happening aleady, isn't it?

minor osprey
#

it's not

#

that I can see - ie. I can't see a sensor that shows "over this day you made X grams of CO2"

#

(effectively)

#

at least I can't see a sensor like that

#

I did look as I kind of thought what you're thinking - surely this has been done

hexed elm
#

it's not a sensor, it's statistics

#

ie output from sensor integration

minor osprey
#

ok

hexed elm
#

sec in meeting

minor osprey
#

np

#

what I want is to do something slightly evil which is to mis-use an energy meter to multiple the CO2 figure by the WH figure. This is exactly what it does

hexed elm
#

I think it's an integration of import W vs co2 rate. Same as $ vs W to make cost.

minor osprey
#

yep

#

what is the thing I am looking for to do that? (tell me what the function/helper/etc is)

#

and I'll try and figure it out

hexed elm
#

reinhmann sum

minor osprey
#

so make a sensor that multiplies gCO2/wh with the usage in Watts and then reimann integrate it? (I should know this, but honestly, I can't remember any maths)

hexed elm
#

Shouldn't need to know any maths. It should already exist. Sec.

#

This makes my brain hurt (it's been a looong time since calculus), but:

  • sensor from integration is in blah/kWh (looks like it (usually) updates every hour)
  • maybe you need to multiply that by some kWh consumption, then divide by the fraction of an hour that you used. (little rectangles of area)
  • I don't know how to do it
minor osprey
#

ok, thanks - yeah - so that's where I got to. (I have, theoretically, a maths degree and I look across to my applied maths text books and realise it's ALL GONE).

I've done some searches and I'm not the only one to ask this question but also no one seems to have an obvious answer.

#

anyway, really appreciate your help on all this - it appears to be working and at worse in 12mins I'll find my automation to flick the tariff hasn't worked.

hexed elm
#

nw

#

I expect you'll get multi-tariff exports too, sooner or later

minor osprey
#

yeah - so I was on that plan, but I managed to get on the Origin EV plan the announced which is flat export, but, get this, $0/kwh between 10am and 3pm

#

so right now I'm just enjoying Origin's insanity

#

I make my house battery charge to full as quickly as possible then run the aircon flat out to heat the house etc

#

I was using 20kW the other day

#

All good:

hexed elm
minor osprey
#

Again, feel free to tell me to bugger off and figure it out, but I'm still on the CO2 thing.

I think I've hit on an answer but it doesn't work:

sensor:
    - platform: filter
      name: "grid import 5minago"
      entity_id: sensor.energy_real_consumed_fronius_meter_0_fronius_lan
      filters:
        - filter: time_throttle
          window_size: "00:05"
          precision: 3

template:
  - trigger:
      - platform: time_pattern
        minutes: "/5"
    sensor:
      - name: "grid import co2"
        state: "{{ (states('sensor.grid_import_co2')|float + ((states('sensor.energy_real_consumed_fronius_meter_0_fronius_lan')|float - states('sensor.grid_import_5minago')|float)/1000)*(states('electricity_maps_co2_intensity')|float))|float(0.0) }}"
        unit_of_measurement: "gCO2"

I note that the CO2 of the grid can't update more than 5mins at time as that's the NEM dispatch interval

So, I use filter to give me the 5min ago number of kwh imported, then in the 5minute triggered template basically calculate diff and add to the co2 number.

However, (1) the filter doesn't seem to show when I look at developer statisics, (2) the template doesn't seem to update - dev state stats says "unavailable".

I suspect if the filter isn't working then the trigger sensor won't, but I've got no errors and I'm a little unclear how to debug.

How would you approach the debugging?

minor osprey
#

ok, so trying to use the template tool and sensor.grid_import_5minago doesn't exist which is obviously not good.

#

oh I see the problem - I used filter wrong. man this stuff is annoying. I'd have thought so many of these would have been sorted.

#

hmm

hexed elm
#

a sensor isn't the same thing as statistics. I don't know filters sorry

#

if you make a template sensor that depends on another sensor, I think it will only run/update when that other sensor changes. maybe you can multiply time-delta (between updates) by the fraction of co2blah/kWh used. But I don't know how to save/use time-delta etc

minor osprey
#

yeha - filters aren't the right way.

#

I've been mucking with it between meetings - I think I've nailed it but had so many typos and errors.

#

I also discovered that sensor.energy_real_consumed_fronius_meter_0_fronius_lan doesn't change of course if you're not drawing from the grid.

#

I have to think about a few things to make the order of operations work

#
automation:

- id: '1691721512948'
  alias: Fronius Grid Usage Update
  description: ''
  trigger:
  - platform: time_pattern
    minutes: /5
  condition: []
  action:
  - service: input_number.set_value
    data:
      value: "{{ states('input_number.fronius_grid_now') }}"
    target:
      entity_id: input_number.fronius_grid_5mins_ago
  - service: input_number.set_value
    data: 
      value: "{{ states('sensor.energy_real_consumed_fronius_meter_0_fronius_lan')}}"
    target:
      entity_id: input_number.fronius_grid_now
  mode: single

Sensor:

 - trigger:
      - platform: state
        entity_id:
        - input_number.fronius_grid_now
    sensor:
      - name: "grid import co2"
        state: >
               {% set kWhConsumed = (states('input_number.fronius_grid_now')|float(0.0) - states('input_number.fronius_grid_5mins_ago')|float(0.0))/1000 %}
               {% set gramsCO2 = kWhConsumed * states('sensor.electricity_maps_co2_intensity')|float(0.0) %}
               {% set currentCO2 = states('sensor.grid_import_co2')|float(0.0) %}
               {{ currentCO2 + gramsCO2 }}
#

I haven't fully checked it works yet - but I think this is the go

#

needs a little clean up for initial conditions

#

I thought I had some issue with the trigger thing, but turns out the fronius wasn't changing the Wh sensor as I wasn't drawing from the grid

#

so no triggers happening

#

duh.

#

it relies on the assumption that with the automation above the first action happens BEFORE the second one

#
  - trigger:
      - platform: state
        entity_id:
        - input_number.fronius_grid_now
    sensor:
      - name: "grid import co2"
        state: >
               {% set froniusnow = states('input_number.fronius_grid_now')|float(0.0) %}
               {% set fronius5ago = states('input_number.fronius_grid_5mins_ago')|float(0.0) %}
               {% set kwhconsumed = (froniusnow - fronius5ago)/1000 %}
               {% if fronius5ago < 2.0 %}
               {% set kwhconsumed = 0 %}
               {% endif %}
               {% set gramsCO2 = kwhconsumed * states('sensor.electricity_maps_co2_intensity')|float(0.0) %}
               {% set currentCO2 = states('sensor.grid_import_co2')|float(0.0) %}
               {{ (currentCO2 + gramsCO2) | round(2) }}
#

basically this should deal with initial conditions of the input_numbers being 0

hexed elm
#

Are you sure you’re not a coder? 🙂

minor osprey
#

not professionally.

#

I'll leave it run for a bit - then need to expand out a bit to capture things like savings of co2 by having solar/battery etc

minor osprey
#

I'll tell you what - debugging this is hard. Have just spent an hour discovered I mistyped an input_number and called it a how instead of a now

hexed elm
#

Just need to find, and understand, the error messsges 😉

minor osprey
#

yeah I know - normally I'd shove printf statements in to try and understand the code better.