Evening all. Been working on quite a significant set of enhancements over the last few days. These have now been published as a new test version that can be installed by clicking the link:
Unreal Battery Changes
The Unreal Battery device no longer requires you to specify a time-base - instead it remembers the time of each event and uses this to calculate the elapsed time since the last event. This is a more resilient approach since it supports recovery after a failure - for example if your Homey goes down for several minutes, the power added will be scaled by the amount of “lost” time rather a fixed time-base. A new capability reports the elapsed time between successive events.
It increases the flexibility of use of the Unreal Battery. In addition to using a timed heart-beat, the device can be driven by When X changes flow cards.
Notes
I have deliberately maintained compatibility with the old version by retaining the original When flow card. You can still specify a time-base but this is ignored by the app. This means your flows will continue to work with no noticeable difference.
There is a new When flow card that does not require the time-base parameter. You are encouraged to migrate to this new flow card as you maintain your flows.
Many capabilities in Homey do not have a When X changes flow card (I find this irksome). The Device Capabilities app is your friend. The Listen (Watch) flow card emulates a When X changes flow card and can be used for any capability on any device.
New Power Integrator Device
Too many devices provide a power capability, but fail to provide an equivalent energy capability, or provide an energy capability that is deficient in some way (daily energy in place of accumulated energy, for example). For me the need to integrate power over time, giving accumulated energy proved to be a consistent need that I solved repeatedly using Advanced Virtual Devices and Flows. The necessary flows are not trivial and need to be maintained.
In the spirit of the Unreal Battery, the Power Integrator is designed to meet this specific need. It takes Power readings from any device and updates both accumulated and daily energy totals.
It operates identically to the Unreal Battery, using a simple flow card to absorb power readings and to calculate energy from power and elapsed time. The device stores the time of each successive event and uses this to calculate the interval between events. Either timed or When X Changes flow cards can be used to trigger updates in the Power Integrator.
Example
The device representing my inverter provides a measure of power (House Load Power) consumed domestically (i.e. power not exported and not routed to charge the battery):
Here you can see the use of the Listen flow card from the Device Capabilities app. Every time House Load Power changes on the Inverter device, the power is integrated into the accumulated energy. The last capability on the Power Integrator device shows the time elapsed between the most recent two events.
Notes
You can change the Device Class through the device settings. For example, I have a Power Accumulator representing the power and energy generated by Solar Panels. By changing the Device Class to “Solar Panel” this device is correctly integrated into the Homey Energy Tab.
This is awesome… The indevolt app doesn’t handle multiple stacks and doesnt implement the power_meter capability. Now I can route everything to the unreal battery. Exactly what I needed.
I also have a value that’s calculating my home energy usage (excluding the batteries/solar panels), and the Power Integrator works well there.
One nitpick… I can’t find a relevant ‘device class’ to map it to something equaling “entire home”. Something generic like “sensor” or “service” doesn’t make it show up in the Energy tab. Any suggestions?
Thanks for the kind comments about what is a really simple app. The new version of the app (V1.0.8) has a device for that! If you create a “Polarizing Power Integrator” device it has a number of settings designed to make it into a full grid device. Depending on the nature of your input data you may need to do some calcs on the value of Power being fed to the device (I wrote with a specific personal purpose - picking up a home battery - and realised it had more general application later).
The device takes a single, signed flow of power - negative power means export and positive power means import (or the other way around - can’t remember). So if you have separate power values for import and export you just need to subtract one from the other before you pass it to the integrator. The device then separates the two signs into separate streams again (yeah, I know…). My battery meets the “single signed flow” criterion - your metering device may not.
Here is my simple flow to feed the integrator - that I am using to monitor my grid input/output as reported by the Inverter.
The card has an Invert parameter so if the sign of the power flow data is the “other way round” the device can still work. The trigger card is the Listen card from the Device Capabilities App. The Number 1 parameter is the tag set by the Listen when it responds to a change in the watched capability.
Note Represents Grid Use and Tracks total home energy consumption - the first sets the device’s energy settings to the correct values. The second is required by the Energy Tab to be treated as the “master of energy universe”. You must also set Exclude from Energy to No (mine is set to “Yes” because I have another device that is actually the “master of my energy universe”).
With that done, you should see your energy import and export appear on the energy tab. If the direction turns out to be the wrong way around, simply change the value of the Invert parameter on the flow card…
By The Way
Don’t know if you are based in the UK or not, but if you are an Octopus customer in the UK there is also the Kraken App. The Energy Account device in this app can also act as the “Master of the Energy Universe” - that’s the device I use by default. These insights show how closely my main meter and my inverter track each other…
Further to my earlier reply, it occurred to me you may have import-only (or even export-only) electricity that you want to include in the Homey Energy tab. This will work very well with the Polarized Power Integrator - except that one direction (probably export) will always be 0. The Homey Energy tab will show it correctly and track its energy correctly too. The only cost are the 2 unused capabilities that remain at zero (or null).
However, on realizing the gap, I have updated and published a new test version of the app:
The enhancements are two-fold. First a setting for the (ordinary) Power Integrator device that allows you to say whether you are using it as the master for import, export or neither. Neither is the default for compatibility purposes. In doing this, I have discovered two things:
The Tracks total home energy consumption setting never seems to appear for a uni-directional device - but this does not seem to impact the integration into the Energy Tab.
Even if you set the direction as export, the power must be negative to count as export on the Energy Tab for a unidirectional device.
To support the second finding, there is a new flow card (keeping the original flow card for compatibility). This is Invert sign and integrate POWER since the last computation to give Energy.
Now, if you have import only or export only, you can choose to use a Polarized Power Integrator (with empty capabilities) or use an ordinary Power Integrator with the new flow card (if required). Both should drive the Energy Tab correctly.
This is fricking brilliant and it’s exactly what I was looking for!
Came here for the battery, but stayed for the rest
I’ve now replaced almost all of my hardware kwh-meters with ‘unreal’ ones because they all have some problems by themselves:
Battery, because it didn’t support the powermeter; and counts the 20w stand-by usage as ‘charging’
EV Charger, because Homey counts 4w standby-usage as ‘charging’.
Home power use (so excluding battery and solar) I had in a Homey variable, now correctly on the Energy tab.
Total power import/export: supplied with a rolling avarage so short/sudden peaks in demand are smoothed out (I want to feed this to the battery to prevent the jerking around…)
Solar panels, because at night Homey registers a 10w negative value (again, standby power).
Thanks for the feedback - it’s always good to hear positive outcomes. Also about problems so they can be solved.
Interesting to hear about the device annoyances that you have faced… I have an annoyance with my Heat Pump. On days when it’s not in use it reports 3kWh of DHW use (on a “real” day we hardly ever use 3kWh to heat DHW, so it’s really annoying). Actually the energy estimation was pretty carp anyway.
Then I found the Homey device also reports power by direction and you can assign the “channel” by looking at the operating mode (CH, DHW, Pasteurisation…). I have used an Advanced Virtual Device (Device Capabilities app) to set up integrators for each direction and key channel in a single device.
There are also daily energy totals and daily COPS. The flow that drives the device is pretty complex because the integration is calculated in the flow rather than in the device. But it’s better than the original.
This was my motivation for starting to write the integrators. Eventually I want to take it one step further and include reflection (like AVD provides) in the set up of the devices so there is no flow needed to drive the integrators.
You’ve got money on the Energy Tab - the UK prices energy differently from the rest of Europe so we don’t really fit the data supplied for use by the Energy Tab. It’s incredibly frustrating because the Kraken Energy app supplies a capability with the current energy price - but there’s no way of pointing the Energy Tab at a pricing capability.