Add individual items of two lists

I would like to add past, current and future energy prices with respective grid tariffs. But how can I do it?

Case:
sensor.nordpool_kwh_oslo_nok_3_10_025 (nordpool custom component) contains today’s and tomorrow’s energy prices for each hour of the two days in the attributes (attributes today and tomorrow):

current_price: 4.987
average: 3.887
off peak 1: 2.492
off peak 2: 3.437
peak: 4.679
min: 1.911
max: 5.739
unit: kWh
currency: NOK
country: Norway
region: Oslo
low price: false
tomorrow_valid: true
today:
  - 2.086
  - 1.992
  - 1.951
  - 1.911
  - 2.058
  - 2.221
  - 2.875
  - 4.838
  - 5.338
  - 5.05
  - 4.603
  - 4.186
  - 3.567
  - 4.335
  - 4.987
  - 5.281
  - 5.424
  - 5.672
  - 5.739
  - 5.418
  - 3.303
  - 4.581
  - 3.114
  - 2.751
tomorrow:
  - 2.981
  - 2.663
  - 2.591
  - 2.566
  - 2.83
  - 3.852
  - 3.209
  - 3.433
  - 6.298
  - 6.349
  - 6.223
  - 5.927
  - 5.615
  - 5.68
  - 5.881
  - 6.238
  - 6.674
  - 7.656
  - 7.41
  - 6.421
  - 5.811
  - 4.946
  - 4.027
  - 3.342
raw_today:
  - start: '2021-12-20T00:00:00+01:00'
    end: '2021-12-20T01:00:00+01:00'
    value: 2.086
  - start: '2021-12-20T01:00:00+01:00'
    end: '2021-12-20T02:00:00+01:00'
    value: 1.992
  - start: '2021-12-20T02:00:00+01:00'
    end: '2021-12-20T03:00:00+01:00'
    value: 1.951
  - start: '2021-12-20T03:00:00+01:00'
    end: '2021-12-20T04:00:00+01:00'
    value: 1.911
  - start: '2021-12-20T04:00:00+01:00'
    end: '2021-12-20T05:00:00+01:00'
    value: 2.058
  - start: '2021-12-20T05:00:00+01:00'
    end: '2021-12-20T06:00:00+01:00'
    value: 2.221
  - start: '2021-12-20T06:00:00+01:00'
    end: '2021-12-20T07:00:00+01:00'
    value: 2.875
  - start: '2021-12-20T07:00:00+01:00'
    end: '2021-12-20T08:00:00+01:00'
    value: 4.838
  - start: '2021-12-20T08:00:00+01:00'
    end: '2021-12-20T09:00:00+01:00'
    value: 5.338
  - start: '2021-12-20T09:00:00+01:00'
    end: '2021-12-20T10:00:00+01:00'
    value: 5.05
  - start: '2021-12-20T10:00:00+01:00'
    end: '2021-12-20T11:00:00+01:00'
    value: 4.603
  - start: '2021-12-20T11:00:00+01:00'
    end: '2021-12-20T12:00:00+01:00'
    value: 4.186
  - start: '2021-12-20T12:00:00+01:00'
    end: '2021-12-20T13:00:00+01:00'
    value: 3.567
  - start: '2021-12-20T13:00:00+01:00'
    end: '2021-12-20T14:00:00+01:00'
    value: 4.335
  - start: '2021-12-20T14:00:00+01:00'
    end: '2021-12-20T15:00:00+01:00'
    value: 4.987
  - start: '2021-12-20T15:00:00+01:00'
    end: '2021-12-20T16:00:00+01:00'
    value: 5.281
  - start: '2021-12-20T16:00:00+01:00'
    end: '2021-12-20T17:00:00+01:00'
    value: 5.424
  - start: '2021-12-20T17:00:00+01:00'
    end: '2021-12-20T18:00:00+01:00'
    value: 5.672
  - start: '2021-12-20T18:00:00+01:00'
    end: '2021-12-20T19:00:00+01:00'
    value: 5.739
  - start: '2021-12-20T19:00:00+01:00'
    end: '2021-12-20T20:00:00+01:00'
    value: 5.418
  - start: '2021-12-20T20:00:00+01:00'
    end: '2021-12-20T21:00:00+01:00'
    value: 3.303
  - start: '2021-12-20T21:00:00+01:00'
    end: '2021-12-20T22:00:00+01:00'
    value: 4.581
  - start: '2021-12-20T22:00:00+01:00'
    end: '2021-12-20T23:00:00+01:00'
    value: 3.114
  - start: '2021-12-20T23:00:00+01:00'
    end: '2021-12-21T00:00:00+01:00'
    value: 2.751
raw_tomorrow:
  - start: '2021-12-21T00:00:00+01:00'
    end: '2021-12-21T01:00:00+01:00'
    value: 2.981
  - start: '2021-12-21T01:00:00+01:00'
    end: '2021-12-21T02:00:00+01:00'
    value: 2.663
  - start: '2021-12-21T02:00:00+01:00'
    end: '2021-12-21T03:00:00+01:00'
    value: 2.591
  - start: '2021-12-21T03:00:00+01:00'
    end: '2021-12-21T04:00:00+01:00'
    value: 2.566
  - start: '2021-12-21T04:00:00+01:00'
    end: '2021-12-21T05:00:00+01:00'
    value: 2.83
  - start: '2021-12-21T05:00:00+01:00'
    end: '2021-12-21T06:00:00+01:00'
    value: 3.852
  - start: '2021-12-21T06:00:00+01:00'
    end: '2021-12-21T07:00:00+01:00'
    value: 3.209
  - start: '2021-12-21T07:00:00+01:00'
    end: '2021-12-21T08:00:00+01:00'
    value: 3.433
  - start: '2021-12-21T08:00:00+01:00'
    end: '2021-12-21T09:00:00+01:00'
    value: 6.298
  - start: '2021-12-21T09:00:00+01:00'
    end: '2021-12-21T10:00:00+01:00'
    value: 6.349
  - start: '2021-12-21T10:00:00+01:00'
    end: '2021-12-21T11:00:00+01:00'
    value: 6.223
  - start: '2021-12-21T11:00:00+01:00'
    end: '2021-12-21T12:00:00+01:00'
    value: 5.927
  - start: '2021-12-21T12:00:00+01:00'
    end: '2021-12-21T13:00:00+01:00'
    value: 5.615
  - start: '2021-12-21T13:00:00+01:00'
    end: '2021-12-21T14:00:00+01:00'
    value: 5.68
  - start: '2021-12-21T14:00:00+01:00'
    end: '2021-12-21T15:00:00+01:00'
    value: 5.881
  - start: '2021-12-21T15:00:00+01:00'
    end: '2021-12-21T16:00:00+01:00'
    value: 6.238
  - start: '2021-12-21T16:00:00+01:00'
    end: '2021-12-21T17:00:00+01:00'
    value: 6.674
  - start: '2021-12-21T17:00:00+01:00'
    end: '2021-12-21T18:00:00+01:00'
    value: 7.656
  - start: '2021-12-21T18:00:00+01:00'
    end: '2021-12-21T19:00:00+01:00'
    value: 7.41
  - start: '2021-12-21T19:00:00+01:00'
    end: '2021-12-21T20:00:00+01:00'
    value: 6.421
  - start: '2021-12-21T20:00:00+01:00'
    end: '2021-12-21T21:00:00+01:00'
    value: 5.811
  - start: '2021-12-21T21:00:00+01:00'
    end: '2021-12-21T22:00:00+01:00'
    value: 4.946
  - start: '2021-12-21T22:00:00+01:00'
    end: '2021-12-21T23:00:00+01:00'
    value: 4.027
  - start: '2021-12-21T23:00:00+01:00'
    end: '2021-12-22T00:00:00+01:00'
    value: 3.342
unit_of_measurement: NOK/kWh
icon: mdi:flash
friendly_name: nordpool_kwh_oslo_nok_3_10_025

I have made an Appdaemon app that fetches the grid tariffs from my grid operator’s API and provides a sensor sensor.nettleie_hjemme_oppe_forbruksledd with attributes on the same format as the nordpool sensor (currently, the grid tariff is constant, but it will change to a variable tariff in the near future):

friendly_name: Nettleie hjemme oppe per kWh
unit_of_measurement: NOK/kWh
icon: mdi:currency-usd
level: NORMAL
today:
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
tomorrow:
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
  - 0.448
raw_today:
  - start: '2021-12-20T00:00:00+01:00'
    end: '2021-12-20T01:00:00+01:00'
    value: 0.448
  - start: '2021-12-20T01:00:00+01:00'
    end: '2021-12-20T02:00:00+01:00'
    value: 0.448
  - start: '2021-12-20T02:00:00+01:00'
    end: '2021-12-20T03:00:00+01:00'
    value: 0.448
  - start: '2021-12-20T03:00:00+01:00'
    end: '2021-12-20T04:00:00+01:00'
    value: 0.448
  - start: '2021-12-20T04:00:00+01:00'
    end: '2021-12-20T05:00:00+01:00'
    value: 0.448
  - start: '2021-12-20T05:00:00+01:00'
    end: '2021-12-20T06:00:00+01:00'
    value: 0.448
  - start: '2021-12-20T06:00:00+01:00'
    end: '2021-12-20T07:00:00+01:00'
    value: 0.448
  - start: '2021-12-20T07:00:00+01:00'
    end: '2021-12-20T08:00:00+01:00'
    value: 0.448
  - start: '2021-12-20T08:00:00+01:00'
    end: '2021-12-20T09:00:00+01:00'
    value: 0.448
  - start: '2021-12-20T09:00:00+01:00'
    end: '2021-12-20T10:00:00+01:00'
    value: 0.448
  - start: '2021-12-20T10:00:00+01:00'
    end: '2021-12-20T11:00:00+01:00'
    value: 0.448
  - start: '2021-12-20T11:00:00+01:00'
    end: '2021-12-20T12:00:00+01:00'
    value: 0.448
  - start: '2021-12-20T12:00:00+01:00'
    end: '2021-12-20T13:00:00+01:00'
    value: 0.448
  - start: '2021-12-20T13:00:00+01:00'
    end: '2021-12-20T14:00:00+01:00'
    value: 0.448
  - start: '2021-12-20T14:00:00+01:00'
    end: '2021-12-20T15:00:00+01:00'
    value: 0.448
  - start: '2021-12-20T15:00:00+01:00'
    end: '2021-12-20T16:00:00+01:00'
    value: 0.448
  - start: '2021-12-20T16:00:00+01:00'
    end: '2021-12-20T17:00:00+01:00'
    value: 0.448
  - start: '2021-12-20T17:00:00+01:00'
    end: '2021-12-20T18:00:00+01:00'
    value: 0.448
  - start: '2021-12-20T18:00:00+01:00'
    end: '2021-12-20T19:00:00+01:00'
    value: 0.448
  - start: '2021-12-20T19:00:00+01:00'
    end: '2021-12-20T20:00:00+01:00'
    value: 0.448
  - start: '2021-12-20T20:00:00+01:00'
    end: '2021-12-20T21:00:00+01:00'
    value: 0.448
  - start: '2021-12-20T21:00:00+01:00'
    end: '2021-12-20T22:00:00+01:00'
    value: 0.448
  - start: '2021-12-20T22:00:00+01:00'
    end: '2021-12-20T23:00:00+01:00'
    value: 0.448
  - start: '2021-12-20T23:00:00+01:00'
    end: '2021-12-21T00:00:00+01:00'
    value: 0.448
raw_tomorrow:
  - start: '2021-12-21T00:00:00+01:00'
    end: '2021-12-21T01:00:00+01:00'
    value: 0.448
  - start: '2021-12-21T01:00:00+01:00'
    end: '2021-12-21T02:00:00+01:00'
    value: 0.448
  - start: '2021-12-21T02:00:00+01:00'
    end: '2021-12-21T03:00:00+01:00'
    value: 0.448
  - start: '2021-12-21T03:00:00+01:00'
    end: '2021-12-21T04:00:00+01:00'
    value: 0.448
  - start: '2021-12-21T04:00:00+01:00'
    end: '2021-12-21T05:00:00+01:00'
    value: 0.448
  - start: '2021-12-21T05:00:00+01:00'
    end: '2021-12-21T06:00:00+01:00'
    value: 0.448
  - start: '2021-12-21T06:00:00+01:00'
    end: '2021-12-21T07:00:00+01:00'
    value: 0.448
  - start: '2021-12-21T07:00:00+01:00'
    end: '2021-12-21T08:00:00+01:00'
    value: 0.448
  - start: '2021-12-21T08:00:00+01:00'
    end: '2021-12-21T09:00:00+01:00'
    value: 0.448
  - start: '2021-12-21T09:00:00+01:00'
    end: '2021-12-21T10:00:00+01:00'
    value: 0.448
  - start: '2021-12-21T10:00:00+01:00'
    end: '2021-12-21T11:00:00+01:00'
    value: 0.448
  - start: '2021-12-21T11:00:00+01:00'
    end: '2021-12-21T12:00:00+01:00'
    value: 0.448
  - start: '2021-12-21T12:00:00+01:00'
    end: '2021-12-21T13:00:00+01:00'
    value: 0.448
  - start: '2021-12-21T13:00:00+01:00'
    end: '2021-12-21T14:00:00+01:00'
    value: 0.448
  - start: '2021-12-21T14:00:00+01:00'
    end: '2021-12-21T15:00:00+01:00'
    value: 0.448
  - start: '2021-12-21T15:00:00+01:00'
    end: '2021-12-21T16:00:00+01:00'
    value: 0.448
  - start: '2021-12-21T16:00:00+01:00'
    end: '2021-12-21T17:00:00+01:00'
    value: 0.448
  - start: '2021-12-21T17:00:00+01:00'
    end: '2021-12-21T18:00:00+01:00'
    value: 0.448
  - start: '2021-12-21T18:00:00+01:00'
    end: '2021-12-21T19:00:00+01:00'
    value: 0.448
  - start: '2021-12-21T19:00:00+01:00'
    end: '2021-12-21T20:00:00+01:00'
    value: 0.448
  - start: '2021-12-21T20:00:00+01:00'
    end: '2021-12-21T21:00:00+01:00'
    value: 0.448
  - start: '2021-12-21T21:00:00+01:00'
    end: '2021-12-21T22:00:00+01:00'
    value: 0.448
  - start: '2021-12-21T22:00:00+01:00'
    end: '2021-12-21T23:00:00+01:00'
    value: 0.448
  - start: '2021-12-21T23:00:00+01:00'
    end: '2021-12-22T00:00:00+01:00'
    value: 0.448

I would like to calculate (as new lists as attributes to a new sensor) the today and tomorrow lists that would contain the prices I actually have to pay (energy price + grid tariff). How do I add one item from one sensor to the same respective item from the other sensor and output it as new lists as attributes to a new sensor? Can’t figure it out…

I could, of course, make another Appdaemon app for summing the two, but is there an (easy) template way?

Oh, and to make it even more interesting, the nordpool (energy price) tomorrow list is empty until about 1 pm (13:00) at which time tomorrow’s energy price is set.

Is this truly a Feature Request? Because it sounds like a question that belongs in the Configuration category.

Copy-paste this into the Template Editor and experiment with it. It adds the individual elements of two equal-length lists and puts the results in a new list.

{% set x = [12, 8, 3] %}
{% set y = [8, 12, 17] %}

{% set ns = namespace(z=[]) %}
{% for i in x %}
  {% set ns.z = ns.z + [i + y[loop.index-1]] %}
{% endfor %}
{{ ns.z }}

No, it’s not a Feature request, it was meant to go in the Configuration category and I don’t know how I managed to get it in the feature request category. My apologies! Can it be moved by a moderator?

Thanks for the template tip. I will test it.

Try editing your first post and changing its category to Configuration. If it doesn’t allow you to do that, send a private message to one of the moderators.

Ah, it seems I could move it myself. Learn something every day… Thanks for pointing out that I had posted in the wrong category, I hadn’t noticed that myself. :roll_eyes:

Thanks, your tip works well. With the following modification to get the lists from the attributes, it works perfectly :smiley:

{% set x = state_attr('sensor.nordpool_kwh_oslo_nok_3_10_025','today') %}
{% set y = state_attr('sensor.nettleie_hjemme_oppe_forbruksledd','today') %}
1 Like