Open hheimbuerger opened 1 week ago
You cannot retroactively register states. HA is a state and event based system, so you can only report a state when it actually happens and HA will save that in the states table.
So it won't be possible to do this with a power sensor.
Might be doable by introducing some new kind of energy sensor which does the following:
In your proposed pseudo code I'm missing the entity_id, which should be the main P1 meter right?
So it might look like this:
- name: Stove
entity_id: sensor.mains_power
untracked:
power_exceeds: 200
min_time: 00:02:00
Got some draft PR going on #2710
Got some draft PR going on #2710
Wow, thank you for looking into this so quickly! I'll try to review the code tomorrow and maybe I can follow along and see if I understand how this works.
Regarding the retroactive events: yeah, I figured that's how it works. I would be very interested in a power sensor as well (real-time power display is what I'm doing a lot of my tracking for), but I understand that these are heuristics, and by definition not fully accurate. So if it just doesn't show up in the first two minutes (or whatever min_time
is set to), and there's the power and energy data is 'off by two minutes', that's perfectly acceptable for me.
In fact, I think in my case, I might just be able to skip the 'minimum time' requirement at all, and simply claim all untracked consumption over a certain wattage as the stove. Given that I have so few untracked, high power-draw devices, the total error will probably be a very low percentage.
As for your question about the entity_id
: as all my powercalc devices are 'virtual' (don't have corresponding devices in HA), I never quite understood what it is for and how to use it. But that's a point for another conversation (or maybe just for me to keep reading the docs) and doesn't belong here.
But yeah, I guess in this case one would need a parameter to specify which electricity source to track, if HA can have multiple untracked consumptions.
Checklist
Is your feature request related to a problem? Please describe.
Have you considered giving powercalc the ability to set up rules based on untracked consumption?
I've set up tracking of most of the significant devices in my household. (Using powercalc for the very static ones that don't warrant active tracking.) The last remaining one is my induction stove, which in my case (as most European homes, I believe) is more directly connected to the apartment's power grid, not just plugged into an outlet.
But I've just realized that I could pretty easily think of a heuristic approach to identify stove usage based on the untracked consumption: Given that most of my devices are tracked, there's only very few that draw a lot of power (200W+): it's mostly the stove, and very rarely an iron or a hairdryer, but those latter two run for maybe a minute or two. And they're also used so rarely that some misclassification wouldn't bother me much.
Describe the solution you'd like
I'd like to use powercalc to set up a rule that goes like this (pseudo-code):
Describe alternatives you've considered
Eventually, I'd like to properly track this device with something like a Shelly, but I'd need to find an electrician to install this into the breaker box, so... a much bigger project. Solving it in software using powercalc would be a very neat stopgap solution!
I'm also considering to see if I can understand enough of the powercalc sources to create these two sensors specifically as its own component.
Additional context
I'm wondering if powercalc (or any HA component, for that matter) can create power/energy events retroactively, i.e. whether it can use the 'for at least two minutes' part of the rule to then create a power draw in the HA database with a timestamp of two minutes before the detection.