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

Question regarding Capacity Part of Grid Tariff - reduction actions (consumption) #105

Closed gulli1986 closed 1 year ago

gulli1986 commented 1 year ago

Hello,

Looking at the documentation for the capacity part of the grid tariff and have a question regarding the Reduction Actions.

Do the entity id of the consumption variable need to be reporting consumption in a specific unit, i.e kW? I have some sensors reporting in W, some other reporting in kW. For me it looks like I need to make the conversion so that everything is in kW, is that correct?

ottopaulsen commented 1 year ago

Hi,

I thought I should examine this carefully now, since I have gotten the same question before. I found that there is a bug. All my sensors are returning consumption in W, but I am treating it as kW.

If your situation is the same, you can fix this in the Reduction Actions node, function getConsumption, the first part of the if, change to:

return sensor.state / 1000

If you are using fixed values or functions, make sure they also result in kW, as that is what is used.

I haven't tried this, so this is what I find by just looking at the code, but I think this will be right.

Please try and give feedback.

gulli1986 commented 1 year ago

Thanks @ottopaulsen . I agree with you, it looks like everything needs to be in kW. My problem is that some of my sensors report W and some report kW so I cannot use the workaround you mentioned above.

As of now I made a template to convert all my sensors from W to kW in HA but I thought maybe it could be possible to read the sensor unit in the getConsumption function and either return sensor.state or sensor.state / 1000 based on the unit?

ottopaulsen commented 1 year ago

Isn't there a way to create a sensor based on another sensor where you divide the value by 1000?

gulli1986 commented 1 year ago

There is in HA using a template which I did. Not sure how this could be implemented in Node Red without creating a new sensor in HA.

ottopaulsen commented 1 year ago

That was the idea, creating a new sensor in HA.

gulli1986 commented 1 year ago

Closing this issue. Creating a new sensor in HA in kW as a workaround.

gulli1986 commented 1 year ago

Hello @ottopaulsen , just updated to the new capacity grid after the last powersaver update. Here I can see the following in the code:

function getConsumption(consumption) {
  if (typeof consumption === "string") {
    const sensor = ha.states[consumption];
    return sensor.state / 1000;
  } else if (typeof consumption === "number") {
    return consumption;
  } else if (typeof consumption === "function") {
    return consumption();
  } else {
    node.warn("Config error: consumption has illegal type: " + typeof consumption);
    return 0;
  }
}

It looks like you have divided the output by 1000. Is that because all your sensors are reporting in W? I converted all my sensors to kW so I guess I can remove the /1000?

gulli1986 commented 1 year ago

Solved, needed to remove /1000