JSPM

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

2.0.0
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 15
    • Score
      100M100P100Q47405F
    • License MIT

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

    Package Exports

      This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (node-red-contrib-ha-avg-by-group) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

      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).