drc38 / DiUS_Powersensor

Home Assistant Custom Integration for DiUS Powersensors
MIT License
9 stars 0 forks source link

Support multiple plugs #38

Open izevaka opened 2 years ago

izevaka commented 2 years ago

Is your feature request related to a problem? Please describe. I added two plugs through the HACS component. This resulted in both plugs updating the same sensor.

Describe the solution you'd like I would like to see that the two plugs create separate sensors.

Describe alternatives you've considered Potentially use a template sensor to create two sensors and filter them based on the MAC address? Not sure if this is HA-y enough though...

Additional context Just opening this for visibility. I'd like to work on this one and contribute :D

drc38 commented 2 years ago

How about simply using the plug name? In the options flow you could add a plug by specifying its name (or mac address). Have a look at the tuya local integration. A more advanced approach would be to auto-detect a new plug based on the datastream and add it. Look forward to seeing what you come up with!

jonaseymour commented 2 years ago

Would this be similar process for adding extra sensor? I was able to add multiple sensors with izevaka's node-red integration by adding an extra mqtt entry in my config with the relevant MAC address of both sensors, but this integration only picks up one automatically (for me the solar generation, not home consumption).

Happy to do any testing, now that I've figured out my IP issue.

drc38 commented 2 years ago

Uploading a log showing the raw output of multiple sensors/plugs would be useful as I only have 1 sensor and 1 plug.

jonaseymour commented 2 years ago

You mean like the raw output from listening to the plug? I get a heap of plug messages and then get 2 separate messages with different mac addresses for the sensor detail. Taken from debugging izevaka's node-red flow:

solar: {"mac":"xxxxxxxxxxa9","device":"sensor","summation":823599143,"duration":30,"type":"instant_power","batteryMicrovolt":4110304,"unit":"w","starttime":1658748977,"power":7} Sorry, it's nighttime so the power is +7, which I think is the inverter drawing power. Normally it shows negative values when generating.

meter: {"mac":"xxxxxxxxxx87","device":"sensor","summation":80125552,"duration":30,"type":"instant_power","batteryMicrovolt":4106208,"unit":"w","starttime":1658748977,"power":536}

Hope that helps. Happy to provide other logs/detail if you can tell me how to access them.

drc38 commented 2 years ago

Thanks @jonaseymour. @izevaka for an extra sensor per mac and per device type I think you'll need to add code to api.py to check the incoming messages for a unique mac address and increment a counter. The counter can then be used to create individual HA sensors for each unique mac in sensor.py.

jonaseymour commented 2 years ago

No worries. Do we know what the "summation" value is in the messages? Is that some sort of track of the Whs of the sensor since installation? If so, that might be useful to capture and track to have an increasing sensor of production, as currently you have to template one in HA to use in energy cards.

On that note, I've got a chat scheduled with the Powersensor team next week after filling out their 'Feature Roadmap form' to provide feedback so far and thoughts on future development. I was planning on asking if they had plans to release a local API and/or official HA integration. If you have anything else you'd like me to raise let me know.

izevaka commented 2 years ago

Summation is the sum of watts since the beginning of time. It increments by the power value on every reading.

Ive had a twitter conversation about this and the conclusion was that these sensors need to be a lot less chatty. Reporting power every second is an overkill, hence my latest updates to the readme, it overloads the recorder database. Using the summation value might just help with that.

jonaseymour commented 2 years ago

My quick calc of the difference between 2 sensor summations didn't match the power reading. But now that I look at it, I think it's actually an average W/second over the duration. So for the plug where you get a message about every second it basically increments by the power, but for the sensor where you get messages less often, it's an average.

i.e. {"mac":"xxxxxxxxxx87","device":"sensor","summation":174635611,"duration":30,"type":"instant_power","batteryMicrovolt":4102112,"unit":"w","starttime":1658964257,"power":-1865} next message: {"mac":"xxxxxxxxxx87","device":"sensor","summation":174580488,"duration":30,"type":"instant_power","batteryMicrovolt":4106208,"unit":"w","starttime":1658964287,"power":-1838}

Difference in summation (over 30s) is -55123, but power is only -1838 for that message. But 1838/55123 = 29.99. So the power variable is basically the average 'instant power' since the last message.

Chattiness only really seems to be an issue for the plug. I guess they drop the frequency of sensor messages to save battery power, but that's not an issue for the plug.

drc38 commented 2 years ago

Based on the above the summation unit is Ws, so to convert to kWh you could divide it by 3,600,000

salty2011 commented 1 year ago

Hey, is this still an issue?

Just bought one of these to use in Home Assistant, however for my situation will need two plugs as solar inverter and mains are opposite end of the house.

Looking through the documentation and this reported issue not clear if my situation is going to be an issue

drc38 commented 1 year ago

@izevaka have you made any progress on having more than 1 sensor?

izevaka commented 1 year ago

Hey all. Haven't looked at this. Got as far as installing the dev environment before life got in the way :)

On Fri, Dec 30, 2022 at 5:20 PM drc38 @.***> wrote:

@izevaka https://github.com/izevaka have you made any progress on having more than 1 sensor?

— Reply to this email directly, view it on GitHub https://github.com/drc38/DiUS_Powersensor/issues/38#issuecomment-1367748133, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAC53L3LMFKY4IV5N3FZUP3WPZ5JJANCNFSM53ZUK3TA . You are receiving this because you were mentioned.Message ID: @.***>

jonaseymour commented 1 year ago

Hey, is this still an issue?

Just bought one of these to use in Home Assistant, however for my situation will need two plugs as solar inverter and mains are opposite end of the house.

Looking through the documentation and this reported issue not clear if my situation is going to be an issue

If you want a workaround in the meantime. I've still been using izevaka's original node-red method until this is resolved here. It's pretty straight-forward to add an extra sensor to that set up. You just need the mac address (I assume the same for plugs). But agree, that it would be great to use this integration instead of relying on node-red. For me, this is literally my only use of node-red, so I could remove it if not required.

isngofoz commented 1 year ago

Hi all, I am glad I found this integration as I don't think many people use PowerSensor. Unfortunately, I have 2 sensors. One for Solar Production and the other for Total Home Consumption. I think the integration is picking up the Total Home Consumption sensor. I have got a fair bit of solar panels on my roof, during the day it is mostly exporting, so I am getting negative figures. I am reading that there is a plan to add the ability to read another sensor?

drc38 commented 1 year ago

Unless I get another sensor I've got no plans to update the repo. Powersensor are planning on releasing an official api, so this integration may become defunct.

jonaseymour commented 1 year ago

Hi all, I am glad I found this integration as I don't think many people use PowerSensor. Unfortunately, I have 2 sensors. One for Solar Production and the other for Total Home Consumption. I think the integration is picking up the Total Home Consumption sensor. I have got a fair bit of solar panels on my roof, during the day it is mostly exporting, so I am getting negative figures. I am reading that there is a plan to add the ability to read another sensor?

Yes, you're reading that correctly. If you want 2 sensors at the moment you'd have to use izevaka's node-red method I mentioned above.

Powersensor are planning on releasing an official api, so this integration may become defunct.

This is good news!

isngofoz commented 1 year ago

Yeah, I went to izevaka's node-red method, it is taking me a while to understand what to do. Probably need to go through it on a day that I am not that busy.

Any idea when Powersensor has planned to release their official api?