Powercalc - Virtual power sensors

Hi there! So far it’s a great custom integration, using it to get all my stuff in home assistant. However I’m stumbling across a Tuya thermostat. It has a programmed scedule which doesn’t change the mode from “off” to “heat” for instance. It always says "heat’, even if the set temperature is lower than the actual temperature. So I can’t use that for powercalc. In the Tuya IoT platform I can see there’s a “working status” flipping from “0” to “1” in de device log when the thermostat goes on. But I can’t find “working status” anywhere within home assistant. Any thoughts?

OK, as a workaround, I made a virtual device in the Tuya IoT platform, made a scene in the Tuya app and created a trigger which sets a virtual smart plug on or off. This virtual plug is in now in Powercalc and working like a charm.

Good to hear you got it working. Powercalc is only working with data available in entities in HA, to work with any device / integration.
When data is not present in HA it should be solved in the concerning integration or you should find out a way to get the data in HA using another method, which is ultimately what you did.

I’m having an issue with a “Daily energy” sensor that I’m trying to use to simulate the consumption of a coffee machine.

I created this template that checks if someone is at home in the morning or at noon, and consequently sets a power consumption of 1000W for 3 minutes. In this way, 0.05 kWh should be incremented each time it turns on.

On the power graph, everything seems correct:

However, on the energy consumption graph, there is a much higher value than it should actually be (today for example 14.64 kWh):

This is the configuration:

This is the complete template:

{% if states('input_boolean.fuori_casa') == "off" and (("07:00:00" <= now().strftime("%H:%M:%S") < "07:03:00") or ("12:30:00" <= now().strftime("%H:%M:%S") < "12:33:00")) == True %}
1000
{%- else -%}
0
{%- endif %}

As an alternative, I know I could create an automation that calls the services “powercalc.increase_daily_energy”.

service: powercalc.increase_daily_energy
data:
  value: 0.05
target:
  entity_id: sensor.my_energy

However, I would like to do everything in Powercalc without external automations.

daily fixed energy is not really purposed to provide a non fixed Watt value. When you provide a value of W it should be a steady value and not really fluctuate depending on some template resolution.

For your use case you should just create a virtual power sensor (manual).
Select fixed as stragegy.
At next step provide your template in power template field.

I had already tried this way, but it is mandatory to set a “Source entity” and in this case there isn’t one, so I didn’t do it.

I will try again anyway, specifying an entity not connected to the coffee machine.

Thanks for your help.

You can set source entity to sensor.dummy manually, this is undocumented.
I will see if I can make it optional in the future.

Or just set to input_boolean.fuori_casa as it will also take a potential device from it and bind the entities generated by powercalc to the same device.

I have tried setting up two entities to test both methods you suggested, but I was unable to solve the problem.

  • If I set sensor.dummy, the power and energy entities are not created:


  • If I set input_boolean.fuori_casa instead, the power is not displayed in Powercalc when the template returns the value 1000, and therefore the energy is not calculated.
    I have tested the power template separately and it works correctly.
    I have also tried to specify the “Calculation enable condition” option, but I was unable to solve the problem.

Could the problem be that input_boolean.fuori_casa is in the off state when the power of 1000 is assigned to it?

btw on closer look of your used template this is never going to work.
Templates are only evaluated whenever a referenced entity in the template is changed, that’s what it tracked by HA.
You cannot do any timebased stuff in the templates afaik, this will also not work when creating a template entity in HA.

edit
Seems you can, but this is not supported in powercalc yet, a template which is re-evaluated each minute. Need to have a look at how that is implemented in template sensor.
I suggest you to create an feature request in powercalc github. Will see what I can do.

To get it working now you could alternatively create another template sensor which behaves like an binary sensor and return On or Off, or create an input_boolean helper and toggle that with automation.
Now you can use that new entity as input for powercalc sensor.

As you say in the edit of your message the templates are reevaluated every minute, I also use them in other automations.

I tried to setup two Virtual power (manual) linked to two new helpers like this:

Helper reversing the sensor "fuori casa" + Power template (Energy calculated exactly 0.05 kWh as it should be)

New helper that simply reverses the state of input_boolean.fuori_casa

Name: binary_sensor.inverti_fuori_casa
Template:

{% if states('input_boolean.fuori_casa') == "off" %}
on
{%- else -%}
off
{%- endif %}

Powercalc configuration:
Source Entity is the new sensor: binary_sensor.inverti_fuori_casa
Power template:

{% if states('input_boolean.fuori_casa') == "off" and (("07:00:00" <= now().strftime("%H:%M:%S") < "07:03:00") or ("12:30:00" <= now().strftime("%H:%M:%S") < "12:33:00")) == True %}
1000
{%- else -%}
0
{%- endif %}

From this we understand that previously Powercalc did not calculate the power (even if the value 1000 was passed to it) because the previously used input_boolean.fuori_casa “Source Entity” sensor was off.
The rest of the settings are the same.

Helper that simulates turning on the coffee machine at certain times (Energy calculated 0,0497 kWh instead of 0.05 kWh as it should be)

Name: binary_sensor.macchina_caffe_virtuale
Template:

{% if states('input_boolean.fuori_casa') == "off" and (("07:00:00" <= now().strftime("%H:%M:%S") < "07:03:00") or ("12:30:00" <= now().strftime("%H:%M:%S") < "12:33:00")) == True %}
on
{%- else -%}
off
{%- endif %}

Powercalc configuration:
Source Entity is the new sensor: binary_sensor.macchina_caffe_virtuale
Power: 1000

I will check in the next few days to see if this small error on the calculated energy occurs again.

I confirm that both methods tested have been working well for a week, always indicating 0.05 kWh.
For consistency of operation of the Powercalc logic I kept the second method, in this way if in the future I added a real switch it would be enough to change the associated entity.

1 Like

I thought I had my home assistant setup pretty good - then I came across this powercalc completely by accident. My god - quite a life changer. As I have power plug monitors in two locations that had google homes and lights, by implementing this, I have been able to free up those power monitors to use elsewhere. In total I have 5 google homes and now I can have power stats for an additional 12 lights using this integration. I am amazed!

I had a stroke 2 years ago, can no longer work and home assistant is my hobby.

I have no idea what else I will stumble across in the journey, but way to go to you developers of this stuff.

2 Likes

Thanks for sharing your story. glad you like the integration and makes things easier for you.

I have also now managed to track a tv with a chromecast with google tv now. Was not able to use the cast integration to know when off/on but after installing the android tv bridge, I can now use powercalc with standby of 1.8w (the chromecast standby), and the whole thing as 89.2w (as measured when TV is on). I have two bedrooms like this - so Another two power monitors saved that can be used elsewhere.

This is my new fav integration.

2 Likes

Since a few weeks I have moved translation management to crowdin, which makes it very easy to contribute to the Powercalc translations.
Some languages needs some love as you can see in the screenshot below.
Also missing languages are welcome.
If any of you do have some spare time, and are native speakers of given languages. please help gettings this done.

1 Like

Hi all, I have implemented a new download feature for Powercalc, which is currently released as beta. Read more on it here: Release 1.12.0-beta.1 · bramstroker/homeassistant-powercalc · GitHub

Looking for beta testers which can test this feature. Please let me know if you can help.

1 Like

This seems to be exactly what I need… only I’m looking for something to track gas usage instead. Is that possible with this? I have a pool heater that burns a constant amount of gas and I can track when it’s on and off, would this work for that? I’m guessing I could use for furnace and fireplace too and possibly tankless water heater…

Powercalc only supports power and energy sensors (W and kWh).
I have no plans to add support for gas or water.
Also see Support for other energy units · Issue #1581 · bramstroker/homeassistant-powercalc · GitHub

I wasnt aware, and I am running B4…

seem to remember a FR of mine for this, and then was figured irrelevant because of library size.

Guess things have grown out of hand :wink:

but, glad to test, although I dont know how.

I cant seem to find a selector, or setting, to only install Signify, Tradfri and Shelly?

how could I do so in yaml?

@Mariusthvdb You don’t have to do anything. It should work all transparently.
Previously files would be in config/custom_components/powercalc/data, now it is automatically downloaded to config/.storage/powercalc_profiles directory. Only the profiles you actually use should be there, and were already downloaded by the download component.

When you don’t experience any issues everything migrated correctly.

1 Like