Baldhor / Homey-ESPhome-Enhanced

This is an Homey app which adds support for ESPHome devices. ESPHome is a system to control your ESP8266/ESP32 by simple yet powerful configuration files and control them remotely through Home Automation systems. More information on their homepage: https://www.esphome.io/
GNU General Public License v3.0
4 stars 3 forks source link

Extra option for measuring devices #39

Closed RoadXY closed 9 months ago

RoadXY commented 9 months ago

Describe the solution you'd like Some devices, such as example a P1 meter or current clamp, can measure the total energy usage of a home or power group. For this to work you should be able to set the cumulative property to true.

See here: https://apps.developer.homey.app/the-basics/devices/energy#measuring-devices

Baldhor commented 9 months ago

@RoadXY For me, it's impossible to use this feature. It's at the "driver" level and cannot be overwritten at the device level.

This kind of feature just cannot be used with "generic" driver.

In my opinion, the cumulative should be handled in the ESPhome configuration. Or a virtual device from another app.

Baldhor commented 9 months ago

The only other solution would be the ability to add a convert function to a capability.

On reception of a new value, the device would execute this function:

processNewStateValue(currentValue, newStateValue, processingFunction) {
  return eval(processingFunction);
}

By default, processingFunction would be: "newStateValue"

But you could overwrite it (through a dedicated capability option in the wizard): "currentValue + newStateValue"

I suppose this function should only be available for number capability. At least for your need, but why not apply it to anything ...

RoadXY commented 9 months ago

@RoadXY For me, it's impossible to use this feature. It's at the "driver" level and cannot be overwritten at the device level.

This kind of feature just cannot be used with "generic" driver.

In my opinion, the cumulative should be handled in the ESPhome configuration. Or a virtual device from another app.

It's only a sort of tag to tell Homey it is an device which has a value which is cumulative. So Homey does not add it up with all the other devices using power.

Baldhor commented 9 months ago

@RoadXY Ok so I don't understand how it works. It's a driver level parameter and cannot be modified by the user. It will change the behaviour of ALL ESPhome devices. So I'm worried about it!

RoadXY commented 9 months ago

It will only affect the Homey device it has been set on. Should be an checkbox during pairing somewhere here. Screenshot_20230909-112244

Baldhor commented 9 months ago

@RoadXY Based on the description it's at driver level, not device: image

Baldhor commented 9 months ago

Same problem as the battery, ... cannot make it "device" specific

RoadXY commented 9 months ago

I had it with a checkbox in the pairing wizard and only when checked that device was 'cumulative'...

Baldhor commented 9 months ago

@RoadXY You mean with your version of the app? before I take it over?

Baldhor commented 9 months ago

I cannot see anything related in the code, so I'm unsure what you refer to

RoadXY commented 9 months ago

Have been searching and you're right. It wasn't on my Github just yet.

Ronny has this as an setting and he's able to set the cumulative in code so not every device is affected by it: https://github.com/search?q=repo%3ARonnyWinkler%2Fio.home-assistant.community%20cumulative&type=code

Baldhor commented 9 months ago

Nice catch, there are 2 functions on Device object: https://apps-sdk-v3.developer.homey.app/Device.html#getEnergy https://apps-sdk-v3.developer.homey.app/Device.html#setEnergy

Meaning at driver level, it's for "default" values, but we can modify it per Device ...

await this.setEnergy({
"cumulative": value
 }

I suppose it's possible to modify the batteries too ... but that's another subject :)

Baldhor commented 9 months ago

I will not implement it in the current version, but only in #30 improved-ui.

Baldhor commented 9 months ago

@RoadXY Can you just describe what it does exactly? I'm annoyed because even at "device" level, it will impact all the capabilities of the device. I'd prefer to be able to configure it individually for each capability!

If it just add up everytime a new value is received, it's very simple to implement, no need of that "battery.cumulative" setting.

RoadXY commented 9 months ago

This will tell Homey it is a device which has a total/cumulative representation of the power and/or energy used by your house. This way Homey won't treat this device as a power using device (like it does now). See here: https://apps.developer.homey.app/the-basics/devices/energy#measuring-devices

It should be under 'slimme meters' (smart meters) Screenshot_20230912-163143

Now Homey is just adding the total house usage like it was a single device using energy right now! (Currently negative because I have solar panels producing power right now) Screenshot_20230912-163134

Baldhor commented 9 months ago

@RoadXY I would go for what Adrian said in the following post: The measure_power capability has some other internal function as it determines what appears in the Energy tab of the app, however meter_power is only applicable to your device, so it can have whatever meaning you want.

https://community.homey.app/t/how-does-homey-process-power-measurements-via-setcapabilityvalue/69086/8

For me, if you want the value to be excluded from energy panel, just use meter_power instead of measure_power.

The cumulative setting draw too much issues not in line with the spirit of ESPhome. The setting apply to ALL the capabilities of the device, so you cannot have measure_power.instant and measure_power.cumulative. Use measure_power (for instant), and meteer_power (for cumulative) !

I would like to close this issue :)

RoadXY commented 9 months ago

Yes, but then Homey does not know how much power is drawn by the house but only knows how much individual devices use. I do get what you're saying about the spirit of ESPhome.

Maybe add an check for the number times measure_power is being used and display an error message when more then 1 is specified?

However I do get it will be an edge case. If the issue pops up for more users it might end back up your ToDo list 😉