Powercalc - Virtual power sensors

Hi. I am trying to create a PowerCalc sensor which gives the SOLAR Wh of electricity which is supplied to my hot water cylinder (HWC). The HWC has a solar diverter (with SSR) so the Wh is not simply the rating of the element… I think I need something like this in the configuration.yaml:

- entity_id: sensor.dummy
        name: 'HWC Solar Wh'
        fixed:
          power: "{{states('my_calculated_solar_watts')}}"

I am happy with the below logic to calculate ‘my_calculated_solar_watts’ (the watts from solar) - the problem is where to put the below code, and also is the formatting correct? Can I somehow include the below calculations within the above? Or where can I do these calculations?
sensor.phase_1 and sensor.hwc_watts are existing HA sensors…
As you can see, a bit of logic is required to give me the watts that has come from solar…

          if (states('sensor.phase_1') <= 0){                     //all hwc is SOLAR!
            return (states('sensor.hwc_watts') | float(0))
          }    
          else{
            if (states('sensor.phase_1') - states('sensor.hwc_watts') >= 0){   //No solar used
               return (0)
            }
            else{                                                          
               if (states('sensor.hwc_watts') > 5){            //return the solar proportion
                  return ((ABS(states('sensor.phase_1') - states('sensor.hwc_watts') / states('sensor.hwc_watts'))) *  states('sensor.hwc_watts') | float (0))
               }
               else{
                  return (0)
               }               
            }
          }

Thank you for any help!

Managed to solve this by creating a template sensor which calculates the solar watts, and using PowerCalc to give me the energy (Wh). Works well…

1 Like

I am trying to create a group of 3 lights in Powercalc that will create two entities: energy and power for the group. I put 3 power sensors and 3 energy sensors into the UI for the group and it did successfully create both sensors. My only issue is that, while the energy sensor works perfectly, the power sensor is “unknown”. All 3 power sensors are 0.2 W currently, so I see no reason why it should be unknown. Any ideas?

That’s strange. Any error/warnings in the logs?

I had to rename a lot of my devices.
Now powercalc has many old entities.

Is there any way to sync or should I maybe just delete powercalc and readd it? There’s a lot of work behind my setup so I would prefer a easier way

I just posted this question Combine the state of several sensors dropout filter - Configuration - Home Assistant Community (home-assistant.io)

I thought I should also ask here if there’s any way to do the same thing for PowerCalc energy sensor entities that would ignore dropouts and essentially maintain the last known value until a connection is restored?

I see this is available for the power sensor entities, but not energy:

Why don’t you use the built-in grouping functionality of Powercalc?
https://homeassistant-powercalc.readthedocs.io/en/latest/sensor-types/group.html

Does the Powercalc grouping option allow you to ignore unavailable energy sensors? Trying to find the answer in the documentation, but it is not clear to me…

Sure. have a look at ignore_unavailable_state. Should do what you want.
You can also set this on the group sensor both in GUI and YAML.

https://homeassistant-powercalc.readthedocs.io/en/latest/configuration/global-configuration.html

1 Like

Hello,

what an great integration! Thanks!
I am playing with the power measurement of my lights.
I had some nudging issues when using my shelly via HA.
Using shelly directly, I get

/app/util/measure_util.py", line 26, in take_average_measurement
    power = self.power_meter.get_power().power
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/powermeter/shelly.py", line 65, in get_power
    return self.api.parse_json(json)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/powermeter/shelly.py", line 33, in parse_json
    meter = json["meters"][0]
            ~~~~^^^^^^^^^^
KeyError: 'meters'

It seems, there are no meters returned?
This is a shelly 3EM and I am using Phase A.

Any Idea, what could be wrong?

Another question:
The measurements are taking too long for my taste.
Can I set these variables via .env?

    SAMPLE_COUNT = 1
    BRI_BRI_STEPS = 3
    CT_BRI_STEPS = 15
    CT_MIRED_STEPS = 50
    HS_BRI_STEPS = 10
    HS_HUE_STEPS=10
    HS_SAT_STEPS=10

For the HS steps, one can configure in the .env the precision… But that’s a bit odd:
HS_BRI_STEPS = round(32 / HS_BRI_PRECISION)
So, a lower precision will lead to more points. But the readme says:

Precision for the HS mode loop. You can increase it up to 4 to improve the precision of the profile by taking more measurements

What am I seeing wrong here?

What would you recommend in order to get the time for a HS-Run down to maybe 30 minutes?

And a question on integrating the custom lights:

2024-01-04 14:53:46.561 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.powercalc
2024-01-04 14:53:46.562 ERROR (MainThread) [custom_components.powercalc.sensors.power] light.og_charlie_lichtwest: Skipping sensor setup Model not found in library (manufacturer: Friedel, model: 105W)
2024-01-04 14:53:46.562 ERROR (MainThread) [custom_components.powercalc.sensors.power] light.og_charlie_lichtwest: Skipping sensor setup: Model not found in library (manufacturer: Friedel, model: 105W)

When trying to add one via GUI, not having the file zipped, I get:

2024-01-04 19:34:19.536 ERROR (MainThread) [custom_components.powercalc.config_flow] No lookup file found for mode: brightness
2024-01-04 19:34:39.645 ERROR (MainThread) [homeassistant.components.unifi] Error connecting to the UniFi Network at 192.168.177.3: Error requesting data from 192.168.177.3: Cannot connect to host 192.168.177.3:8443 ssl:False [Connect call failed ('192.168.177.3', 8443)]
2024-01-04 19:35:06.034 WARNING (MainThread) [homeassistant.components.sensor] Updating onewire sensor took longer than the scheduled update interval 0:00:30
2024-01-04 19:35:07.029 INFO (MainThread) [custom_components.emporia_vue] Integrating minute data into day sensors

Why is that?

Greetings,
Hendrik

Hi all, I’ve setup Powercalc in Home Assistant - I’ve enabled debugging as I can’t see where it has “found” my devices. Debugging suggests that devices have been identfied (see example below) - I have restarted Home Assistant, but I can’t find the option to configure the devices. Where should I be looking?

2024-01-05 17:19:59.460 DEBUG (MainThread) [custom_components.powercalc.discovery] device_tracker.m2102j20sg: Auto discovered model (manufacturer=Aqara, model=M2102J20SG)

It does look as though Powercalc creates a standby energy sensor.

2024-01-05 17:20:08.062 DEBUG (MainThread) [custom_components.powercalc.sensors.energy] Creating energy sensor: All standby energy

Please create a github issue for this. Then we can further investigate by inspecting the API response you get from shelly and figuring out why the measure tool doesn’t work with that.

Increasing the HS_BRI_PRECISION will cause the step size to decrease. So when you set it to 4, the step size will be 32/4 = 8. So the measure loop will do 1 → 9 → 17 → 25 etc. By default it’s 1 → 33 …
So the docs in .env.dist are correct.

You may set precisions to 0.5

HS_HUE_PRECISION = 0.5
HS_SAT_PRECISION = 0.5

But beware that this will cause less accurate measurements, so I wouldn’t suggest to do that.
The default setting should not take longer than 2 hours. And it’s only a one time process.

Where did you place the files?

This means the light you are setting up has brightness as a supported color mode. You could check that for the light entity in HA developer tools.
You’ll need to run the measure tool and provide the CSV for all the possible supported color modes of the light.
It’s a bit strange, because for a light supporting colors, brightness should never be a possible color mode. But some integrations are buggy and did not implement according to HA specs: Light Entity | Home Assistant Developer Docs

`

This only means powercalc found a possible entity because it could find manufacturer and model information on the entity.
It does not mean it is actually supported by powercalc. When it is you should see more debug lines (also Creating power sensor).
You can check the following list for all supported devices: homeassistant-powercalc/docs/supported_models.md at 06a88bcd50eca34748b74b9de618924f3d72ac0e · bramstroker/homeassistant-powercalc · GitHub.

This is an energy sensor which is created for all powercalc installations by default. It will sum all the standby power values for all powercalc sensors. So you’ll get a sense how much all your IOT devices etc. are consuming even when off (smart switches etc., google homes, smart bulbs).

I have a govee heater.

The heater have the on/off entity light.smarte_heizung, then I have an entity number.smarte_heizung_gearmode_parameter with the gear 1, 2 or 3

Is it possible, that I chan change the w in powercalc when I change the gear?

for example:
light.smarte_heizung = on
number.smarte_heizung_gearmode_parameter = 1
W = 1000

light.smarte_heizung = on
number.smarte_heizung_gearmode_parameter = 2
W = 1300

light.smarte_heizung = on
number.smarte_heizung_gearmode_parameter = 3
W = 1500

Edit:
I have find the solution
I have take the entity from the gear and not from the light.smarte_heizung.
under calibration values:
“1”: 1000
“2”: 1300
“3”: 1500

under Condition for activating the calculation:
{{ is_state(‘light.smarte_heizung’, ‘on’) }}

Was just typing an answer, but this was exactly what I was about to propose.
I think this is the cleanest solution with current powercalc possibilities.

Alternative was to use light.smarte_heizung as entity and use an template for fixed->power.

Hi all - I’m trying to take some measurements, hopefully to contribute, but I’m struggling to get one of the recommended plugs (Tapo P110) to connect. I’m setting .env up to use Kasa as there isn’t a Tapo config and they are both TP Link…but maybe that’s where I’m going wrong and I’m getting ‘ConnectionRefusedError: [Errno 111] Connect call failed’ and ‘SmartDeviceException: Unable to connect to the device’ errors in the underlying Python. Has anyone managed to connect a Tapo P110 to the measure script?

You can just use the hass option, which connects to HA API. So any entity which is in HA can be used.

1 Like

Great thank you that sorted it…but now models are pulling through into the UI configuration when adding new lights. One of my models (that is linear, not measured) is showing by nesting under:

/powercalc-custom-models/innr(manufacturer)/RS 225(model)/model.json

but all of my others measured using the measuring script are showing the manufacturer in the Powercalc UI but not the model. Is this a bug or user error? I have copied the json and csv.gz produced by measure into the model folder.

Hi There, how can i launch another discovery for the ignored device?
I have wrongly ingored some devices but i want that on powercalc…
Thanks a lot for your help!

Hi,

have anybody values for Sonos Beam and Move?

Sonos Move I have found here, but these are not at the official modell list:

      fixed:
        states_power:
          playing: 8.3
          paused: 3.2
          idle: 3.2

Thanks, Steffen