ottopaulsen / node-red-contrib-power-saver

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

Error when using dynamic configuration #157

Closed WilLlLli closed 1 year ago

WilLlLli commented 1 year ago

When using a dynamic configuration on a "ps-strategy-lowest-price" node I get the following error and no reconfiguration of the node: "TypeError: Cannot destructure property 'plan' of 'handleStrategyInput(...)' as it is undefined."

The code used for the dynamic configuration is the following:

var newMsg = { "payload": { "config": { "maxPrice": 14 //"contextStorage" String //"fromTime" String with number, 2 digits, "00" - "23" //"toTime" String with number, 2 digits, "00" - "23" //"hoursOn" Number //"maxPrice" Number //"outputIfNoSchedule" Legal values: true, false //"outputIfNoSchedule" Legal values: true, false //"doNotSplit" Legal values: true, false //"outputOutsidePeriod" Legal values: true, false //"sendCurrentValueWhenRescheduling" Legal values: true, false //"outputValueForOn" See description in Dynamic Config //"outputValueForOff" See description in Dynamic Config //"outputValueForOntype" See description in Dynamic Config //"outputValueForOfftype" See description in Dynamic Config //"override" Legal values: "on", "off", "auto" } } }; return newMsg;

I searched the internet but didn't find a good example of a function used for the dynamic reconfigurations of a node.

ottopaulsen commented 1 year ago

If you are sending the text above, it will not work. It is JavaScript, not JSON. Try to send only this:

{
  "payload": {
    "config": {
      "maxPrice": 14
    }
  }
}

However, if your code is actually JavaScript that you are running in a function node, you can replace the return newMsg with:

node.send(newMsg)

I think that might work.

I hope it will take some time until the max price of 14 kr strikes ;-)

WilLlLli commented 1 year ago

Thank Otto, your suggestion worked! The price is hower not in kr but in Eurc/kWh in my case which makes is more realistic.

ottopaulsen commented 1 year ago

Interesting. What country are you in? So you are also priced per hour?

WilLlLli commented 1 year ago

I'm from Belgium and yes, we have contracts with prices that change every hour

ottopaulsen commented 1 year ago

Great :-) Thanks, closing this issue, then.