Smanar / Domoticz-deCONZ

deCONZ plugin for Domoticz (Zigbee application)
GNU General Public License v3.0
37 stars 26 forks source link

Wrong power consumption when there is more than one device #41

Closed markhellegers closed 4 years ago

markhellegers commented 4 years ago

I have two innr smartplugs that report the power consumption. However, according to the logging they do this interleaved. This causes the power from one plug to be reported in the consumption of the other.

I looked at the code and the problem seems to be that there is a buffercommand variable that assumes that the last reported power is for the device that is now reporting the consumption. I am not sure what the best fix would be. I would guess best would be to know which device the power is registered for.

Smanar commented 4 years ago

Hello. But you have not 2 websockets notifications, one for each devices, with "power" and "consumption" in all of them ? Or 1 for "power" and 1 for "consumption" (so 4 notifications in total) ?

Your device is a ZHAConsumption and not a ZHAPower ?

If "websocketnotifyall" is set to "true" you normally have the both information in the same notification, so clear the field "buffercommand" and the start of the fonction ProcessAllState() will be enought ? But normally the code check first for "power" then for "consumption" (for the same notification) and the second one overwrite the data with both values and clear the field.

markhellegers commented 4 years ago

Hello,

I see this in the logging. Hope that makes it clearer:

2020-01-04 20:29:16.685 (Conbee) ### WebSocket Data : {'e': 'changed', 'id': '2', 'r': 'sensors', 'state': {'consumption': 410, 'lastupdated': '2020-01-04T19:29:16'}, 't': 'event', 'uniqueid': '00:15:8d:00:03:42:a7:ab-01-0702'} 2020-01-04 20:29:16.686 (Conbee) ### Update device (Device A - Consumption 2) : {'nValue': 0, 'sValue': '0;410'}, IGNORED , no changes ! 2020-01-04 20:29:17.588 (Conbee) ### WebSocket Data : {'e': 'changed', 'id': '3', 'r': 'sensors', 'state': {'current': 24, 'lastupdated': '2020-01-04T19:29:17', 'power': 3, 'voltage': 236}, 't': 'event', 'uniqueid': '00:15:8d:00:03:42:a7:ab-01-0b04'} 2020-01-04 20:29:17.589 (Conbee) ### Update device (Device A - Power) : {'nValue': 0, 'sValue': '3'}, IGNORED , no changes ! 2020-01-04 20:29:18.491 (Conbee) ### WebSocket Data : {'e': 'changed', 'id': '4', 'r': 'sensors', 'state': {'consumption': 7850, 'lastupdated': '2020-01-04T19:29:18'}, 't': 'event', 'uniqueid': '00:15:8d:00:03:42:f0:8e-01-0702'} 2020-01-04 20:29:18.492 (Conbee) ### Update device (Device B - Consumption 4) : {'nValue': 0, 'sValue': '3;7850'}, IGNORED , no changes ! 2020-01-04 20:29:19.394 (Conbee) ### WebSocket Data : {'e': 'changed', 'id': '5', 'r': 'sensors', 'state': {'current': 0, 'lastupdated': '2020-01-04T19:29:19', 'power': 0, 'voltage': 234}, 't': 'event', 'uniqueid': '00:15:8d:00:03:42:f0:8e-01-0b04'} 2020-01-04 20:29:19.395 (Conbee) ### Update device (Device B - Power) : {'nValue': 0, 'sValue': '0'}, IGNORED , no changes !

The overview in Domoticz says that the consumption device has type "General" and subtype "kWh", while the power device has type "Usage" and subtype "kWh".

Where can I check for "websocketnotifyall". I am still a bit new to Domoticz and the plugin.

Smanar commented 4 years ago

Don't worry, you have a message when you start the plugin about this option, but you have it to "true"

And yes, you are right, on your log you are updating" Device B - Consumption 4" with 'consumption' from the notification but with the power from "Device A - Power".

In fact this device create one device for consumption 00:15:8d:00:03:42:a7:ab-01-0702 and one other for power 00:15:8d:00:03:42:a7:ab-01-0b04. Some other device use the same cluster 0b04 only.

Will be easy to correct, like i have said before, I just need to reset the field

clear the field "buffercommand" and the start of the fonction ProcessAllState()

But I need to make some tests, the device created in domoticz use both value, power and consumption, in your situation power will be always 0, because you have it on other device. So I need to check how domoticz will react.

I will give you a code to try tomorrow.

Smanar commented 4 years ago

Ok so you have news files here https://github.com/Smanar/Domoticz-deCONZ/tree/beta

But you need to delete your device "(Device X - Consumption)" and restart the plugin after modification, devices will be re-created but as energy counter. You can't have the same device than previously. Some plugs have power and consumption on same device on domoticz, but on your situation you will have them separated.

nesalkiN commented 4 years ago

Noticed the same thing. I also have two innr plugs (SP 120). Beta looks better.

Thanks!

For comparison:

This is a z-wave power plug (PowerNode, not added devices to Domoticz, only use is as repeater): Capture_Domoticz_-_Google_Chrome_2020-01-06_19-05-39_25603216

This is the beta of this plugin with the new devices (2 plugs): Capture_Domoticz_-_Google_Chrome_2020-01-06_19-13-39_68471644

One thing, it doesn't show "Today:" for the "General, Managed Counter" as it does when the type is "General, kWh". Don't know how this will affect the reports (and cost) section yet.

Capture_Domoticz_-_Google_Chrome_2020-01-06_20-22-49_26341280 vs Capture_Domoticz_-_Google_Chrome_2020-01-06_20-21-22_81556607

"Elmätare" is a MySensors device counting pulses from my power meter for the house Capture_Domoticz_-_Google_Chrome_2020-01-06_20-28-42_13114585

Screenshot_20200106-204028

Sorry for all the edits. Adding info as I go. On small thing triggering my OCD. Added some Aqara vibration sensors: https://github.com/Smanar/Domoticz-deCONZ/blob/9f9566e143d74b31e42d9e7725af48c01f999e9d/plugin.py#L1204 The "d" in "Drop". ;-)

Smanar commented 4 years ago

Typo corrected, thx :)

For counter, I m not sure yet ^^. I have, as choose at least

1 - General/Managed counter. 2 - General/KWh 3 - RFXmeter/RFX meter counter.

For sure I can have report and cost for the three. I have checked (on other hardware), but not sure it's working, I think we need at least 24h for a first result.

I need to use fakes values to use the 2, because it works with power and not consumption in reality.

But I haven't understand how they make cumul and use the "today" feature. The three can have it but the display seem random, only the 2 have this line all the time.

For the 2, it 's easy, this device works with power, so domoticz can make calculation itself. But for other, I think it's the device that make calculation and send directly a cumul.

For your server (server kw/h), the value go down, or only increase ?

nesalkiN commented 4 years ago

18 kWh in total since plugging in the innr plug. The server use about 1.5-1.8 kWh/day.

The devices named "Server" shown in my screenshots comes from this plugin (the beta branch)

Smanar commented 4 years ago

Ok, so I realy thing it's better to take General/Managed counter, this device is just a counter and only that. If you take a look in the device Elmatare General/kwh, you have on the titlebar, a power and not a comsumption, and you have just under the consumption but just for the day.

Now just need to be sure the report and cost are working corectly.

nesalkiN commented 4 years ago

Yes, I want to see the daily kWh usage to detect any strange deviations from day to day. The last image comes from the Domoticz app's widget.

The MySensors device called "Elmätare" is based on this: https://www.mysensors.org/build/pulse_power (Reports both kWh and Watt back to gateway so the calculation happens in device, the innr plug also reports total kWh usage and current watt usage?)

I have no history at all yet. The kWh-usage keeps going up as it should.

nesalkiN commented 4 years ago

History and report is still empty. It would be great iaf General, kWh could be used.. We need to send the total kWh usage and current watt usage to the (same) device. I think the plug will report that info?

Other plugs will use three devices. The on/off switch, General kWh (kWh and watt) and Usage, Electric (watt). No need for domoticz to calculate kWh or watt, the plug does that.

Smanar commented 4 years ago

Yep, but to use the General, kWh, I need to use special value for power, so I prefer use it in last try.

I have just find some new counter Domoticz_PowerUsage

It reset itself, and display today usage But this one make addition itself, if you send 5kw/h then 10 kw/h it will display 15 and not 10.

So I m testing this one ATM aaa You have the actual consumption, and another value on title, but I haven't understand what is it (perhaps daily)

But I have history working on all of them, IDK why it's not working on your machine.

Edit: Ok it's that, you have the cumul on the first line, and on title domoticz, make calculation for daily consumption.

So if you want to make a test, I can configure the second one ? 0.088 is the value send by the device, so it increase itself. 0.089 is a value calculated by domoticz (according to time) for a day.

Edit2: I have open an issue on domoticz to have clarification on how work their counter ....

nesalkiN commented 4 years ago

Some of the counter types use the division you set in Domoticz settings. Capture_Domoticz_-_Google_Chrome_2020-01-07_19-19-44_65310506

It's just a counter counting stuff. I used the RFXMeter counter in my old house. Counting pulses from the power meter (10 000 pulses = 1kWh). It was just that. Counting the number of pulses and Domoticz divided it and made it show in kWh.

I need to read everything again when at my computer.

Smanar commented 4 years ago

But this one don't count, it just display the value I send to it (and using the division) !

I have created 2 widgets with the same setting. The first one display the value I send + 1 and the other the value I send - 1.

https://www.domoticz.com/forum/viewtopic.php?f=28&t=30815&p=233096#p233096

nesalkiN commented 4 years ago

Not sure that i fully understand.

This can't be used? https://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s#Electricity_.28instant_and_counter.29

Power from the "active power" value from the plug (currently 62 watt): Capture_192 168 1 25_(deconz0_(root))_-_VNC_Viewer_2020-01-07_20-06-28_84866561

The ENERGY value from the counter in the plug (currently 20.29 kWh, 20290 Wh since plugged in): Capture_192 168 1 25_(deconz0_(root))_-_VNC_Viewer_2020-01-07_20-07-20_68276605

Just guessing here. Sorry, I know too little. I don't know how the data looks from deCONZ. Need to learn Python I guess. ;)

Smanar commented 4 years ago

Nope you are right ^^. But your device create 2 widgets in domoticz (because it use 2 differents cluster), one with only power and another with only consumption, it depend on device (some other just create one, use the command on your previous link and are already working), and each of them receive it's own new value.

The domoticz widget general/kwh is a good widget but I will not use at 100% for your device. So I m searching a consumption widget, with daily information.

it exists on domoticz, and domoticz can manage them itself (reset every day for exemple), but I don't find how they work.

The rfxmeter device look good, but it works realy strange during my test. You can check on your widgets, I think you already have one working ? He have

It's just perfect for me, except the strange working mode ....

nesalkiN commented 4 years ago

I don't have any rfxmeter device anymore. When I had, it was a simple 1-wire counter, no kWh, no watt. Domoticz did the calculations.

I do have one z-wave power plug (with almost no load connected). Looks like this: Capture_Domoticz_-_Google_Chrome_2020-01-07_21-56-54_07134626

Capture_Domoticz_-_Google_Chrome_2020-01-07_21-57-33_64878651

I also have the MySensors device mentioned before. Looks the same as the z-wave plug. Same type and subtype as the z-wave plug. I could probably do some Lua-scripting and update my own virtual "General, kWh" device if needed to make the innr plugs look like the other power meters.

Smanar commented 4 years ago

Give me some days (waiting for return from domoticz community) to make a try.

The rfxmeter will not look like the Zwave kwh Meter. But it will be more usable, for exemple you will have total consumption (not present in zwave widget), the future device will be a widget made just for consumption. IDK how will be the report but I realy think I will be fine.

If, realy, the future widget will be bad, I will make with the general/kwh but I see lot of disadvantages with it.

nesalkiN commented 4 years ago

Ah. I see what you mean. No problem. I can create my own as long as I have access to current watt and (k)Wh value.

Total usage checked using the reports. My energy meter for the whole house (MySensors) is at 14028.009 kWh. Not much of use to see the total usage in the widget for that one 😉..

Thank you for taking your time to look at it!

Smanar commented 4 years ago

@NiklasOlofsson Ok so I have a new counter to try > https://github.com/Smanar/Domoticz-deCONZ/commit/87b3c8dedfa2770acee325354de953f26f0c4c54#diff-66c71ea3faaa52c277917c951aa67921

Good point:

Bad point

I have updated my domoticz version, because on previous It log bad value when the counter reset. The widget do the math : Today = actual - previous, but if the counter reset you have actual = 0 so a negative value > bug. I m making test since 2 / 3 days, it seem working now, but you need at least 24h to have correct data.

Pls tell me how you fell this one !

nesalkiN commented 4 years ago

From Domoticz in webbrowser; Screenshot_20200112-014333

Widget from the Domoticz Android app on my home screen. Screenshot_20200112-014121

Seems to work just fine. Will evaluate in a couple of days with some history to talk about.

Thanks!

Smanar commented 4 years ago

So, no problem, how is the device ?

If you have same probleme than me with "big number", can you make a screeshoot for I make an issue.

nesalkiN commented 4 years ago

Looking good here. No problem with big numbers. Don't know what will happen if I cut power to the plug. If the counter value is saved in the plug or starts at 0 again. Then, it could lead to problems. I had that problem when using a 1-wire counter and the RFXMeter device a couple of years ago.

Smanar commented 4 years ago

And yes, it's that the problem ^^. When you power off the plug, the counter restart to 0, this is something normal on this device I think, but on domoticz side, sometime it works, but sometime the first value is a big one, it will be corrected at first next good value, but on old domoticz version the "fake value" was stored in database, and make report totaly useless.

I have make a post about this https://www.domoticz.com/forum/viewtopic.php?f=28&t=30815&p=233096#p233096 And I m not alone, other counter are buggy too. https://www.domoticz.com/forum/viewtopic.php?f=6&t=30083&p=233353

But without answer, so if you still have the problem, I will make an issue.

I did not have the problem on my last tries, but tell me if you see it (you will see it on report, on dashboard it will be corrected itself by domoticz after some good value)

nesalkiN commented 4 years ago

Just a power cut. Strong winds outside today.

Capture_Domoticz_-_Google_Chrome_2020-02-09_20-43-35_43425232

Don't know if the counter in the plug has been reset to 0. Will look in to it.

Edit: No reset. Why the high value then? Strange. Capture_192 168 1 25_(deconz0_(root))_-_VNC_Viewer_2020-02-09_20-50-41_63533626

Capture_Domoticz_-_Google_Chrome_2020-02-09_20-52-23_45311033 I will just delete the big numbers with shift+click for now. :)

Smanar commented 4 years ago

It haven't reset ? The bug is from domoticz code, they just make

total_day = total_send - total_min_today

And I send the cumulated value you have on the device at the device, 828 on your screenshot. Domoticz calculate itself the daily consumption with this formula.

If you make a reset, the send value decomes 0 so you have

total_day = 0 - another_value

And the variable used can't be negative, so you have a "big number".

I think you had a situation where the plugin have received a consumption = 0 (without reset, just bad value). So in this situation, I m agree it's a bug from the plugin (or perhaps deconz, but without log, We'll never know) but if you make a reset you will same problem, so for me, the domoticz code need to be patched too.

I m making a domoticz issue ATM.

Smanar commented 4 years ago

@NiklasOlofsson I m trying to simulate your bug, but I can't.

Can you explain what have happened ? You have a power cut during some hours, with the plug and domoticz off ?