Powercalc - Virtual power sensors

I’m trying to clean up the interface and experimenting with the Lovelace-fold-entity-row

One of the objectives is to filter anything that has 0

However that addition of state under include does not yield any results. Tried variations but it either shows nothing or all sensors (incl 0). Also tried >1 in case there was some small value.

Any suggestions? It might be caused by how the entities are pulled from the ‘grouped’ sensor? Can it somehow be included in the template under filter?

type: custom:fold-entity-row
head:
  type: custom:mushroom-light-card
  entity: sensor.other_measured_devices_power
  name: All other measured devices
  icon: mdi:power-plug
entities:
  - type: custom:auto-entities
    filter:
      template: |
        {{state_attr("sensor.other_measured_devices_power", "entities") }}
      include:
        state: "> 0"
    card:
      type: custom:layout-card
    sort:
      method: state
      reverse: true
      numeric: true

I don’t know, I don’t see why this wouldn’t work.
When you evaluate this in developer tools {{state_attr("sensor.pwrctrl_use_heating_power", "entities") }} is it also returning the sensor.icehouse_heater_power entity_id?
I suggest you are better of asking this on auto entities topic or issue tracker, as this is not really specifically powercalc related.

Looking at auto entities documentation. It includes both filter.template and include entities, and than excludes any entities indicated with exclude.
So you should probably use exclude.

Something like this:

filter:
  template: |
    {{state_attr("sensor.other_measured_devices_power", "entities") }}
  exclude:
    state: "= 0"

Unfortunately that does work. I have now tried many things and I can get it to work with non powercalc ‘groups’. Are you sure it’s not related to @Mariusthvdb his post here? Concerning entity_id

from dev tools.

then the card;

I agree, it is not a powercalc-bug, but I got this idea from you, and I think it will be brilliant for everyone using powercalc-groups, so I took a shot and hoped you had a solution :slight_smile:
(Hoping it was something basic I’d missed)

I’ll do some more testing, and report to Auto Entities topic if I can’t figure it out :+1:

That should be unrelated, it’s only a suggested other way to include entities in the auto entities list, but you don’t have any issues with that. I did have a look into that 2 weeks ago but I cannot change that in powercalc btw because things are hardcoded in HA core.

Anyway back to the topic of excluding 0 watt entities.
I tested this on my installation and it’s working fine. Previously I had 8 entities having 0 watt, after changing the configuration all the 0 watt entities disappeared.

type: custom:fold-entity-row
head: sensor.alle_verlichting_power
entities:
  - type: custom:auto-entities
    card:
      type: entities
    filter:
      template: |
        {{state_attr("sensor.alle_verlichting_power", "entities") }}
      exclude:
        - state: unavailable
        - state: '= 0'
    sort:
      method: state
      reverse: true
      numeric: true

Not sure why this is not working on your installation. I suggest to create an issue on auto entities github when you can’t get the exclude to work properly.

I didnt think of sorting away lights that were off (using less than 1 watt) it made my list a lot cleaner, thank you, dudes!

      - type: custom:fold-entity-row
        padding: -5
        head:
          entity: sensor.kjent_stromforbruk
          name: Sanntidsforbruk
          tap_action:
            action: fire-dom-event
            fold_row: true
        entities:
          - type: custom:auto-entities
            card:
              type: entities
              style: |
                ha-card{
                  box-shadow: none;
                  background: none;
                  padding: 0px;

                }
            filter:
              include:
                - name: '*[Ss]anntid*'
                  options:
                    type: custom:template-entity-row
                    state: '{{states(''this.entity_id'') | int}} W'
                    name: >-
                      {{state_attr('this.entity_id','friendly_name').split('Sanntid')[0]}}
              exclude:
                - entity_id: sensor.eva_meter_reader_smartenergymetering
                - entity_id: sensor.billader_power
                - state: '< 0.9'
            sort:
              method: state
              reverse: true
              numeric: true

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.