Powercalc - Virtual power sensors

I submitted an issue - but probably should have brought it up for discussion here first.

I have a number of powercalc sensors. I noticed last night that the daily ones (all of them) did not reset at midnight (or any other time). They have been running fine for the last few weeks, always resetting at midnight, but last night stopped resetting. The only change I think I made yesterday was applying the last powercalc update. I appreciate that if this was caused by that, it would have been noticed before now - but I really canā€™t see why they stopped updating. I will see what happens tonight. My powercalc.yaml file is attached to the issue if anyone wants to peruse it.

I may have just solved it. I did have an offset of 10 hours in my yaml - which previously didnā€™t seem to do anything (I assumed that it was combined with the days offset to determine when the month rollover happened) - but I see now that my daily sensors roll over at 10:00 AM instead of midnight. Iā€™ll set that back to 0 and see what happens tonight.

OK, i give up migrating my Setup to >1.8.x :frowning:
Maybe it is because of my non-standard-Layout, maybe i am too dumb. Whatever. But always something went and stayed ā€œunavailableā€, and after having longer downtimes and lost histories in Sum, i think it is more efficient to start from Scratch, this time doing everything in UI.

  • Is there an Option to wipe all, by Powercalc in the Past created, entities?
  • I have set up Light-Groups per Room, each containing Light-Groups, where the actual Lights are added.
    What would be best-Practice (with the GUI) if i only want/need kwh per Room in the End?
    Most probably there still must be sensors per light get created, this is fine.
    And for non-recognized devices they must get created manually, of Course.
    However - (how) can i tell Powercalc with GUI "This is my light.group_room1, do your Magic - and end up with light.group_room1_kwh?

I am lost at how i can point it to my existing Lightgroups, and dynamically add the Devices found within that Group, so that i end up having kwh-Sensors per Room.

I really love Powercalc, and most probably its because of me not getting what to do with my existing configuration. Anyway. Maybe now it is a good Time to restart from Scratch and giving the (now Way-to-Go?) GUI a Go :slight_smile:

Would be really grateful if some Person smarter than me can help me out :slight_smile:

I cannot get this one working. Is this possible:

  - platform: powercalc
    entity_id: device_tracker.nmap_tracker_ec_c4_0d_be_68_9e
    ignore_unavailable_state: true
    fixed:      
      states_power:
        home: >
          {% if state_attr('media_player.receiver_onkyo', 'source') == 'Game' %}
            8.0
          {% else %}
            0
          {% endif %}
        not_home: >
          {% if as_timestamp(now(),0) - as_timestamp(state_attr('device_tracker.nmap_tracker_ec_c4_0d_be_68_9e', 'last_time_reachable') | default(0)) | int(0) < 2700 %}
            12.0
          {% else %}
            0
          {% endif %}              

Looks rather complicated and not sure what you are trying to achieve.
What are you trying to create a virtual sensor for which is consuming 8, 12 or 0 watt? And what has your presence or game mode to do with that?
You need to enable powercalc debug mode and look at the logs for clues. Also double check correctness of templates you use with the developer tools.

Itā€™s for a Nintendo Swiich, which is unmanageble with HA. The only thing you can you is creating a presence sensor (with nmap).
When the console is docked then it has the state not_home . If you are playing it has the state of home.(device_tracker.nmap_tracker_ec_c4_0d_be_68_9e). After playing when itā€™s docked it consumes 12 W to charge. The average time of charging is 45 min (2700 sec). After then it consumes 0 W.
When playing on TV then itā€™s docked and comsumes 8W. This can I check with the source of my receiver (state_attr(ā€˜media_player.receiver_onkyoā€™, ā€˜sourceā€™) == ā€˜Gameā€™).

This is the goal and I know it are averages but itā€™s better then nothing :slight_smile: .
The templates are working in the dev tools, I have to enable debug mode for Powercalc.
Hope this is clear to understand whatā€™s the meaning of it.

1 Like

Your problem is probably because of following reasons.

device tracker is a binary sensor and not_home is considered OFF for powercalc. In this case standby_power is used and calculation is not delegated to the fixed power calculation configuration.
This is by design. I will add a note to the states_power documentation which makes that more clear.

However currently you cannot use templates as standby power. I can see how that would be useful so I will add support for that.

Besides that, even if templates were supported for standby_power, the way you are using as_timestamp wonā€™t work as template will only be evaluated again when referenced entity device_tracker.nmap_tracker_ec_c4_0d_be_68_9e state changes. It will not recalculate and re-evaluate each second or something like that. So the 2700 treshold will never hit.

That being said there is an undocumented setting sleep_power which I think does exactly what you want.

I will do some testing to see if I can come up with a good configuration to do what you want.

Did some further testing and the following should work for you:

powercalc:
  sensors:
    - entity_id: device_tracker.nmap_tracker_ec_c4_0d_be_68_9e
      fixed:
        power: "{{ iif(state_attr('media_player.baa', 'source') == 'Game', 8.0, 0) }}"  # This template will be used when the device_tracker has state `home`
      standby_power: 12  # This value will be used when the device is off `not_home`
      sleep_power:  # This setting can be utilized to set the power sensor to a given amount of watts after x seconds elapsed. Timer will be started after device turns off
        power: 0
        delay: 2700
1 Like

Thx for your support! This is working.

1 Like

I have a strange problem with one of my power sensors - not related to Powercalc, but perhaps can be resolved using itā€¦
So, I have quite complex set of power sensors that are mixture of physical one (like Shelly PM or EM), some devices that are reporting power consumption directly and lots of sensors created using Powercalc. I have 95% of power receivers covered this way, but one, probably the biggest, which is inductive hob. So I created template sensor that calculates hob power consumption by substracting from total power consumption of house the sum of consumprion of all known devicesā€¦ Not very accurate, as I have some not measured devices, but these are low power, so overal error is minimal. I compensate for this by small adjustment of calculated value by further substracting average of other devices consumption. Bottom line I get pretty reasonable estimate of what hob is consuming in terms of power. But then I have strange situation with energy calculation, that I did not obeserved for other sensors. It shows consumption way too hight to my judgement.
So, here is the code for power sensor:

      - name: Induction Owen Power Total
        unique_id: induction_owen_power_total
        state: >-
          {% set other = states('sensor.other_power_total')|float(0) %}
          {% if other > (500 + states('sensor.average_other_power')|float(0)) %}
            {% set owen = other - states('sensor.average_other_power')|float(0) %}
          {% else %}
            {% set owen = 2 %}
          {% endif %}
          {{ owen }}
        unit_of_measurement: "W"
        device_class: power

And here is associated energy sensor:

  - platform: integration
    source: sensor.induction_owen_power_total
    name: induction_owen_energy
    unique_id: induction_owen_energy
    unit_prefix: k
    round: 6

And here is the problem - chart below shows how hob was working today (since midnight:

As you can see hob was on for ~2.1 minutes with power consumption of ~550W. This should give energy consumption of 550*2.1/60=19.5Wh. But the energy dashboard shows for this device todays consumption of 3.07kWhā€¦ not small discrepancy (~160x):

For comparison my IT rack consumes about ~115W of power and same calculation gives result of 1.38kWh which is pretty close to reported in dashboaard 1.24kWhā€¦
Any idea what is wrong? Can Powercalc be used to create proper energy sensor from my power sensor?

Have a look at method in docs and try/use left instead of default=trapezoidal

2 Likes

Hi, I have a question about the icon of the powercalc devices that are created. In my case all powercalc devices are from Hue lights. All but 1 hue light devices have the Icon of Hue, and there is 1 device that has the icon of Powercalc.

Nothing wrong with the sensor, but it just appeared strange to me as to why this was. Does anyone have an idea about that?

Powercalc does not set an icon for devices, nor it has control over that.
Multiple integrations can provide entities for the same device. In your scenario powercalc and hue integration both provide entities.
HA need to pick one icon. How it does that I donā€™t know.

Here are some examples from my installation. The first two have both zwave and powercalc. For the first Zwave logo is shown. for the second Powercalc.
In the 3rd entry both Unifi and EspHome integrations provide entities and EspHome logo is picked.

Seems it looks at the order of integrations, last column. However I donā€™t known what the logic behind that is.

@bramski few releases ago you have changed something on how to declare the sensors in yaml.

For HASS I have a huge yaml file in which I create all my custom sensors (over 80, not just Powercalc). Then I have an include in my main configuration file. For this I still use the legacy format (this - bottom part about legacy configuration) which is still supported by HASS

So all my powercalc sensors are like (within sensors.yaml which I !include):

# - platform: powercalc
#   create_group: All powercalc
#   entities:
#     - create_group: All Sonos and Home
#       entities:
#         - entity_id: media_player.hobbyruimte #sonos 1 checked
#           ignore_unavailable_state: true
#           fixed:
#             states_power:
#               playing: 8.3
#               paused: 4.4
#               idle: 4.4
#         - entity_id: media_player.keuken #sonos 1 checked
#           ignore_unavailable_state: true
#           fixed:
#             states_power:
#               playing: 8.3
#               paused: 4.4
#               idle: 4.4

Iā€™m getting powercal integration warning that I need to change this to the new format (from your documentation):

powercalc:
  sensors:
    - entity_id: light.my_light
      fixed:
        power: 20

But I canā€™t seem to combine these 2 methods; Does this mean I need to change all my non-powercalc sensors (which are complex template sensors so this would be a massive task) to use the new formatting (first part of this) to be able to continue to use powercalc or are there other ways?

Iā€™m not 100% sure of your question and struggle.
But you only have to migrate the Powercalc sensors.
So all entries starting with.

- platform: powercalc

Needs to go under powercalc->sensors.

Other sensors you are referencing to in your links are template sensors. You can just keep them as is. They are unrelated to powercalc in any way.

You have to put your powercalc sensors in a separate file powercalc.yaml (explanation in some comments above) or put in main configuration.yaml or use packages system.

You canā€™t keep them in sensors.yaml as only things which are directly under sensors: are allowed to put there.
That would also apply if you want to adopt the new configuration structure for template sensors, than you also canā€™t put them in sensors.yaml anymore.

Hope this helps.

Anyone els running into this? Unable to update.


Logger: homeassistant.components.websocket_api.http.connection
Source: components/update/__init__.py:134
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 09:55:01 (5 occurrences)
Last logged: 09:59:01

[23397749903552] No update available for update.powercalc_update
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 226, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1974, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2011, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 235, in handle_service
    return await service.entity_service_call(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 870, in entity_service_call
    response_data = await _handle_entity_call(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 942, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/update/__init__.py", line 134, in async_install
    raise HomeAssistantError(f"No update available for {entity.entity_id}")
homeassistant.exceptions.HomeAssistantError: No update available for update.powercalc_update

I donā€™t know. Never seen this before. It seems a HACS issue nothing I can fix in powercalc.
Your best bet would be to raise an issue on HACS issue tracker or ask on HACS discord.

Yes, I have the same problem. I have the HACS experimental features enabled by the way.

If I go into HACS and select Powercalc and click in the menu on Redownload, the latest version that can be seen is v1.9.0, although the latest release is 1.9.1 according to the same integration.

There seems something messed up with the release listing in HACS. In github the releases are fine. So itā€™s definitely an issue in HACS.
Please report at HACS because itā€™s not something I have control of or can fix.

See Update-Error to v1.9.1 Ā· Issue #1815 Ā· bramstroker/homeassistant-powercalc Ā· GitHub.
Issues with the 1.9.1 release should hopefully be solved now.

2 Likes