dala318 / nordpool_planner

nordpool_planner custom component for Home Assistant
MIT License
18 stars 4 forks source link

outcome not in line with expectations (1 hour off) #12

Open ronaldt80 opened 1 year ago

ronaldt80 commented 1 year ago

Hi, I have been playing around with the tool for a few days and found that the outcome is not optimal, eg. in this case one hour off; what's the best way to debug?

I want the start time for the cheapest 4 hour period in a max 24 hour time horizon (rolling) - based on the nordpool sensor my binary planning sensor generates 19:00 with an average cost of 41cents [calculation is correct adding up 19 - 23pm / 4]; however, starting one hour later (20:00) would generate a lower average of 35cents. Any thoughts what I am doing wrong?

YAML code:

 binary_sensor:   
 -  platform: nordpool_planner
    nordpool_entity: sensor.nordpool_kwh_nl_eur_3_10_009
    entity_id: optimal_start_time_dishwasher
    duration: 4
    moving:
      search_length: 24

Used nordpool data:

  - start: '2022-11-29T19:00:00+01:00'
    end: '2022-11-29T20:00:00+01:00'
    value: 0.506
  - start: '2022-11-29T20:00:00+01:00'
    end: '2022-11-29T21:00:00+01:00'
    value: 0.436
  - start: '2022-11-29T21:00:00+01:00'
    end: '2022-11-29T22:00:00+01:00'
    value: 0.365
  - start: '2022-11-29T22:00:00+01:00'
    end: '2022-11-29T23:00:00+01:00'
    value: 0.324
  - start: '2022-11-29T23:00:00+01:00'
    end: '2022-11-30T00:00:00+01:00'
    value: 0.278
dala318 commented 1 year ago

It does not seem you are doing anything wrong, but the plug-in is doing something wrong.

dala318 commented 1 year ago

The only way I know of to debug is to run it in the HASS development environment. Once you find the guide it's quite easy to follow and setup, and integrates well with VS Code.

rolis1122 commented 1 year ago

Hi. Found your custom HACS integration and found it very cool. Thanks for your job! :) As mentioned before - seems that best period found by sensor is off by 1 hour as commmented in 1st post. I'm not good at programming at all, but hope You will find time to look at code any time soon :)

dala318 commented 1 year ago

After fixing #13 in #14 I also found a spot in prices to try to reproduce this issue but seem to function as expected, could be that #14 fixed this one as well. Please update to v.0.2.3 and see if you agree.

binary_sensor:
  - platform: nordpool_planner
    entity_id: moving_1
    nordpool_entity: sensor.nordpool_kwh_se3_sek_3_10_025
    duration: 3
    moving:
      search_length: 6

Ignore noise in binary sensor history graph before 13:30 as that was during my testing of other prameters image

Danny-DFx commented 8 months ago

Hi. I play around with the planner the last days, because I want to charge my Luna Battery automaticly, when the prices are at the lowest at that day. I used the planner, and I had the same issue like @ronaldt80 reported it. But at my setup, with a 3 hour off, today or better tomorrow night is the lowest price at 3, but the planner activate at 0.

image

Nordpool Data:

- start: '2023-12-28T22:00:00+01:00'
end: '2023-12-28T23:00:00+01:00'
value: 1.772
- start: '2023-12-28T23:00:00+01:00'
end: '2023-12-29T00:00:00+01:00'
value: 0.1
Raw tomorrow
- start: '2023-12-29T00:00:00+01:00'
end: '2023-12-29T01:00:00+01:00'
value: 0
- start: '2023-12-29T01:00:00+01:00'
end: '2023-12-29T02:00:00+01:00'
value: -0.008
- start: '2023-12-29T02:00:00+01:00'
end: '2023-12-29T03:00:00+01:00'
value: -0.028
- start: '2023-12-29T03:00:00+01:00'
end: '2023-12-29T04:00:00+01:00'
value: -0.093
- start: '2023-12-29T04:00:00+01:00'
end: '2023-12-29T05:00:00+01:00'
value: -0.095
- start: '2023-12-29T05:00:00+01:00'
end: '2023-12-29T06:00:00+01:00'
value: -0.026

My binary sensor:

binary_sensor:
  - platform: nordpool_planner
    nordpool_entity: sensor.nordpool_kwh_de_lu_eur_4_10_0
    entity_id: Planner
    duration: 2

    moving:
      search_length: 24

My expectation is, the binary sensor activate at 3am and ends at 5am. What I'm doing wrong? (I'm relative new to HA and all these things, but I can't solve this at the moment, cause I didn't know what to look after... ;-) What do you need for files, maybe this is a bug? I would like to send you debug files, but I struggle to get them at the moment... Sorry.

Maybe you have an idea how to solve it? Thanks in advance.

Kind regards. Daniel

Danny-DFx commented 8 months ago

Good morning. An addition to the problem. The binary sensor activated at 1am last night when the price was below 0 cent, until 8am this morning when the price was above 0 cent. This suggests that the problem could be with prices below 0 cent. Please find attached my Nordpool prices and the status of the sensor last night.

I would be pleased to receive a reply. Thank you very much.

Best regards Daniel

today: 0, -0.008, -0.028, -0.093, -0.095, -0.026, -0.007, -0.001, 0.444, 0.109, 0.005, -0.001, 0.06, 0.099, 0.223, 0.999, 1.002, 2.512, 2.659, 1.717, 1.01, 0.504, 2.29, 1.889
tomorrow: 
tomorrow_valid: false
raw_today: 
- start: '2023-12-29T00:00:00+01:00'
  end: '2023-12-29T01:00:00+01:00'
  value: 0
- start: '2023-12-29T01:00:00+01:00'
  end: '2023-12-29T02:00:00+01:00'
  value: -0.008
- start: '2023-12-29T02:00:00+01:00'
  end: '2023-12-29T03:00:00+01:00'
  value: -0.028
- start: '2023-12-29T03:00:00+01:00'
  end: '2023-12-29T04:00:00+01:00'
  value: -0.093
- start: '2023-12-29T04:00:00+01:00'
  end: '2023-12-29T05:00:00+01:00'
  value: -0.095
- start: '2023-12-29T05:00:00+01:00'
  end: '2023-12-29T06:00:00+01:00'
  value: -0.026
- start: '2023-12-29T06:00:00+01:00'
  end: '2023-12-29T07:00:00+01:00'
  value: -0.007
- start: '2023-12-29T07:00:00+01:00'
  end: '2023-12-29T08:00:00+01:00'
  value: -0.001
- start: '2023-12-29T08:00:00+01:00'
  end: '2023-12-29T09:00:00+01:00'
  value: 0.444
- start: '2023-12-29T09:00:00+01:00'
  end: '2023-12-29T10:00:00+01:00'
  value: 0.109
- start: '2023-12-29T10:00:00+01:00'
  end: '2023-12-29T11:00:00+01:00'
  value: 0.005
- start: '2023-12-29T11:00:00+01:00'
  end: '2023-12-29T12:00:00+01:00'
  value: -0.001
- start: '2023-12-29T12:00:00+01:00'
  end: '2023-12-29T13:00:00+01:00'
  value: 0.06
- start: '2023-12-29T13:00:00+01:00'
  end: '2023-12-29T14:00:00+01:00'
  value: 0.099
- start: '2023-12-29T14:00:00+01:00'
  end: '2023-12-29T15:00:00+01:00'
  value: 0.223
- start: '2023-12-29T15:00:00+01:00'
  end: '2023-12-29T16:00:00+01:00'
  value: 0.999
- start: '2023-12-29T16:00:00+01:00'
  end: '2023-12-29T17:00:00+01:00'
  value: 1.002
- start: '2023-12-29T17:00:00+01:00'
  end: '2023-12-29T18:00:00+01:00'
  value: 2.512
- start: '2023-12-29T18:00:00+01:00'
  end: '2023-12-29T19:00:00+01:00'
  value: 2.659
- start: '2023-12-29T19:00:00+01:00'
  end: '2023-12-29T20:00:00+01:00'
  value: 1.717
- start: '2023-12-29T20:00:00+01:00'
  end: '2023-12-29T21:00:00+01:00'
  value: 1.01
- start: '2023-12-29T21:00:00+01:00'
  end: '2023-12-29T22:00:00+01:00'
  value: 0.504
- start: '2023-12-29T22:00:00+01:00'
  end: '2023-12-29T23:00:00+01:00'
  value: 2.29
- start: '2023-12-29T23:00:00+01:00'
  end: '2023-12-30T00:00:00+01:00'
  value: 1.889
starts_at: 2023-12-29 10:00
cost_at: 0.002
now_cost_rate: 222
icon: mdi:flash
friendly_name: nordpool_planner_Planner

image

Danny-DFx commented 8 months ago

Good morning. So, today is another day while the planner switch to on and it is not the cheapest time of the day, later it was "cheaper", but another issue, the price is gone up to 4ct. and the planner did not switch off. Take a look in the attachment.

Do you have any ideas to solve this?

Thanks in advance, Kind regards. Daniel

image

Average
4,52
Off peak 1
0,44
Off peak 2
6,59
Peak
6,55
Min
-0,14
Max
8,3
Mean
5,76
Unit
kWh
Currency
EUR
Country
Germany and Luxembourg
Region
DE-LU
Low price
true
Price percent to average
0,9
Today
-0,01, -0,12, -0,13, -0,13, -0,13, -0,14, 0,11, 4,06, 5,96, 6,06, 5,7, 5,49, 5,39, 5,44, 6,09, 6,72, 7,36, 8,23, 8,3, 7,9, 7,32, 6,74, 6,5, 5,81
Tomorrow
Tomorrow valid
false
Raw today
- start: '2024-01-03T00:00:00+01:00'
end: '2024-01-03T01:00:00+01:00'
value: -0.008
- start: '2024-01-03T01:00:00+01:00'
end: '2024-01-03T02:00:00+01:00'
value: -0.123
- start: '2024-01-03T02:00:00+01:00'
end: '2024-01-03T03:00:00+01:00'
value: -0.13
- start: '2024-01-03T03:00:00+01:00'
end: '2024-01-03T04:00:00+01:00'
value: -0.131
- start: '2024-01-03T04:00:00+01:00'
end: '2024-01-03T05:00:00+01:00'
value: -0.131
- start: '2024-01-03T05:00:00+01:00'
end: '2024-01-03T06:00:00+01:00'
value: -0.138
- start: '2024-01-03T06:00:00+01:00'
end: '2024-01-03T07:00:00+01:00'
value: 0.109
- start: '2024-01-03T07:00:00+01:00'
end: '2024-01-03T08:00:00+01:00'
value: 4.059
- start: '2024-01-03T08:00:00+01:00'
end: '2024-01-03T09:00:00+01:00'
value: 5.961
- start: '2024-01-03T09:00:00+01:00'
end: '2024-01-03T10:00:00+01:00'
value: 6.061
- start: '2024-01-03T10:00:00+01:00'
end: '2024-01-03T11:00:00+01:00'
value: 5.7
- start: '2024-01-03T11:00:00+01:00'
end: '2024-01-03T12:00:00+01:00'
value: 5.489
- start: '2024-01-03T12:00:00+01:00'
end: '2024-01-03T13:00:00+01:00'
value: 5.389
- start: '2024-01-03T13:00:00+01:00'
end: '2024-01-03T14:00:00+01:00'
value: 5.442
- start: '2024-01-03T14:00:00+01:00'
end: '2024-01-03T15:00:00+01:00'
value: 6.086
- start: '2024-01-03T15:00:00+01:00'
end: '2024-01-03T16:00:00+01:00'
value: 6.718
- start: '2024-01-03T16:00:00+01:00'
end: '2024-01-03T17:00:00+01:00'
value: 7.359
- start: '2024-01-03T17:00:00+01:00'
end: '2024-01-03T18:00:00+01:00'
value: 8.228
- start: '2024-01-03T18:00:00+01:00'
end: '2024-01-03T19:00:00+01:00'
value: 8.297
- start: '2024-01-03T19:00:00+01:00'
end: '2024-01-03T20:00:00+01:00'
value: 7.903
- start: '2024-01-03T20:00:00+01:00'
end: '2024-01-03T21:00:00+01:00'
value: 7.323
- start: '2024-01-03T21:00:00+01:00'
end: '2024-01-03T22:00:00+01:00'
value: 6.741
- start: '2024-01-03T22:00:00+01:00'
end: '2024-01-03T23:00:00+01:00'
value: 6.5
- start: '2024-01-03T23:00:00+01:00'
end: '2024-01-04T00:00:00+01:00'
value: 5.812
Raw tomorrow
Current price
4,06
Additional costs current hour
0
Price in cents
true

image

dala318 commented 7 months ago

Hi, have not really thought of negative prices until now. Spontaneously I would say it should work just fine, but apparently there is something strange happening. I actually think I may have found something there where both the ACCEPT_COST and ACCEPT_RATE default to 0.0. And seem they are locked to not being possible to set negative values.

        vol.Optional(ACCEPT_COST, default=0.0): vol.All(
            vol.Coerce(float), vol.Range(min=0.0, max=10000.0)
        ),
        vol.Optional(ACCEPT_RATE, default=0.0): vol.All(
            vol.Coerce(float), vol.Range(min=0.0, max=10000.0)
        ),

One could try to allow negative range but specially the ACCEPT_RATE I'm not so sure how large negative value must be allowed.

In the example from 2023-12-29 it should not activate until the two [-0.093, -0.095] 03:00 and 04:00 (which has the lowest average in the up to 24h span ahead).

On the other hand it should likely not switch off when that time has passed as the "moving 24h" only looks at prices in the future. So at 07:00 when the price is -0.001 it's still the cheapest looking in the future.

Danny-DFx commented 7 months ago

Hello, thanks for your answer. The planner ignores the default duration completely, also my individual setting does not work. It doesn't matter what is in the binary sensor. My workaround is, that I set the duration max=5 in /homeassistant/custom_components/nordpool_planner/binary_sensor.py to what I need, but this is only a workaround.

dala318 commented 4 days ago

I have now published a pre-release of v2.0 (#33 & #31 ) which completely we-works the integration, both how it is configured but also how the searching for lowest (and highest) cost. If you want to please try it and give feedback if it helps.