ottopaulsen / node-red-contrib-power-saver

A Node-RED node to saver money by turning off when the power is most expensive
Other
71 stars 17 forks source link

[Request] Highest prices #82

Open riksarchen opened 1 year ago

riksarchen commented 1 year ago

This might sound odd but any chance to add an inverted lowest price which returns the highest price in a defined period?

It would be very useful for controlling the home battery so you don't waste battery energy on low price hours.

ottopaulsen commented 1 year ago

Just switch output 1 and 2, and change hours on to 24 - x, where x is the number of hours you want. Assuming the period you select is 24 hours.

ottopaulsen commented 1 year ago

It is actually described in the documentation: https://powersaver.no/nodes/ps-strategy-lowest-price.html#highest-price

riksarchen commented 1 year ago

Hi Otto, Thank you. I tried that but it has some limitations. I have to define the number of hours it must be on. In reality when you invert the output you want to define the highest x hours in a timeframe. In my example I want the highest 4 hours between 04:00 and 11:00 (my battery last around 4 hours).

Today the highest prices are between 06:00 and 10:00 in my area. If I select hours on = 7-4 it has to have 3 hours on before it can select 4 hours off which means it will 'turn off' at 07:00 instead of 06:00.

Do I need to unselect concecutive hours or are there any other workarounds? I prefer not to unselect it as it doesnt work very well on longer timeframes. I think it would be easiest with a strategy where you can define the x hours that are most expensive as it doesnt rely on how many hours that are cheap before and after the timeframe. Not sure if this makes any sense :-D

ottopaulsen commented 1 year ago

Good point. My example will only work for not consecutive hours. Maybe Highest Price is a good idea! I will see when I get time.

riksarchen commented 1 year ago

Thank you 😊

marhoy commented 1 year ago

@riksarchen and @ottopaulsen: I guess you could just change the sign of the prices (and possibly add a constant to prevent them from being negative, if that's a problem). Given inverted price-data, the lowest-price node would instead find periods with highest price.

riksarchen commented 1 year ago

@riksarchen and @ottopaulsen: I guess you could just change the sign of the prices (and possibly add a constant to prevent them from being negative, if that's a problem). Given inverted price-data, the lowest-price node would instead find periods with highest price.

That's really clever. Thank you, I'll use that method until officially supported

riksarchen commented 1 year ago

@riksarchen and @ottopaulsen: I guess you could just change the sign of the prices (and possibly add a constant to prevent them from being negative, if that's a problem). Given inverted price-data, the lowest-price node would instead find periods with highest price.

I tried your approach but I can't get it to work. See here:

12 | 04:00 | -0.754 | On |   |   |   -- | -- | -- | -- | -- | -- | -- 12 | 05:00 | -0.784 | On |   |   |   12 | 06:00 | -1.377 | Off |   |   |   12 | 07:00 | -3.344 | Off |   |   |   12 | 08:00 | -3.391 | Off |   |   |   12 | 09:00 | -3.469 | Off

The options I use is lowest 2 hours concecutive hours. Off outside, Off no schedule.

{"schedule":[{"time":"2022-10-11T00:00:00+02:00","value":false,"countHours":4},{"time":"2022-10-11T04:00:00+02:00","value":true,"countHours":2},{"time":"2022-10-11T06:00:00+02:00","value":false,"countHours":22},{"time":"2022-10-12T04:00:00+02:00","value":true,"countHours":2},{"time":"2022-10-12T06:00:00+02:00","value":false,"countHours":18}],"hours":[{"price":-0.586,"onOff":false,"start":"2022-10-11T00:00:00+02:00","saving":null},{"price":-0.586,"onOff":false,"start":"2022-10-11T01:00:00+02:00","saving":null},{"price":-0.591,"onOff":false,"start":"2022-10-11T02:00:00+02:00","saving":null},{"price":-0.599,"onOff":false,"start":"2022-10-11T03:00:00+02:00","saving":null},{"price":-0.613,"onOff":true,"start":"2022-10-11T04:00:00+02:00","saving":null},{"price":-0.691,"onOff":true,"start":"2022-10-11T05:00:00+02:00","saving":null},{"price":-0.735,"onOff":false,"start":"2022-10-11T06:00:00+02:00","saving":null},{"price":-0.758,"onOff":false,"start":"2022-10-11T07:00:00+02:00","saving":null},{"price":-0.765,"onOff":false,"start":"2022-10-11T08:00:00+02:00","saving":null},{"price":-0.763,"onOff":false,"start":"2022-10-11T09:00:00+02:00","saving":null},{"price":-0.761,"onOff":false,"start":"2022-10-11T10:00:00+02:00","saving":null},{"price":-0.758,"onOff":false,"start":"2022-10-11T11:00:00+02:00","saving":null},{"price":-0.758,"onOff":false,"start":"2022-10-11T12:00:00+02:00","saving":null},{"price":-0.752,"onOff":false,"start":"2022-10-11T13:00:00+02:00","saving":null},{"price":-0.738,"onOff":false,"start":"2022-10-11T14:00:00+02:00","saving":null},{"price":-0.735,"onOff":false,"start":"2022-10-11T15:00:00+02:00","saving":null},{"price":-0.741,"onOff":false,"start":"2022-10-11T16:00:00+02:00","saving":null},{"price":-0.759,"onOff":false,"start":"2022-10-11T17:00:00+02:00","saving":null},{"price":-0.764,"onOff":false,"start":"2022-10-11T18:00:00+02:00","saving":null},{"price":-0.76,"onOff":false,"start":"2022-10-11T19:00:00+02:00","saving":null},{"price":-0.736,"onOff":false,"start":"2022-10-11T20:00:00+02:00","saving":null},{"price":-0.73,"onOff":false,"start":"2022-10-11T21:00:00+02:00","saving":null},{"price":-0.7,"onOff":false,"start":"2022-10-11T22:00:00+02:00","saving":null},{"price":-0.628,"onOff":false,"start":"2022-10-11T23:00:00+02:00","saving":null},{"price":-0.728,"onOff":false,"start":"2022-10-12T00:00:00+02:00","saving":null},{"price":-0.727,"onOff":false,"start":"2022-10-12T01:00:00+02:00","saving":null},{"price":-0.73,"onOff":false,"start":"2022-10-12T02:00:00+02:00","saving":null},{"price":-0.74,"onOff":false,"start":"2022-10-12T03:00:00+02:00","saving":null},{"price":-0.754,"onOff":true,"start":"2022-10-12T04:00:00+02:00","saving":null},{"price":-0.784,"onOff":true,"start":"2022-10-12T05:00:00+02:00","saving":null},{"price":-1.377,"onOff":false,"start":"2022-10-12T06:00:00+02:00","saving":null},{"price":-3.344,"onOff":false,"start":"2022-10-12T07:00:00+02:00","saving":null},{"price":-3.391,"onOff":false,"start":"2022-10-12T08:00:00+02:00","saving":null},{"price":-3.469,"onOff":false,"start":"2022-10-12T09:00:00+02:00","saving":null},{"price":-4.296,"onOff":false,"start":"2022-10-12T10:00:00+02:00","saving":null},{"price":-3.365,"onOff":false,"start":"2022-10-12T11:00:00+02:00","saving":null},{"price":-3.236,"onOff":false,"start":"2022-10-12T12:00:00+02:00","saving":null},{"price":-3.155,"onOff":false,"start":"2022-10-12T13:00:00+02:00","saving":null},{"price":-3.122,"onOff":false,"start":"2022-10-12T14:00:00+02:00","saving":null},{"price":-3.142,"onOff":false,"start":"2022-10-12T15:00:00+02:00","saving":null},{"price":-3.134,"onOff":false,"start":"2022-10-12T16:00:00+02:00","saving":null},{"price":-3.38,"onOff":false,"start":"2022-10-12T17:00:00+02:00","saving":null},{"price":-3.403,"onOff":false,"start":"2022-10-12T18:00:00+02:00","saving":null},{"price":-3.363,"onOff":false,"start":"2022-10-12T19:00:00+02:00","saving":null},{"price":-3.113,"onOff":false,"start":"2022-10-12T20:00:00+02:00","saving":null},{"price":-1.917,"onOff":false,"start":"2022-10-12T21:00:00+02:00","saving":null},{"price":-0.799,"onOff":false,"start":"2022-10-12T22:00:00+02:00","saving":null},{"price":-0.791,"onOff":false,"start":"2022-10-12T23:00:00+02:00","saving":null}],"source":"Nordpool","config":{"fromTime":"04","toTime":"09","hoursOn":2,"maxPrice":null,"doNotSplit":true,"sendCurrentValueWhenRescheduling":true,"outputIfNoSchedule":false,"outputOutsidePeriod":false,"contextStorage":"memory"},"sentOnCommand":false,"time":"2022-10-11T13:33:26.993+02:00","version":"3.6.2","current":false}

riksarchen commented 1 year ago

Adding a constant solved the problem. Seems like a bug in lowest price node that it can't handle negative prices? How does that affect when we have negative prices in reality?

twosh commented 1 year ago

Hi,

I have the exact same wish as you @riksarchen due to my battery also lasting around 4 hours. Could you describe in more detail how you got your workaround working?

My setup is that I have the Home Assistant Nordpool Spot Price node pushing the price object to the Price Receiver, then to a Tariff node, followed by the Lowest Price node (which I would like to act as a Highest Price node instead)

Could you share your flow / code for adding the negative sign and constant?

I'll also take this chance to give creds to @ottopaulsen as well for a really useful set of nodes! :)

Cheers!

riksarchen commented 1 year ago

Hi,

I have the exact same wish as you @riksarchen due to my battery also lasting around 4 hours. Could you describe in more detail how you got your workaround working?

My setup is that I have the Home Assistant Nordpool Spot Price node pushing the price object to the Price Receiver, then to a Tariff node, followed by the Lowest Price node (which I would like to act as a Highest Price node instead)

Could you share your flow / code for adding the negative sign and constant?

I'll also take this chance to give creds to @ottopaulsen as well for a really useful set of nodes! :)

Cheers!

Hello, I created a function module between the price receiver and lowest price module.

[{"id":"6345bb6314295ff2","type":"function","z":"f8d8ec8d854f582e","name":"change to highest prices","func":"var array = msg.payload.priceData;\n\narray.forEach(function (item, index) {\n item.value = (item.value * -1)+100;\n});\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1210,"y":80,"wires":[["45beba082fb9a665"]]}]

twosh commented 1 year ago

That worked like a charm! Still a noob in manipulating objects in Node Reds function nodes. Thank you very much! :)

riksarchen commented 1 year ago

That worked like a charm! Still a noob in manipulating objects in Node Reds function nodes. Thank you very much! :)

You're welcome :-)