Skip to content

Add Energy Usage to the API -> Home Assistant Energy Usage #7

Open

Description

@deftdawg

Wondering Energy usage can be added?

I'm thinking maybe Hourly could be reported downstream to Home Assistant to make NuHeat contribute to the Energy stats for consumption devices in a similar manner to how some smart plugs report energy consumption.

I've done the this work to update the Neurio component, hopefully that will arrive with in HA's 2021.12.1 release. I'd be cool to try to make this work downstream for HA's NuHeat component (though I'm not a native python dev; so might take a while to get merged). :)

Activity

  1. kaijk commented on Jan 16, 2022

    @kaijk

    I up-vote this request for the API to support hourly energy reporting. I too use Home Assistant with a nuheat thermostat and would appreciate the energy data being available.
    Thanks.

  2. trdischat commented on Jul 2, 2022

    @trdischat

    Just adding my voice to this request. It certainly looks like the nuheat API supports queries for energy use.

  3. kut commented on Dec 4, 2024

    @kut

    Looks like the GET endpoint /api/v1/EnergyLog/Day/{serialNumber}/{date} would return:

    
    {
      "energyUsageType": "string",
      "energyUsageFrom": "string",
      "energyUsageTo": "string",
      "mondayIsFirstDay": true,
      "energyUsage": [
        {
          "entry": "string",
          "minutes": 0,
          "energyKWattHour": 0,
          "chargeKWattHour": 0
        }
      ]
    }
    
    

    See: https://api.mynuheat.com/swagger/

    Do folks still think this is interesting? I also would be very interested in adding this to Home Assistant energy monitoring...

  4. barndawgie commented on Jul 6, 2025

    @barndawgie

    A little further investigation seems to indicate that they aren't actually metering anything - simply estimate kWh based on your indicated 1) Square Footage 2) Hours of Runtime, and 3) Watts per square foot (which they say is generally 12W).

    So you can replicate this pretty easily with a Template Sensor like this:

    {% set watts_per_square_foot = 12 %}
    {% set square_footage = 28 %}
    
    {% if state_attr('climate.basement_bath','hvac_action') == 'heating'%}
      {{ watts_per_square_foot * square_footage | int }}
    {% else %}
      {{ 0 | int }}
    {% endif %}

    Just replace 12 with your expected W/Area and 28 with the Area of your heated floor. That will create a Power sensor and you can then create an Integration Helper to get kWh used.

    I'm going to try and validate this against the API but it seems to be having some issues currently.

  5. trdischat commented on Jul 6, 2025

    @trdischat

    Just replace 12 with your expected W/Area and 28 with the Area of your heated floor. That will create a Power sensor and you can then create an Integration Helper to get kWh used.

    I have used a very similar approach for years. The cable in my floor has a rated draw of 6 amps. That times 120 volts gives me 720 watts. That times runtime (using an integration sensor) yields kWh. My template power sensor is quite similar to yours, but I added a tiny amount of random variation to the values. Otherwise, the integration sensor doesn't work correctly.

    - name: "Power Consumption NuHeat"
      unit_of_measurement: "W"
      device_class: power
      state: >-
        {% if state_attr('climate.nuheat', 'hvac_action') == 'heating' %}
          {{ 720.0  + ( ( range(-100, 101) | random ) / 10000 ) }}
        {% else %}
          {{ 0.0 }}
        {% endif %}
    - platform: integration
      source: sensor.power_consumption_nuheat
      name: "Energy Consumption NuHeat"
      unit_prefix: k
      unit_time: h
      method: left
  6. barndawgie commented on Jul 7, 2025

    @barndawgie

    @trdischat - What exactly breaks the integral? I haven't put in that randomness - I guess I could, but would like to understand what exactly I'm working around.

  7. trdischat commented on Jul 7, 2025

    @trdischat

    The Integral sensor is designed to calculate the Riemann sum of a source sensor's values over time. However, there can be issues when the source sensor's value remains unchanged for extended periods. If your source sensor consistently reports the same value (e.g., a constant power draw), the Integral sensor may not update until the source sensor's value changes. This can lead to inaccurate integration results, as the integral isn't calculated over the duration the value was constant. For example, if you're integrating power (Watts) to get energy (Watt-hours) and the power sensor reports a steady value, the energy calculation will not be updated until the power value changes, even though energy is being consumed during that period. See home-assistant/core#88940.

    One way to address this issue is to add a tiny amount of random jitter to the sensor values, which triggers updates to the Integral sensor without significantly affecting the overall integral calculation. The other recommendation is to use the left method for the Riemann sum, since it is best for "rectangular functions which are very stable for long periods of time and change very rapidly." A final suggestion, which I haven't tried yet, is to set the max_sub_interval option to something other than zero in your Integral sensor. This triggers an update to the sensor periodically, even if the source value doesn't change. It is possible that this option would make it unnecessary to inject random jitter into the power sensor.

  8. barndawgie commented on Jul 7, 2025

    @barndawgie

    The Integral sensor is designed to calculate the Riemann sum of a source sensor's values over time. However, there can be issues when the source sensor's value remains unchanged for extended periods. If your source sensor consistently reports the same value (e.g., a constant power draw), the Integral sensor may not update until the source sensor's value changes. This can lead to inaccurate integration results, as the integral isn't calculated over the duration the value was constant. For example, if you're integrating power (Watts) to get energy (Watt-hours) and the power sensor reports a steady value, the energy calculation will not be updated until the power value changes, even though energy is being consumed during that period. See home-assistant/core#88940.

    One way to address this issue is to add a tiny amount of random jitter to the sensor values, which triggers updates to the Integral sensor without significantly affecting the overall integral calculation. The other recommendation is to use the left method for the Riemann sum, since it is best for "rectangular functions which are very stable for long periods of time and change very rapidly." A final suggestion, which I haven't tried yet, is to set the max_sub_interval option to something other than zero in your Integral sensor. This triggers an update to the sensor periodically, even if the source value doesn't change. It is possible that this option would make it unnecessary to inject random jitter into the power sensor.

    Thanks! I am using left already due to that recommendation and have that periodic update piece set as well. Will try to report back if I see issues - so far it it seems to be working.

  9. kaijk commented on Jul 7, 2025

    @kaijk
  10. eric commented on Jan 11, 2026

    @eric

    I'm working on exposing this in the nuheat component directly: home-assistant/core#160751

  11. eric commented on Jan 13, 2026

    @eric

    Here's the pull request here related to this: #21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions