Can't create graph statistics card for wattage sensors?

just installed a new energy meter with 16 sensors in my electric panel. getting W, V, A, kWh sensors, but can only graph kWh. if my my wattage entity isn’t showing up as an option for the graph card, does that mean I can use the recorder function in yaml to make them graphable?

Note you can only graph one unit at a time, so make sure you clear any pre-exisitng entities from the card before checking just to be sure.

Are your other entities enabled for statistics? They must have a state_class attribute to record statistics.

I’m not sure. the sensors are added by config.yaml to be added to mqtt like this small sample of the many sensors. That probably doesn’t answer your question, because they all look about the same. Assuming the way they work is kWh have the state_class attribute and the rest don’t. Is there a way to manually add that or force it?

mqtt:
  sensor:
    - name: "1 channel voltage"
      unique_id: channel_1_voltage
      state_topic: "SEMMETER/A085E3FD19FA/HA"
      value_template: "{{ (value_json.sense[0][0] | float | multiply(0.1)) | round(2) }}"
      unit_of_measurement: "V"
      icon: "mdi:flash"
      device:
        name: "SEM Meter"
        identifiers: "SEM Meter"
        manufacturer: "Fusion Energy"

    - name: "1 channel current"
      unique_id: channel_1_current
      state_topic: "SEMMETER/A085E3FD19FA/HA"
      value_template: "{{ (value_json.sense[0][1] | float | multiply(0.02)) | round(2) }}"
      unit_of_measurement: "A"
      icon: "mdi:current-ac"
      device:
        name: "SEM Meter"
        identifiers: "SEM Meter"
        manufacturer: "Fusion Energy"

    - name: "1 channel Wattage"
      unique_id: channel_1_wattage
      state_topic: "SEMMETER/A085E3FD19FA/HA"
      value_template: "{{ (value_json.sense[0][2] | float | multiply(0.02)) | round(2) }}"
      unit_of_measurement: "W"
      icon: "mdi:power-plug"
      device:
        name: "SEM Meter"
        identifiers: "SEM Meter"
        manufacturer: "Fusion Energy"

    - name: "1 channel Kilowatt Hours"
      unique_id: channel_1_kwh
      state_topic: "SEMMETER/A085E3FD19FA/HA"
      value_template: "{{ (value_json.sense[0][3] | float | multiply(0.002)) | round(2) }}"
      unit_of_measurement: "kWh"
      icon: "mdi:counter"
      device_class: energy
      state_class: total_increasing
      device:
        name: "SEM Meter"
        identifiers: "SEM Meter"
        manufacturer: "Fusion Energy"

You can add a state class to a mqtt sensor:

https://www.home-assistant.io/integrations/sensor.mqtt/#state_class

do you know where I could find an example of how to use it? that’s over my head, and I don’t see any examples in the documentation after reading it. I struggle to get anything out of HA docs unless examples are given.

In this instance, it’s probably just a matter of adding one line to each sensor, for example:

mqtt:
  sensor:
    - name: "1 channel voltage"
      state_class: measurement
      unique_id: channel_1_voltage
      state_topic: "SEMMETER/A085E3FD19FA/HA"
      value_template: "{{ (value_json.sense[0][0] | float | multiply(0.1)) | round(2) }}"
      unit_of_measurement: "V"
      icon: "mdi:flash"
      device:
        name: "SEM Meter"
        identifiers: "SEM Meter"
        manufacturer: "Fusion Energy"

I will try that! thanks! will let you know, but that sounds believable for sure, lol.

Can I ask one more question about graph card before I do? of course I graphed the one I could kWh, but don’t see any settings in the card of when to reset the values. I would maybe have one view that resets daily and another around electric bill cutoff date, but it appears it will just keep going up and up forever, afaik…

I can’t answer that one, but perhaps someone else here can.

something basic I really don’t understand about the statistics graph card. I only added that state_class: measurement to one sensor, reloaded all yaml in developer tools and looked for the results, but didn’t find any. maybe I have to wait a bit? but I can go into the sensors list under mqtt integration and click wattage, voltage, and amperage sensors on any of them and get something like this, so why doesn’t the graph card see them? data is obviously being stored. I use graphs like this all the time for tracking battery levels and things like that, but maybe that is a different card?

I might be wrong, but I think that the change to add the state_class is not retrospective. In other words, it won’t “rehabilitate” the prior data so that HA sees it as a measurement. It will only work for data collected after the change (assuming it works…)

it’s a graph card. adding a battery tracker graph card just works…

Why not try the energy dashboard? This will then give you daily, weekly, monthly, etc.

I totally plan to do that too, just playing around with dashboards for my new sensors and hitting a brick wall.

In case anyone finds this, a couple of my responses back was my clue to the actual solution to my original question… I was asking the wrong question. Solution: use the history card, not the graph statistics card. Then you won’t need to add state class, all the sensors were always there under the history card which is actually the kind of graphing card I was looking for. @d921 was 100% correct though in his answer to my question. If I really did want to use the statistics card, then adding state class to each sensor solved that, because I could then add the sensors to the statistics card. In the end, I removed the state class attribute because I didn’t need that for what I was doing.

Home Assistant critique and compliment: Why the heck does history card have such an ugly example when adding from gui? Maybe it should be renamed or have a better sample image? It can be a graphing card too, depending on the entity, which makes it kind of weird to predict which behavior will do.

I was pretty impressed when after removing the state class attribute from my sensor, in a little while I got a repair notification saying the state class was missing and I could delete the data from database or edit yaml to repair. Very cool!