Energy of virtual device not in energy tab

Hi, I’ve added a virtual device “Warmtepomp 2“ that perfectly shows the “Vermogen“ But the Total kWh remains empty and also the device not not shown on the energy tab as energy comsumer. What do I do wrong?

You forgot the Energy measurement
Power = Watts
Energy = kWh (the used Watts per hour)

Add another card and use this Energy capability:
meter_power

It should be feeded with the kWh tag

1 Like

Hi Peter, Thank you for your swift response! I was under the impression that Homey would calculate the value itself based on the Watts. I think should feed this with the p1 total “Totaal t3 gebruik? Somehow that does not give a value, so then I have to check what is wrong with the (homewizard) p1 meter integration.

T1, T2, T3 and T4 are tariffs. So T1/T2 (dal/normaal). Some countries have T3 and T4 (Germany, France, Italy?, UK)

1 Like

Hi Jeroen, Thank you for your answer! That makes sense. But it also means that there is no total to be found in the homewizard p1 data of the phase 3 (wich is dedicated to the warmtepomp) @Peter_Kawa is there any way to calculate it?

Wait wait, total of what?

I have a warmtepomp (heatpump) that runs dedicated on phase 3 So all the energy used from the 3rd phase in my house is the warmtepomp. The goal is to get this device as an energy consumer in my homey energy tab. I tried to achieve this by adding a virtual device, and feeding it with the measure_power. (huidige gebruik fase 3 (W) ) This shows the current usage indeed and I thought this would be enough. But according to @Peter_Kawa I also have to give the total power (kWh). That is the point where I am now.

Your “slimme meter” does not track kwh per phase and hence your P1 wont provide that.
What you want requires a kwhmeter in between so a SDM230 or SDM630. That will track usage (kwh).

Also it is not an option to estimate kwh based on watts + time. You will miss samples and the calculation / estimation will not be correct. You really need a kwh meter before your “warmtepomp” to track usage. Or a energy_socket if watts is within the capabilities of the socket.

1 Like

AI, Dat is balen. Jammer maar dank voor de uitleg!

I believe a summarizer from Power by the Hour app can be configured to generate a decent approximation of the energy from a power reading. Then you no longer need the virtual device or the flow to update it.

That will take the overall usage from the P1 and not per phase, moreover as I mentioned above, it will be an estimate as it will not track the fluctuations between polls. Say 10s poll, measure 100w, then for 8s its 1000w and at the next 10s sample its 100watts, you would miss the 8s 1000watt / kwh track.

Damn, that’s correct. Double damn, because not being able to pick a specific source from a device is my only complaint with the app.
All is not lost, keep the flow and the virtual device and add a summarizer and it will work.
Yes, it is an approximation, but I suspect this load doesn’t have a lot of fast fluctuations.

I’ve used the energy change trigger of the homewizard p1 to update a total kWh variable that is calculated based on the last timestamp and the wattage. Since the time inbetween is 2 seconds I assume (so indeed I do not know and it will be a guestimate) I think it is the best I can do for now with the hardware I have in place.

And the good news, for me.. if the data is almost correct (to be tested :slight_smile: ) the warmtepomp does occur in the enery tab now.

For documentation purposes hereby the script that i use (HomeyScript, written by gemini) The flow and a short output that I logged for testing purposes.

TEST OUTPUT

FLOW

Note; the google sheets log is not needed, just used for testing

SCRIPT:

// 1. Wattage ophalen
const currentWattage = parseFloat(args[0]); 
if (isNaN(currentWattage)) {
    console.error("Geen geldig wattage ontvangen");
    return false;
}

const now = Date.now();

// 2. Tijd ophalen uit de Logica Variabele
const vars = await Homey.logic.getVariables();
const tijdVar = Object.values(vars).find(v => v.name === 'Laatste_Meting_Tijd');
const totaalVar = Object.values(vars).find(v => v.name === 'Totaal_Verbruik_kWh');

if (!tijdVar || !totaalVar) {
    console.error("FOUT: Controleer of 'Laatste_Meting_Tijd' EN 'Totaal_Verbruik_kWh' bestaan.");
    return false;
}

const lastRun = parseFloat(tijdVar.value);
let consumedKWh = 0;

// 3. Bereken verbruik als er een vorige tijd bekend is
if (lastRun > 0) {
    const timeDiffHours = (now - lastRun) / (1000 * 3600);
    consumedKWh = (currentWattage * timeDiffHours) / 1000;
    
    const nieuwTotaal = (parseFloat(totaalVar.value) || 0) + consumedKWh;
    
    // Update Totaalverbruik
    await Homey.logic.updateVariable({ 
        id: totaalVar.id, 
        variable: { value: nieuwTotaal } 
    });
    console.log(`Toegevoegd: ${consumedKWh.toFixed(8)} kWh`);
} else {
    console.log("Eerste run: Tijdstempel vastgelegd.");
}

// 4. Update de tijdstempel voor de volgende keer
await Homey.logic.updateVariable({ 
    id: tijdVar.id, 
    variable: { value: now } 
});

return true;

VARIABLES

Well it is still an estimate, beware when your P1 (or Homey) drops/looses its “wifi” connection the updated watt samples per 2s will be missed. Sure the script is nice but not as perfect when a kwh meter that tracks the real deal per kwh.

Anyway, good job @Martijn_W :slight_smile:

1 Like

Thanks If I’m correct it should not depend on the 2 seconds, but it calculates since the last measuring. If the wifi is out for a certain time the values will be less accurate indeed. You’re totaly right that the real deal would be preferable with a dedicated meter.

Thank you all for your help and support!

Another thing you can try is P1 but APIv2 based. That support websocket. Has a 1s update and should be less stressful for Homey and P1.

My 2cents