npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

node-red-contrib-ha-avg-by-group

v2.0.0

Published

Node-RED node for averaging Home Assistant temperature sensors by group. Real HA server selector, robust HA state discovery, and searchable entity autocomplete.

Readme

node-red-contrib-ha-avg-by-group

A Node-RED node that computes group-based temperature averages from Home Assistant sensors.
It skips rows when the associated contact sensor is on or when the row is unchecked.
Outputs are dynamic: the node creates one output per used group, and each output emits only msg.payload (the numeric average).
If a group has no valid rows, no message is sent on that port; if no groups have results, no messages are sent at all.


Features

  • Dynamic outputs: one output per used group (1–20). Port labels show Group N.
  • Home Assistant server selector: pick the HA config node from a dropdown.
  • Entity autocomplete (editor): search sensor.* and binary_sensor.* with friendly names.
  • Row-level rules:
    • Unchecked row → ignored.
    • Contact sensor state on → row ignored.
    • Missing fields in a checked row → ignored (and highlighted red in editor).
  • Robust HA state discovery in runtime:
    • Optional override path (e.g. homeassistant.homeAssistant.states).
    • Uses the selected server name (camelCased) inside global.homeassistant.
    • Falls back to the first namespace with .states (prefers homeAssistant).
  • Decimal comma support for sensor values (e.g. "22,4").

Requirements

  • Node-RED
  • node-red-contrib-home-assistant-websocket
  • In the HA server config node, enable Expose to global context
    (the node reads HA states from global.homeassistant.*.states).

Installation

  1. Create a folder:
    ~/.node-red/node_modules/node-red-contrib-ha-avg-by-group/
  2. Place these files inside:
    • package.json
    • nodes/ha-avg-by-group.html
    • nodes/ha-avg-by-group.js
  3. Restart Node-RED.
  4. Find the node under Function → HA avg temps.

Configuration

Home Assistant server
Select the HA server (config node). Autocomplete and runtime state discovery use this selection.

HA state path (override) (optional)
Explicit path inside global.homeassistant. Examples:

  • homeassistant.homeAssistant.states
  • homeassistant.myHomeInstance.states

Leave empty to auto-detect.

Rows (editable list)
Each row has:

  1. Use (checkbox) — whether the row is considered.
  2. Temperature sensor — a sensor.* entity.
  3. Contact sensor — a binary_sensor.* entity.
  4. Group — number 1–20.

The editor shows red borders for missing fields in checked rows.
Use the + button to add rows; rows are sortable and removable.


How outputs work

  • The node gathers the distinct groups used in your rows and stores that order.
  • On Deploy, it sets the number of outputs to match the used groups.
  • At runtime, it builds an output array where:
    • Index i corresponds to group groupOrder[i] (shown as port label Group N).
    • If a group has a valid average, that port sends { payload: <average> }.
    • If a group has no valid rows, that port sends nothing.
  • If no groups have results, no message is sent at all.

Rounding: averages are rounded to 2 decimal places.


Autocomplete (editor)

  • Start typing sensor. or binary_sensor. (or part of the friendly name).
  • The editor calls GET /ha-avg-by-group/entities?serverId=<config-id> and lists entities as
    entity_id — Friendly Name.
  • Note: you must have deployed at least one instance of this node in the flow once, so the endpoint can access global context.

Examples

Example A – Single group, both rows valid

  • Row 1: sensor.temp1 = 20, binary_sensor.door1 = off, Group 1
  • Row 2: sensor.temp2 = 22, binary_sensor.door2 = off, Group 1

Output (port “Group 1”):

{ "payload": 21 }

Example B – Single group, one row ignored

  • Row 1: sensor.temp1 = 20, binary_sensor.door1 = off, Group 1
  • Row 2: sensor.temp2 = 22, binary_sensor.door2 = on, Group 1

Output (port “Group 1”):

{ "payload": 20 }

Example C – Single group, all rows ignored
(e.g., both contacts on, or both rows unchecked)

Output: no message.

Example D – Two groups

  • Group 1 rows average to 22
  • Group 2 rows average to 21

Outputs:

  • Port “Group 1” → { "payload": 22 }
  • Port “Group 2” → { "payload": 21 }

Troubleshooting

“No HA states” status on the node

  • Ensure Expose to global context is enabled on your HA server config.
  • Make sure you selected the correct Home Assistant server in the node.
  • If your global path is custom, set HA state path (override).
    Example: homeassistant.myHomeInstance.states
  • The node’s status will print the keys it can see under global.homeassistant (e.g., homeAssistant, myHomeInstance) to help you pick the right path.

Autocomplete shows no entities

  • Deploy at least once (so the admin endpoint can read the global context).
  • Verify the correct server is selected.
  • Verify HA states exist under global.homeassistant.*.states.

Outputs don’t match my groups

  • The number and order of outputs are determined at save/deploy time from the used groups.
  • If you change groups in rows, open the node and Deploy to update outputs.

Notes & Behavior

  • A row with missing fields (when checked) is ignored.
  • A row is ignored if its contact sensor state is on.
  • Averages use the sensor state value directly; "22,4" is supported (decimal comma).
  • The node emits only msg.payload; no other msg.* properties are set.

License

MIT


Acknowledgements

Built to work alongside node-red-contrib-home-assistant-websocket. Thanks to the community for the HA global context pattern (global.homeassistant.*.states).