Powercalc - Virtual power sensors

Your example also works with me. Thanks! Helps me to build up from there.

Still would love to get some ‘mushroom’ style also in the underlying layer. Anybody have any idea how to pull that off?

type: custom:fold-entity-row
head:
  type: custom:mushroom-light-card
  entity: sensor.other_measured_devices_power
  icon: mdi:dishwasher
  style: |
    ha-card {
       box-shadow: none;
    }
entities:
  - type: custom:auto-entities
    card:
      type: entities
    filter:
      template: |
        {{state_attr("sensor.other_measured_devices_power", "entities") }}
      exclude:
        - state: unavailable
        - state: '= 0'
    sort:
      method: state
      reverse: true
      numeric: true

Gives:

In the option-section you can paste the card you want it to be, example from my media-player card:

type: custom:auto-entities
card:
  type: entities
filter:
  include:
    - domain: media_player
      state: playing
      options:
        type: custom:mushroom-media-player-card
        use_media_info: false
        show_volume_level: true
        icon_type: entity-picture
        volume_controls:
          - volume_set
          - volume_buttons
          - volume_mute
        collapsible_controls: false
        card_mod:
          style: |
            ha-card {
              box-shadow: none;
            }

I’m using Powercalc for quite some time already and it works fine. But recently I got strange error; one of my sensors stopped to be created.

  # Garden Lights
  - platform: powercalc
    entity_id: light.shelly_garden_lights
    name: Garden Light
    unique_id: garden_light_power
    fixed:
      power: 120
    standby_power: 1

I have several sensors configured exactly the same way and all of them work as expected.
Recently shelly unit controlling garden lights failed and I replaced it with the new one. After some initial issues to restore device’s and entities’ names to original state everything works fine, but this particular Powercalc sensor.
Related entity (light.shelly_garden_lights) exists and properly changes its state. I do not see any errors from Powercalc in log. What could be wrong here?

Thanks but the issue seems to be that if you define the filter as ‘template’ you cannot use the options within that. You can only use the options under ‘include’ (like in your example).

So trying to re-create an include that gives me the same result as the template. Not easy…

So below is already better but the combination of attribute filter ‘power’ combines with integration ‘powercalc’ does only show a small set of the power sensors. Further testing shows it’s the integration: powercalc filter that does not return all powercalc sensors (if I remove other filters).

It seems that sensors created lik below do not get tagged with integration ‘powercalc’ only the ones that are created virtually.

Another drawback is that the powercalc groups do not play nice in auto-entities. You would expect group: sensor.all_powercalc_power to work as a group filter (like it does for instance for lights or media players, but auto-entities does not play nice. @bramski Is there anything you can do about this or is this 100% on auto-entity side?

Not tagges with powercalc as integration
    - create_group: Other measured devices
      entities:
        - entity_id: switch.zigbeeplug_tv_power
          power_sensor_id: sensor.zigbeeplug_tv_power
        - entity_id: switch.zigbeeplug_aquarium
          power_sensor_id: sensor.zigbeeplug_aquarium_power
          name: CV Ketel

type: custom:auto-entities
card:
  type: vertical-stack
card_param: cards
filter:
  include:
    - attributes:
        device_class: power
      integration: powercalc
      options:
        type: custom:mushroom-entity-card
        entities:
          - this.entity_id
  exclude:
    - state: unavailable
    - state: '= 0'
sort:
  method: state
  reverse: true
  numeric: true

auto entities looks at entity_id attribute of the group entity, powercalc defined the child entities in entities attribute, so that’s why the group filter not works. I don’t want to change that as lot of users may already depend on that. So there must be a very good reason to do so.

I understand & respect that, but maybe there is a way powercalc could (optional) create another entity eg a a ‘real’ group next to the ‘powercalc’ group? That way you maintain existing functionality but at the same time facilitate new functionality. ‘Real’ groups (and their benefits) are use-full in many cases. posted it on your github.

Alternatively I found this. Need to investigate

Only an idea, but I don’t use these auto-entities: why not add the second as well, so you don’t have to remove the existing.

Ok. Seems there is a way around this.

You can actually create dynamic groups (I did not know of) by calling group.set service like the example below. This will create a ‘real’ group called (in this case) group.test_powercalc which then behaves like a normal group and therefore can also be used by -for instance- auto entities to filter on.

I think these are non-persistent and will need to be called at startup.

service: group.set
data:
  object_id: test_powercalc
  entities: >-
     {{state_attr("sensor.other_measured_devices_power", "entities") }}
1 Like

It is not good practice for integrations to put much data in the attributes as this needs to be written on every state change, and also quickly adds to the database size.
So I want to adhere to that as much as possible.

1 Like

Would like to add price for each entity added by the powercalc. Is this possible to do easly?

I have added the integration. All my Hue lights are found and there are sensors created for them.

But my Hue smart switch (LOM007) is not found. Do you have to add those switches manual?

So now we found a way to create ‘real groups’ we can create some better looking powercalc views. Sharing mine below.

p.s. the ‘real groups’ are becoming really interesting as from version 2023.2 it seems you can use statistics on sensor groups.

When pulled down:

Code has become pretty long and you will need to adapt:
type: vertical-stack
cards:
  - type: custom:stack-in-card
    cards:
      - type: horizontal-stack
        cards:
          - type: custom:mushroom-template-card
            entity: sensor.power_consumption
            primary: P1 Meter
            secondary: >
              {{ (states('sensor.power_consumption') | round(3) * 1000) | int }}
              W
            icon_color: >
              {% set power = (states('sensor.power_consumption') | round(3) *
              1000) | int %} {% if power < 300 %} green {% elif power < 400 %}
              blue {% elif power < 600 %} amber {% elif power < 1500 %} red {%
              else %} grey {% endif %}
            icon: mdi:counter
            card_mod:
              style: |
                ha-card {
                  --ha-card-border-width: 0;
                  --ha-card-box-shadow: 0;
                }
          - type: custom:mini-graph-card
            entities:
              - entity: sensor.power_consumption
            hours_to_show: 24
            color_thresholds:
              - color: '#228B22'
                value: 0
              - color: '#d35400'
                value: 0.1
              - color: '#c0392b'
                value: 1.5
            group_by: hour
            line_width: 2
            animate: false
            show:
              name: false
              icon: false
              state: false
              legend: false
              fill: true
              graph: bar
  - type: horizontal-stack
    cards:
      - type: entities
        entities:
          - type: custom:fold-entity-row
            head:
              type: custom:mushroom-template-card
              entity: sensor.other_measured_devices_power
              primary: Other Devices
              secondary: |
                {{ states('sensor.other_measured_devices_power') | round(0) }} W
              icon_color: >
                {% set power = states('sensor.other_measured_devices_power') |
                int %} {% if power < 160 %} green {% elif power < 200 %} blue {%
                elif power < 300 %} amber {% elif power < 400 %} red {% else %}
                red {% endif %}
              icon: mdi:dishwasher
            padding: 80
            entities:
              - type: custom:auto-entities
                filter:
                  include:
                    - group: group.other_measured_devices_powercalc
                      options:
                        type: custom:mushroom-entity-card
                        icon_color: light-blue
                        tap_action:
                          action: more-info
                  exclude:
                    - state: unavailable
                    - state: < 2'
                card:
                  type: custom:layout-card
                  cards: []
                  layout_type: masonry
                sort:
                  method: state
                  reverse: true
                  numeric: true
            card_mod:
              style: |
                :host {
                  --masonry-view-card-margin: -12px 8px 0px 8px; 
                  --ha-card-border-width: 0;
                  --ha-card-background: none;
                  --ha-card-box-shadow: 0;
                }
        card_mod:
          style:
            fold-entity-row$: |
              ha-icon {
                background: none !important;
                margin-right: 24px !important;
                --toggle-icon-width: 21px !important;
                color: rgb(var(--rgb-disabled-color));
              }
            .: |
              .card-content {
                padding: 0;
              }
      - type: entities
        entities:
          - type: custom:fold-entity-row
            head:
              type: custom:mushroom-template-card
              entity: sensor.ground_floor_lights_power
              primary: Lights L0
              secondary: |
                {{ states('sensor.ground_floor_lights_power') | round(0) }} W
              icon_color: >
                {% set power = states('sensor.ground_floor_lights_power') | int
                %} {% if power < 160 %} green {% elif power < 200 %} blue {%
                elif power < 300 %} amber {% elif power < 400 %} red {% else %}
                red {% endif %}
              icon: mdi:numeric-0-box
            padding: 80
            entities:
              - type: custom:auto-entities
                filter:
                  include:
                    - group: group.ground_floor_lights_power_powercalc
                      options:
                        type: custom:mushroom-entity-card
                        icon_color: light-blue
                        tap_action:
                          action: more-info
                  exclude:
                    - state: unavailable
                    - state: < 2'
                card:
                  type: custom:layout-card
                  cards: []
                  layout_type: masonry
                sort:
                  method: state
                  reverse: true
                  numeric: true
            card_mod:
              style: |
                :host {
                  --masonry-view-card-margin: -12px 8px 0px 8px; 
                  --ha-card-border-width: 0;
                  --ha-card-background: none;
                  --ha-card-box-shadow: 0;
                }
        card_mod:
          style:
            fold-entity-row$: |
              ha-icon {
                background: none !important;
                margin-right: 24px !important;
                --toggle-icon-width: 21px !important;
                color: rgb(var(--rgb-disabled-color));
              }
            .: |
              .card-content {
                padding: 0;
              }
  - type: horizontal-stack
    cards:
      - type: entities
        entities:
          - type: custom:fold-entity-row
            head:
              type: custom:mushroom-template-card
              entity: sensor.first_floor_lights_power
              primary: Lights L1
              secondary: |
                {{ states('sensor.first_floor_lights_power') | round(0) }} W
              icon_color: >
                {% set power = states('sensor.first_floor_lights_power') | int
                %} {% if power < 160 %} green {% elif power < 200 %} blue {%
                elif power < 300 %} amber {% elif power < 400 %} red {% else %}
                red {% endif %}
              icon: mdi:numeric-1-box
            padding: 80
            entities:
              - type: custom:auto-entities
                filter:
                  include:
                    - group: group.first_floor_lights_power_powercalc
                      options:
                        type: custom:mushroom-entity-card
                        icon_color: light-blue
                        tap_action:
                          action: more-info
                  exclude:
                    - state: unavailable
                    - state: < 2'
                card:
                  type: custom:layout-card
                  cards: []
                  layout_type: masonry
                sort:
                  method: state
                  reverse: true
                  numeric: true
            card_mod:
              style: |
                :host {
                  --masonry-view-card-margin: -12px 8px 0px 8px; 
                  --ha-card-border-width: 0;
                  --ha-card-background: none;
                  --ha-card-box-shadow: 0;
                }
        card_mod:
          style:
            fold-entity-row$: |
              ha-icon {
                background: none !important;
                margin-right: 24px !important;
                --toggle-icon-width: 21px !important;
                color: rgb(var(--rgb-disabled-color));
              }
            .: |
              .card-content {
                padding: 0;
              }
      - type: entities
        entities:
          - type: custom:fold-entity-row
            head:
              type: custom:mushroom-template-card
              entity: sensor.second_floor_lights_power
              primary: Lights L2
              secondary: |
                {{ states('sensor.second_floor_lights_power') | round(0) }} W
              icon_color: >
                {% set power = states('sensor.second_floor_lights_power') | int
                %} {% if power < 160 %} green {% elif power < 200 %} blue {%
                elif power < 300 %} amber {% elif power < 400 %} red {% else %}
                red {% endif %}
              icon: mdi:numeric-2-box
            padding: 80
            entities:
              - type: custom:auto-entities
                filter:
                  include:
                    - group: group.second_floor_lights_power_powercalc
                      options:
                        type: custom:mushroom-entity-card
                        icon_color: light-blue
                        tap_action:
                          action: more-info
                  exclude:
                    - state: unavailable
                    - state: < 2'
                card:
                  type: custom:layout-card
                  cards: []
                  layout_type: masonry
                sort:
                  method: state
                  reverse: true
                  numeric: true
            card_mod:
              style: |
                :host {
                  --masonry-view-card-margin: -12px 8px 0px 8px; 
                  --ha-card-border-width: 0;
                  --ha-card-background: none;
                  --ha-card-box-shadow: 0;
                }
        card_mod:
          style:
            fold-entity-row$: |
              ha-icon {
                background: none !important;
                margin-right: 24px !important;
                --toggle-icon-width: 21px !important;
                color: rgb(var(--rgb-disabled-color));
              }
            .: |
              .card-content {
                padding: 0;
              }
  - type: horizontal-stack
    cards:
      - type: entities
        entities:
          - type: custom:fold-entity-row
            head:
              type: custom:mushroom-template-card
              entity: sensor.garden_lights_power
              primary: Garden
              secondary: |
                {{ states('sensor.garden_lights_power') | round(0) }} W
              icon_color: >
                {% set power = states('sensor.garden_lights_power') | int %} {%
                if power < 160 %} green {% elif power < 200 %} blue {% elif
                power < 300 %} amber {% elif power < 400 %} red {% else %} red
                {% endif %}
              icon: mdi:flower
            padding: 80
            entities:
              - type: custom:auto-entities
                filter:
                  include:
                    - group: group.garden_lights_power_powercalc
                      options:
                        type: custom:mushroom-entity-card
                        icon_color: light-blue
                        tap_action:
                          action: more-info
                  exclude:
                    - state: unavailable
                    - state: < 2'
                card:
                  type: custom:layout-card
                  cards: []
                  layout_type: masonry
                sort:
                  method: state
                  reverse: true
                  numeric: true
            card_mod:
              style: |
                :host {
                  --masonry-view-card-margin: -12px 8px 0px 8px; 
                  --ha-card-border-width: 0;
                  --ha-card-background: none;
                  --ha-card-box-shadow: 0;
                }
        card_mod:
          style:
            fold-entity-row$: |
              ha-icon {
                background: none !important;
                margin-right: 24px !important;
                --toggle-icon-width: 21px !important;
                color: rgb(var(--rgb-disabled-color));
              }
            .: |
              .card-content {
                padding: 0;
              }
      - type: entities
        entities:
          - type: custom:fold-entity-row
            head:
              type: custom:mushroom-template-card
              entity: sensor.all_sonos_and_home_power
              primary: Sonos & Home
              secondary: |
                {{ states('sensor.all_sonos_and_home_power') | round(0) }} W
              icon_color: >
                {% set power = states('sensor.all_sonos_and_home_power') | int
                %} {% if power < 160 %} green {% elif power < 200 %} blue {%
                elif power < 300 %} amber {% elif power < 400 %} red {% else %}
                red {% endif %}
              icon: mdi:google
            padding: 80
            entities:
              - type: custom:auto-entities
                filter:
                  include:
                    - group: group.all_sonos_and_home_power_powercalc
                      options:
                        type: custom:mushroom-entity-card
                        icon_color: light-blue
                        tap_action:
                          action: more-info
                  exclude:
                    - state: unavailable
                    - state: < 2'
                card:
                  type: custom:layout-card
                  cards: []
                  layout_type: masonry
                sort:
                  method: state
                  reverse: true
                  numeric: true
            card_mod:
              style: |
                :host {
                  --masonry-view-card-margin: -12px 8px 0px 8px; 
                  --ha-card-border-width: 0;
                  --ha-card-background: none;
                  --ha-card-box-shadow: 0;
                }
        card_mod:
          style:
            fold-entity-row$: |
              ha-icon {
                background: none !important;
                margin-right: 24px !important;
                --toggle-icon-width: 21px !important;
                color: rgb(var(--rgb-disabled-color));
              }
            .: |
              .card-content {
                padding: 0;
              }

2 Likes

Cool, nice to see what people come up with. Looks very nice.

I don’t think this is supported by HA yet. Powercalc does not provide pricing. I think there was a topic about it in WTH to also have pricing for individual entities.
Or you might build something yourself with some template sensors.

Should be auto discovered. You can enable debug logging which should give some clues as to what model is detected by powercalc. Maybe this somehow does not match the model in the database.

This is showed in the log:

2023-02-03 08:07:50.377 DEBUG (MainThread) [custom_components.powercalc.discovery] light.spots_achtertuin: Auto discovered model (manufacturer=Signify Netherlands B.V., model=Hue smart plug (LOM007))

But what I noticed is that there is not a second line in the log like this:

2023-02-03 08:07:50.314 DEBUG (MainThread) [custom_components.powercalc.discovery] light.luifel_garage_deur: Auto discovered model (manufacturer=Signify Netherlands B.V., model=Hue color spot (LCT003))
2023-02-03 08:07:50.316 DEBUG (MainThread) [custom_components.powercalc.discovery] light.luifel_garage_deur: Already setup with discovery, skipping new discovery

2023-02-03 08:07:50.366 DEBUG (MainThread) [custom_components.powercalc.discovery] switch.tv_woonkamer_power_plug: Auto discovered model (manufacturer=Shelly, model=Shelly Plug S)
2023-02-03 08:07:50.367 DEBUG (MainThread) [custom_components.powercalc.discovery] switch.tv_woonkamer_power_plug: Already setup with discovery, skipping new discovery


Do I need to manually add it?

Strange, could you go forward and create an issue on github? Please include the full logs after startup with debug enabled.

I recently added a couple Emporia Vue Gen 2 energy monitors to my main panel and subpanel. Even with all of current sensors installed, I have ~20 circuits which are unmonitored. So, I’m initially using them to find the power curves for each of my loads (e.g. dimmable lights via Excel and trendlines, electronics, and basically anything else that has a state monitored/controlled via HA). Thanks to your integration, I’ll be able to monitor them as well as my higher load and non-HA monitored circuits with the Vue. Thank you.

Now that I have the power curve equations, I’m starting to create the Powercalc sensors. After making a few in the UI and getting a good sensor template and overall configuration with the necessary parameters, I’d like to switch to yaml to more quickly configure the remaining sensors.

Where can I find the yaml created by the UI, so I can copy/paste that into my configuration.yaml?

I could go all yaml, but I’ll probably use a mix of UI and yaml Powercalc sensors. Does Powercalc allow for a mixed configuration like this?

You can’t, it’s a completely separate setup routine in fact in HA. UI entries don’t have a corresponding YAML configuration.

Sure you can mix both, no problem.

1 Like

Thank you for this great integration, it has proved to be very helpful in tracking the energy usage.

I had several light groups defined in configuration.yaml and they had worked well for few months. But now when I migrated HA and some other stuff (HA from Docker to HAOS VM, zigbee2mqtt to Docker) to new platform, I noticed that the powercalc grouped entities had stopped working. I’m not sure what had changed in the migration (nothing should’ve as such), but with debugging I was able to trace the problem to “could not resolve any entities in group…” error and then I noticed also one line saying that a particular light was missing (but only for one light, in the indoor group). Light was not missing as a zigbee entity but the debug log was pointing to its original id from the time I linked it. I then removed the light from under Powercalc in UI (in integrations screen), and indoor group started working. From additional “could not resolve…” messages I deducted that something was wrong with light in one other group (on lowest level of nested groups for outdoor lights), even though I was not able to see any similar error that would have pointed to old id as with the indoor light. Anyhow, removing every light related to this sub group in Powercalc integration via UI finally led to victory. All working again.

Is there some obvious error in what I did? Should I have removed the instances I had in UI under Integrations / Powercalc to begin with so that they are not in two places? I still have some of the lights left there, the ones that did not cause any errors. So I wonder why (only) some of them started behaving badly at this point. They are zigbee bulbs and coming to HA via mqtt (zigbee2mqtt + mqtt server running on another VM) and I guess I might have changed the name in zigbee2mqtt after linking them while they were already auto dicovered in HA. So the name changed at the very beginning (few months ago). And now some of the error messages I saw in debug log hinted that there could’ve been a reference in powercalc to the original name while in yaml I was using the current names. But as said, everyhing worked until few days ago when I did the migration. So - all good for now but to avoid this hassle in future, looking for advice where I did wrong and how to prevent this from happening in future? :slight_smile:

Btw, I should mention I did not find a way to reload the powercalc groups without a HA restart, took a bit of time with several restarts. Is there some better way to do this?