PowerSaverPowerSaver
Guide
Nodes
Examples
FAQ
Contribute
Changes
  • GitHub
  • npm registry
  • Node-RED Library
Guide
Nodes
Examples
FAQ
Contribute
Changes
  • GitHub
  • npm registry
  • Node-RED Library
  • Examples

    • Nord Pool and current state node
    • Nord Pool and events: state node
    • Tibber, a switch and MQTT
    • Simple heat capacitor strategy flow
    • Cascade temperature control
    • Lovelace Visualization
    • Capacity part of grid tariff
    • Strømstøtte
    • Reduce minutes array

Reduce minutes array

If you want to reduce number of entries in the minutes array on output 3, you can send it through a function node with the following code:

const minutes = []
let previousHour = ""
let previousSaving = null
let previousPrice = null
msg.payload.minutes.forEach(m => {
  const hour = m.start.substring(0, 13)
  if (hour !== previousHour || m.saving !== previousSaving || m.price !== previousPrice) {
    minutes.push(m)
    previousHour = hour
    previousSaving = m.saving
    previousPrice = m.price
  }
})

msg.payload.minutes = minutes

return msg;

It will remove all entries that are equal to the one before, but still send at least one per hour.

Last Updated:
Prev
Strømstøtte