I would like to do an energy calculation not over time like PowerCalc, but when the state changes. This means that if a binary sensor goes on, I would like to add x kwh to the energy sensor (template option would be important).
Is there anything ready? Or can I you use PowerCalc?
Yes I know, but this is over time you have to calculate watt over one hour.
In my case the watt relates from different temperature states + different programs duration.
So it would be easier, binary sensor on → Add x kwh.
Instead of:
temperature a → x kwh / program duration
temperature b → x kwh / program duration
Currently I’m not sure whether I have the duration as a sensor
That doesn’t really make sense; you’re not going to have an instantaneous increase in kWh.
It doesn’t need to be an hour, but it does need to be over some time period. Not knowing exactly what you’re doing makes it tricky, but it seems like this should be possible either natively in Powercalc or by using an automation and some helpers.
Actually the application is simple: I have a binary sensor and I know exactly how much power it consumes depending on the setting (temperature) as soon as it turns on. I know the power consumption directly from the temperature. But when the device is switched on, you can evaluate the temperature and know the power consumption until it is switched off again. The duration doesn’t matter.
Based on what you’re describing, I’d probably go with a template sensor (and probably use a trigger of your switch being turned on). I’ve never had a need for a trigger template sensor, so I can’t help you off the top of my head. If that seems tricky, honestly even an automation with a helper number should get you what you’re after.
I see you just want to increase an energy sensor (kWh) with X amount whenever a state changes.
You could create a template sensor with correct device_class and increase that with a service.
Or use powercalc daily fixed energy sensor. Daily fixed energy — Powercalc documentation
Set it to 0 per day and just use the powercalc.increase_daily_energy service from an automation to increase it with the amount you want.
Your trigger in automation would be state.
I have a similar need in my environment, but I also want to decrease the value of another sensor when I increase the device sensor.
IE, the dishwasher completed it’s cycle, add 2.5 kWh to the Dishwasher Energy sensor, but I also want to remove those 2.5 kWh from the Unaccounted Energy sensor that is calculated based on power usage of multiple devices subtracted from the total power consumption of the house.
The service doesn’t seem to like a negative value since I get an error when I try to run it