ha-emporia-vue icon indicating copy to clipboard operation
ha-emporia-vue copied to clipboard

Information supplied to HA Energy Configuration

Open knuckleheadsmiff opened this issue 2 years ago • 11 comments

I’m not sure where the “bug” is or if it is one. I am a newbie to HA. I get my meter values as single positive and negative numbers. I want to easily feed in the return to grid number and grid usage numbers into the energy configuration and am not sure how to do this. I’m able to see the current/daily and monthly numbers just fine but again it is jusr one positive and negative value which is hard to use with the energy configuration UI.

Im sorry if this is not a bug and my lack of understanding about the Energy Pane in HA.

knuckleheadsmiff avatar Feb 04 '22 18:02 knuckleheadsmiff

The sensor reports it's value should only increase: https://github.com/magico13/ha-emporia-vue/blob/c1aaac407560e9c91ffdc2c016c368ade2a0b0a8/custom_components/emporia_vue/sensor.py#L112-L113 In order to allow decreasing the sensor should report STATE_CLASS_TOTAL https://developers.home-assistant.io/docs/core/entity/sensor/

In addition the usage of state classes as strings is depreciated and should be updated to use enum: https://github.com/home-assistant/core/blob/6871271e7328b8cbf1a2c5c6604f292f43780dcd/homeassistant/components/sensor/init.py#L172-L193

thecode avatar Feb 05 '22 09:02 thecode

I’m going to close this. I think this is just really a documentation issue—and the Energy Configuration in HA needs better doc too. It looks like if I use the “daily” sensor and only set it as “grid consumption” in the energy config then everything works as I expect it too.

I believe the “current” sensor to be like a thermometer where it is the actually value and negative numbers seem correct.

knuckleheadsmiff avatar Feb 05 '22 17:02 knuckleheadsmiff

Closed per comment above.

knuckleheadsmiff avatar Feb 05 '22 17:02 knuckleheadsmiff

Ok, I’m reopening. While I thought it was working for the daily value, as soon as I went negative for the day the HA Energy Panel barfed with negative Numbers. This was at the point where I sent back more energy to to grid then I received. So again I’m not sure where the issue is but the comment above was from someone with HA.

In the 1st graph HA Energy you can see the consumption from grid stop. The second graph is of the entity used and you can see the for today, the problem happens when it crossed 0, around 12:30pm. I’ll also note that I don’t see anything in the HAs Energy graph for yesterday.

6588E248-7A2A-4931-A2E2-F3979A99D267 28E98236-8B5B-47F4-909D-46F8AAEBB52F

knuckleheadsmiff avatar Feb 06 '22 00:02 knuckleheadsmiff

Oh, the logs contain errors log this:

"integration emporia_vue has state class total_increasing, but its state is negative."

when using in the Energy Configuration.

Again just a newbie here but perhaps keeping current sensors like they are and add 2 virtual sensors with the values split into to grid/ from grid? Don't know it that makes sense and since I can't do this with templates for the energy dashboard I'm not sure how I can work around.

knuckleheadsmiff avatar Feb 06 '22 17:02 knuckleheadsmiff

@knuckleheadsmiff the sensor needs to be changed as I explained in https://github.com/magico13/ha-emporia-vue/issues/101#issuecomment-1030584225 there is nothing else to be done. Using virtual sensors will not be approved. Sensors should represent the device.

thecode avatar Feb 06 '22 17:02 thecode

This is technically a duplicate of #93 since it really only applies to the utility connect device. When using a Vue you should have separate To Grid and From Grid sensors that are (when the API gives me sensible data, which isn't always true) correctly total_increasing. The only way for the utility connect to work when you have solar or other export is for me (or someone else in a PR) to make the changes @thecode mentions.

magico13 avatar Feb 06 '22 17:02 magico13

I'll leave it to you guys who know a lot more. Thanks.

(I don't need to understand the details but in reality the physical device "runs backwards" and for folks with net metering this makes sense. Why sensors can't have negative values seems at best odd to me.)

knuckleheadsmiff avatar Feb 06 '22 18:02 knuckleheadsmiff

As an FYI….

I was able to create two template meters/sensors that can represent to grid and from grid by keeping track of deltas and feeding it into the energy pane. It mostly works but could be better.

One issue is that I can’t use the daily sensor/entity as my data source because when it resets at midnight it effectively zeros out the deltas for the day. So I’m using the month sensor/entity which works just fine except at the end of the month so 1 day will be off and my monthly numbers will net out to zero.

The other issue with using the monthly sensor is that it only updates hourly and that does not work well with the energy hourly graphing, more frequent updates are better. (The daily entity displays the just fine except for the midnight reset issue mentioned above.)

What would be great is a sensor that updates as frequently as the daily sensor but never resets. Then my templates would work well with the energy panel. (Even better of course is a solution where I didn’t need to create my own meters.)

knuckleheadsmiff avatar Feb 19 '22 01:02 knuckleheadsmiff

This is my template code if anyone cares.

  • trigger:
    • platform: state entity_id: sensor.pg_e_smartmeter_123_1mon to: # Skip attribute-only changes. sensor:
      • name: "Electric Meter Consumption" unique_id: "electric_meter_consumption" device_class: "energy" unit_of_measurement: "kWh" state_class: "total_increasing" state: > {% set last = states("sensor.electric_meter_consumption") | float(0) %} {% if trigger.from_state.state == 'unknown' or trigger.from_state.state == 'unavailable' or trigger.to_state.state == 'unknown' or trigger.to_state.state == 'unavailable'%} {{ last }} {% else %} {% set from = trigger.from_state.state | float %} {% set to = trigger.to_state.state | float %} {% if to - from > 0 %} {{ (last + to - from) | round(3) }} {% else %} {{ last | round(3) }} {% endif %} {% endif %}
      • name: "Electric Meter Return" unique_id: "electric_meter_return" device_class: "energy" unit_of_measurement: "kWh" state_class: "total_increasing" state: > {% set last = states("sensor.electric_meter_return") | float(0) %} {% if trigger.from_state.state == 'unknown' or trigger.from_state.state == 'unavailable' or trigger.to_state.state == 'unknown' or trigger.to_state.state == 'unavailable' %} {{ last }} {% else %} {% set from = trigger.from_state.state | float %} {% set to = trigger.to_state.state | float %} {% if to - from > 0 %} {{ last | round(3) }} {% else %} {{ (last + from - to) | round(3) }} {% endif %} {% endif %}

knuckleheadsmiff avatar Feb 19 '22 01:02 knuckleheadsmiff

@knuckleheadsmiff Thanks for sharing this! I tweaked it to pull from the 1day sensor but needed to ignore the first ~20 mins of each day since that sensor doesn't reset to 0 exactly when the day changes (usually happens between 00:06 and 00:15 in my case). Photo showing this below:

image
template:
  - trigger:
      - platform: state
        entity_id: sensor.YOUR_EMPORIA_VUE_SENSOR_123_1d
        to: # Skip attribute-only changes.
    sensor:
      - name: "Derived Grid Consumption 1 Day"
        unique_id: "derived_grid_consumption_1_day"
        device_class: "energy"
        unit_of_measurement: "kWh"
        state_class: "total_increasing"
        state: >
          {% set last = states("sensor.derived_grid_consumption_1_day") | float(0) %}
          {% if trigger.from_state.state == 'unknown'
            or trigger.from_state.state == 'unavailable'
            or trigger.to_state.state == 'unknown'
            or trigger.to_state.state == 'unavailable' %}
            {{ last }}
          {% elif as_local(trigger.to_state.last_changed).strftime("%H")|int == 0 and as_local(trigger.to_state.last_changed).strftime('%M')|int < 20 %}
            {# Reset to 0 for first 20 minutes of the day (to handle the emporia sensor's delayed reset to 0) #}
            {{ 0 }}
          {% else %}
            {% set from = trigger.from_state.state | float %}
            {% set to = trigger.to_state.state | float %}
            {% if to - from > 0 %}
              {# Energy used - add to previous value #} 
              {{ (last + to - from) | round(3) }}
            {% else %}
              {{ last | round(3) }}
            {% endif %}
          {% endif %}
      - name: "Derived Grid Return 1 Day"
        unique_id: "derived_grid_return_1_day"
        device_class: "energy"
        unit_of_measurement: "kWh"
        state_class: "total_increasing"
        state: >
          {% set last = states("sensor.derived_grid_return_1_day") | float(0) %}
          {% if trigger.from_state.state == 'unknown'
            or trigger.from_state.state == 'unavailable'
            or trigger.to_state.state == 'unknown'
            or trigger.to_state.state == 'unavailable' %}
            {{ last }}
          {% elif as_local(trigger.to_state.last_changed).strftime("%H")|int == 0 and as_local(trigger.to_state.last_changed).strftime('%M')|int < 20 %}
            {# Reset to 0 for first 20 minutes of the day (to handle the emporia sensor's delayed reset to 0) #}
            {{ 0 }}
          {% else %}
            {% set from = trigger.from_state.state | float %}
            {% set to = trigger.to_state.state | float %}
            {% if to - from > 0 %}
              {{ last | round(3) }}
            {% else %}
              {# Energy returned - add to previous value #} 
              {{ (last + from - to) | round(3) }}
            {% endif %}
          {% endif %}

This creates two new sensors that can be added to the energy dashboard: image

powdahound avatar Jun 23 '22 13:06 powdahound