Powercalc - Virtual power sensors

you can’t mix fixed and composite in the “root” of the configuration.
It’s either one of them.

Anyway for what you want to do it’s much easier to define as follows:

  - platform: powercalc
    entity_id: sensor.status_solaredgeomvormer
    fixed:
      power: "{{ iif(is_state('sensor.current_solar_power_production', '0), '2.5', '0') }}"

Or use calculation_enabled_condition, then the fixed strategy will only be applied when this condition evaluates to true:

  - platform: powercalc
    entity_id: sensor.status_solaredgeomvormer
    calculation_enabled_condition: "{{ is_state('sensor.current_solar_power_production', '0') }}" 
    fixed:
      power: 2.5

Both untested, but should work.

1 Like

You can do it like this:

configuration.yaml

powercalc: !include includes/powercalc.yaml

/config/includes/powercalc.yaml

#######################################
# PowerCalc
#-|---|---|---|---|---|---|---|---|---|
enable_autodiscovery: false
energy_sensor_naming: "{} ENERGY Total"
energy_sensor_friendly_naming: "{} ENERGY Total"
power_sensor_naming: "{} POWER Current"
power_sensor_friendly_naming: "{} POWER Current"
sensors:
  - create_group: Alle Lichter
    entities:
      -  entity_id: light.flur
         manufacturer: signify
         model: LTW013
         multiply_factor: 4
         multiply_factor_standby: true
      -  entity_id: light.flur_eingang
         manufacturer: signify
         model: LTW013
         multiply_factor: 4
         multiply_factor_standby: true
      -  entity_id: light.zha_schlafzimmer_licht
         manufacturer: signify
         model: LTA001
      -  entity_id: light.zha_kueche_licht
         manufacturer: signify
         model: 3216331P6
      -  entity_id: light.wohnzimmer_licht
         manufacturer: signify
         model: 5060830P7 #3er Spot
      -  entity_id: light.zha_wohnzimmer_schreibtisch_licht
         manufacturer: signify
         model: LST002
      -  entity_id: light.wohnzimmer_couch_licht
         manufacturer: signify
         model: LCT024
         multiply_factor: 2
         multiply_factor_standby: true
  - create_group: Alle EchoDots
    entities:
      - entity_id: media_player.badezimmer_echo_dot
        manufacturer: amazon
        model: D91029T
      - entity_id: media_player.schlafzimmer_echo_dot
        manufacturer: amazon
        model: D91029T
      - entity_id: media_player.wohnzimmer_echo_dot
        manufacturer: amazon
        model: D91029T

this is how i use it currently

2 Likes

Great, thanks! Next time this happens, I’ll use the function instead of deleting and recreating the sensor.

Thanks, will find some spare time to upgrade and make the changes later this week. I’ll report back if there are issues…

Thank you! I didn’t realize you could do that!

Thank you @bramski

Hi everyone, i’ve just discovered this very neat integration. thanks for creating this.
I’ve tried to use it via a yaml configuration, but somehow this kind of simple example doesn’t work.
I want a different fixed power of my “Shelly Plus Plug S” when it’s state is enabled (0.5w) or disabled (0.3w).

But somehow, this sensor displays 0.5w when enabled and 0w when disabled. What is wrong?

#
# powercalc.yaml
#
power_sensor_naming: "{} Device Power"
create_energy_sensors: true
energy_sensor_naming: "{} Device Energy"
create_utility_meters: false

sensors:
  - entity_id: switch.steckdose_messung
    fixed:
      power: "{{ iif(is_state('switch.steckdose_messung', 'on'), '0.5', '0.3') }}"

The jinja template is working fine in the developer tools.

Thanks a lot for helping!

OFF state is a special case for powercalc.
Your example can be rewritten as follows:

sensors:
  - entity_id: switch.steckdose_messung
    fixed:
      power: 0.5
    standby_power: 0.3

As powercalc will already look at the state of entity_id and use 0.5 when it is on. when it is off it will look at standby_power 0.3

1 Like

Thanks, it works perfectly!

1 Like

I’m using Powercalc for some of my power draws. I have set it to give me utility meters for daily, weekly, monthly and yearly periods. My other utility meters (set up via utility meter helpers) give me daily, weekly, monthly, monthly with offset and yearly.

My initial question was going to be how do I get a utility meter with an offset using powercalc - but I saw an (undocumented?) capability earlier in this thread using the global setting of:

utility_meter_offset:
days: 13
hours: 00
minutes: 0

If this works, I have a couple of questions -

  1. does this offset only apply to the monthly utility meter or will it affect the yearly meter as well?
  2. I would like to have both a monthly and a “monthly with offset” meter. What’s the best way to do this?

Here is what I am currently trying:

#######################################
# PowerCalc
#-|---|---|---|---|---|---|---|---|---|
create_utility_meters: true
enable_autodiscovery: false
energy_sensor_precision: 3
utility_meter_types:
  - daily
  - weekly
  - yearly
  - monthly

utility_meter_offset:
  days: 15
  hours: 10
  minutes: 0  
  
  
sensors:
  - create_group: Power Calc All Entities
    entities:

#   Furnace Air Cleaner
      - entity_id: switch.plug_furnace_air_cleaner_state
        fixed:
          power: 108
        
#   Alexa & Google smart speakers & devices (20 - always on) - total fixed energy per day      
      - name: All Alexa & Google Smart speakers
        daily_fixed_energy:
          value: 45
          unit_of_measurement: W
          update_frequency: 60

        
##  Power Calc Group for Lights        
      - create_group: Power Calc Lights
        entities:
#   Living Room Lights
          - entity_id: light.living_room_ne_table_lamp
            fixed:
              power: 15
          - entity_id: light.living_room_sw_corner_lamp
            fixed:
              power: 15
          - entity_id: light.living_room_nw_corner_lamp
            fixed:
              power: 15


#   Outdoor Landscape & Patio Lights
          - entity_id: light.rear_deck_patio_outlet
            fixed:
              power: 132
          - entity_id: light.rear_deck_wall_lamp
            fixed:
              power: 16.5
          - entity_id: light.front_hall_front_patio_lght
            fixed:
              power: 25

#   Family Room Lights
          - entity_id: light.family_room_bookcase_light_2
            fixed:
              power: 13.5
          - entity_id: light.family_room_pedestal_light_2
            fixed:
              power: 17
          - entity_id: light.family_room_stairs_light
            fixed:
              power: 9.7

#   Closet (202)
          - entity_id: light.bedroom_mid_frnt_mn_dr_left_side
            fixed:
              power: 30

#   Other Basement Office and Gear Room
          - entity_id: light.basement_office_wall_switch_lt
            fixed:
              power: 15
          - entity_id: switch.gear_room_plug_switch_1
            fixed:
              power: 11


#   Garage Lights
          - entity_id: light.garage_side_door_light
            fixed:
              power: 22
          - entity_id: light.front_hall_garage_lights_od
            fixed:
              power: 72


#   Master Bedroom bed lights
          - entity_id: light.master_bedroom_wall_switch_plug
            fixed:
              power: 11
          - entity_id: light.master_bedroom_mstr_bdrm_crnr_l
            fixed:
              power: 11

#   Theatre lights
          - entity_id: light.theatre_thtre_exrcse_trk
            fixed:
              power: 12
          - entity_id: light.theatre_trk_lghtng_back
            fixed:
              power: 12
          - entity_id: light.theatre_pot_light_relay
            fixed:
              power: 30
          - entity_id: light.theatre_stair_btm_s_lte
            fixed:
              power: 45


#   Two entries for 2 switches for mudroom light  
          - entity_id: light.mud_room_mud_rm_inside_dr
            fixed:
              power: 15
          - entity_id: light.mud_room_mud_rom_back_dor
            fixed:
              power: 15

#    Michelle Office
          - entity_id: light.rear_bedroom_ceiling_light
            fixed:
              power: 15
#####

Hi, I will add this missing option to the documentation.

This option applies to all utility meters created by powercalc.
I’m not going to further complicate the configuration for such an edge case.

When you like to have different utility meter cycle/offset combinations I suggest to just create the utility meters with the helpers section, and set create_utility_meters: false in powercalc. Select the energy sensor generated by powercalc as the source of your utility meter.
In fact the utility meters created by powercalc are just using the same code as the helpers.
Only powercalc makes it more easy to create the utility meters, without having to add hundreds of them manually.

You could also set:

utility_meter_types:
  - daily
  - weekly
  - yearly

And create the monthly utility meter manually with the helpers.

Maybe not the answer you hoped on, but I hope it helps anyway.

1 Like

Oh my, i feel really stupid - but in order to follow the new Structures, i am struggeling with restructuring the Sensors, and in the same Time outsourcing it to a separate yaml.
Can somebody, maybe the Master @bramski himself :smiley: , see whats going wrong and assist me?

Given:
The old configuration.yaml (one Section with powercalc:, and all sensors been working like below:

sensor:
  - platform: powercalc
    (...)
  - platform: powercalc
    (...)

Now powercalc: !include powercalc.yaml in configuration.yaml is basically working.

This is the Results of my Trial-and-Error:

  • powercalc.yaml Configuration, and ONE sensor is working
  • powercalc.yaml Configuration, and TWO or more sensors is not working
enable_autodiscovery: false
energy_sensor_naming: energy_{}_kwh
disable_extended_attributes: true
sensors:
  - create_group: light.roomlight_azd
    unique_id: 5c0318fa-e7ed-11ed-a05b-0242ac120003
    hide_members: true
    unavailable_power: 0
    include:
      group: light.roomlight_azd


  - create_group: light.roomlight_azl
    unique_id: 5c031558-e7ed-11ed-a05b-0242ac120003
    hide_members: true
    unavailable_power: 0
    include:
      group: light.roomlight_azl
    entities:
      - entity_id: light.dimmable_light_23
        # Osram E27 Warmwhite 2
        linear:
          min_power: 0.5
          max_power: 8.5
        standby_power: 0.4
      - entity_id: light.dimmable_light_22
        # Osram E27 Warmwhite 1
        linear:
          min_power: 0.5
          max_power: 8.5
        standby_power: 0.4
      - entity_id: light.dimmable_light_21
        # Osram E14 Warmwhite 1
        linear:
          min_power: 0.4
          max_power: 5.0
        standby_power: 0.4

The Error when having two or more Sensor like this is:

Logger: homeassistant.setup
Source: custom_components/powercalc/__init__.py:225
Integration: powercalc (documentation, issues)
First occurred: 14:00:52 (1 occurrences)
Last logged: 14:00:52
Error during setup of component powercalc

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 288, in _async_setup_component
    result = await task
             ^^^^^^^^^^
  File "/config/custom_components/powercalc/__init__.py", line 225, in async_setup
    sorted_sensors = sorted(
                     ^^^^^^^
TypeError: '<' not supported between instances of 'NodeDictClass' and 'NodeDictClass'

After fiddeling around, i found out when using sensors: before every Sensor, there is no Error Log / Notification. But all beloved Sensors from Powercalc are “unavailable” (‘not longer provided by Powercalc…’).

What the Hell am i doing wrong?!

I am not really sure seeing this error. But I see you got some newlines between the first and second sensor. Pretty sure you can’t have newlines when defining array in YAML, so this could potentially be the issue.

Though i was pretty sure i already tried it, but rechecked it again - with again the same Error :frowning:
This powercalc.yaml (removed Newlines) leads to the same Error upon restart:

enable_autodiscovery: false
energy_sensor_naming: energy_{}_kwh
disable_extended_attributes: true
sensors:
  - create_group: light.roomlight_azd
    unique_id: 5c0318fa-e7ed-11ed-a05b-0242ac120003
    hide_members: true
    unavailable_power: 0
    include:
      group: light.roomlight_azd
  - create_group: light.roomlight_azl
    unique_id: 5c031558-e7ed-11ed-a05b-0242ac120003
    hide_members: true
    unavailable_power: 0
    include:
      group: light.roomlight_azl
    entities:
      - entity_id: light.dimmable_light_23
        linear:
          min_power: 0.5
          max_power: 8.5
        standby_power: 0.4
      - entity_id: light.dimmable_light_22
        linear:
          min_power: 0.5
          max_power: 8.5
        standby_power: 0.4
      - entity_id: light.dimmable_light_21
        linear:
          min_power: 0.4
          max_power: 5.0
        standby_power: 0.4

Tried it with a less “complicated” 2nd Sensor as well, with the same Error.
Every Sensor for itself alone doesn’t generate that Error. Absolutely weird.
I really don’t know what to do :frowning:

Yes very strange. Could you please create an issue on github? Will see if I can reproduce somehow.

Thanks for your lighning-fast and great Support! Sure i will do :slight_smile:

1 Like

Was already able to reproduce. And have made a fix. Just released v1.8.5 which should fix your issue.

1 Like

Noooooo! I should have waited before submitting the Error :smiley:
Yessssss! Awesome, looking forward to check it out! While i cant wait, probably it will be tomorrow…
Thank you, that is Worldrecord in reacting and fixing :slight_smile:

Haha no problem. Hopefully your powercalc sensors will soon work again :wink:

1 Like

Where should I look to see if an Auto discovered device was setup? I know i have two Alexa devices that are on the supported list.