PatchworkBoy / homebridge-edomoticz

Domoticz Homebridge-Plugin
Other
118 stars 43 forks source link

A request to add a Water Counter type #40

Closed dmikhalsky closed 6 years ago

dmikhalsky commented 8 years ago

Here is the JSON outcome for the device:

{ "ActTime" : 1472668145, "ServerTime" : "2016-08-31 21:29:05", "Sunrise" : "05:34", "Sunset" : "19:24", "result" : [ { "AddjMulti" : 1.0, "AddjMulti2" : 1.0, "AddjValue" : 0.0, "AddjValue2" : 0.0, "BatteryLevel" : 255, "Counter" : "211.200 m3", "CounterToday" : "100 Liter", "CustomImage" : 0, "Data" : "211.200 m3", "Description" : "", "Favorite" : 1, "HardwareID" : 2, "HardwareName" : "My GW", "HardwareType" : "MySensors Gateway USB", "HardwareTypeVal" : 41, "HaveTimeout" : false, "ID" : "0501", "LastUpdate" : "2016-08-31 20:43:05", "Name" : "Water Cold", "Notifications" : "false", "PlanID" : "0", "PlanIDs" : [ 0 ], "Protected" : false, "ShowNotifications" : true, "SignalLevel" : "-", "SubType" : "RFXMeter counter", "SwitchTypeVal" : 2, "Timers" : "false", "Type" : "RFXMeter", "TypeImg" : "counter", "Unit" : 0, "Used" : 1, "ValueQuantity" : "", "ValueUnits" : "", "XOffset" : "0", "YOffset" : "0", "idx" : "1" } ], "status" : "OK", "title" : "Devices" }

dmikhalsky commented 8 years ago

Just to clarify: this is a standard mysensors pulse watermeter, not something exotic, so adding it might be useful

PatchworkBoy commented 8 years ago

Have added that particular type / subtype combination to the existing Watermeter service - Head to homebridge-edomoticz/lib...

sudo mv domoticz_accessory.js domoticz_accessory.bak 
sudo wget https://raw.githubusercontent.com/PatchworkBoy/homebridge-edomoticz/4f41b0719ccd30465fbf174808cfd99e69bae8a2/lib/domoticz_accessory.js

Test & let me know...!

dmikhalsky commented 8 years ago

[eDomoticz] Initializing platform accessory 'Water Cold'... /usr/local/lib/node_modules/homebridge-edomoticz/lib/domoticz_accessory.js:1218 var wMeterDeviceService = new (this.name); ^

TypeError: this.name is not a function at Object.eDomoticzAccessory.getServices (/usr/local/lib/node_modules/homebridge-edomoticz/lib/domoticz_accessory.js:1218:33) at Server._createAccessory (/usr/local/lib/node_modules/homebridge/lib/server.js:357:36) at Server. (/usr/local/lib/node_modules/homebridge/lib/server.js:343:32) at /usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/util/once.js:15:19 at callbackLater (/usr/local/lib/node_modules/homebridge-edomoticz/index.js:172:37) at Object. (/usr/local/lib/node_modules/homebridge-edomoticz/index.js:201:17) at Request.self.callback (/usr/local/lib/node_modules/homebridge-edomoticz/node_modules/request/request.js:198:22) at emitTwo (events.js:87:13) at Request.emit (events.js:172:7) at Request. (/usr/local/lib/node_modules/homebridge-edomoticz/node_modules/request/request.js:1082:10)

dmikhalsky commented 8 years ago

I assume the line "var wMeterDeviceService = new (this.name);" should look like "var wMeterDeviceService = new eDomoticzServices.MeterDeviceService(this.name);"

I corrected this, and also changed "CurrentConsumption" charachteristic to "Total consumption"

The counter is now listed in Eve, but:

dmikhalsky commented 8 years ago

Ok, here what happens: when the counter changes in Domoticz, the correct value appears in Eve, but very briefly, than changes back to zero. So it's not persistent.

PatchworkBoy commented 8 years ago

OK - give it another try now - I added it to completely the wrong characteristic last time. It’s now been shifted into a different one...

sudo mv domoticz_accessory.js domoticz_accessory.bak 
sudo wget https://raw.githubusercontent.com/PatchworkBoy/homebridge-edomoticz/mqtt-integration/lib/domoticz_accessory.js
dmikhalsky commented 8 years ago

Thanks. Good news: flow counters (current consumption) work FLAWLESSLY now Bad news:

dmikhalsky commented 8 years ago

This type WORKS correctly:

{ "ActTime" : 1474567596, "ServerTime" : "2016-09-22 21:06:36", "Sunrise" : "06:16", "Sunset" : "18:27", "result" : [ { "AddjMulti" : 1.0, "AddjMulti2" : 1.0, "AddjValue" : 0.0, "AddjValue2" : 0.0, "BatteryLevel" : 255, "CustomImage" : 0, "Data" : "0.00 l/min", "Description" : "", "Favorite" : 1, "HardwareID" : 9, "HardwareName" : "My Pi", "HardwareType" : "MySensors Gateway USB", "HardwareTypeVal" : 41, "HaveTimeout" : false, "ID" : "00000501", "Image" : "Moisture", "LastUpdate" : "2016-09-22 21:02:44", "Name" : "Расход (Холодная)", "Notifications" : "false", "PlanID" : "0", "PlanIDs" : [ 0 ], "Protected" : false, "ShowNotifications" : true, "SignalLevel" : "-", "SubType" : "Waterflow", "Timers" : "false", "Type" : "General", "TypeImg" : "moisture", "Unit" : 1, "Used" : 1, "XOffset" : "0", "YOffset" : "0", "idx" : "62" } ], "status" : "OK", "title" : "Devices" }

This DOESN'T: { "ActTime" : 1474567677, "ServerTime" : "2016-09-22 21:07:57", "Sunrise" : "06:16", "Sunset" : "18:27", "result" : [ { "AddjMulti" : 1.0, "AddjMulti2" : 1.0, "AddjValue" : 0.0, "AddjValue2" : 0.0, "BatteryLevel" : 255, "Counter" : "224.000 m3", "CounterToday" : "400 Liter", "CustomImage" : 0, "Data" : "224.000 m3", "Description" : "", "Favorite" : 1, "HardwareID" : 9, "HardwareName" : "My Pi", "HardwareType" : "MySensors Gateway USB", "HardwareTypeVal" : 41, "HaveTimeout" : false, "ID" : "0501", "LastUpdate" : "2016-09-22 19:57:32", "Name" : "Счетчик (Холодная)", "Notifications" : "false", "PlanID" : "0", "PlanIDs" : [ 0 ], "Protected" : false, "ShowNotifications" : true, "SignalLevel" : "-", "SubType" : "RFXMeter counter", "SwitchTypeVal" : 2, "Timers" : "false", "Type" : "RFXMeter", "TypeImg" : "counter", "Unit" : 0, "Used" : 1, "ValueQuantity" : "", "ValueUnits" : "", "XOffset" : "0", "YOffset" : "0", "idx" : "66" } ], "status" : "OK", "title" : "Devices" }

PatchworkBoy commented 8 years ago

total consumption counters are not visible in Eve app

I’ve only written in Currentconsumption support... haven’t written in total consumption support.

something is accidentally broken with dimmable lamps (homebridge crashes when switching them on/off talking about "brightness not being defined". Reverting back to original domoticz_accessory.js fixed this

Dammit - I’ll have to drag @xTheRamon in on that - sorry Ramon - think I broke something in my manual merging!

This type WORKS correctly:

It’s just defaulting to a meter sensor which only shows the output from the Data: field in the JSON as the “Waterflow” subtype isn’t implicitly supported.

Different Type/SubType combinations have to be handled differently... for instance the first only presents the Data: field, whereas the second presents Counter & CounterToday which means needing their own service definitions. Units have to be stripped from the readings else you can’t use use the data for any automation rules.

I’m going to need MQTT output for the RFXMeter also if you can get it...? For most of my meters that output similarly to the RFXMeter, via MQTT domoticz ONLY sends current consumption. Never sends total consumption.

dmikhalsky commented 8 years ago

I’m going to need MQTT output for the RFXMeter also if you can get it...? For most of my meters that output similarly to the RFXMeter, via MQTT domoticz ONLY sends current consumption. Never sends total consumption.

yes, I recall analyzing MQTT output and noticing it. One of many Domoticz oddities. I'll look at it again and post RFXMeter MQTT output here

dmikhalsky commented 8 years ago

Here we go:

{ "Battery" : 255, "RSSI" : 12, "dtype" : "RFXMeter", "id" : "1280", "idx" : 67, "name" : "--------------", "nvalue" : 0, "stype" : "RFXMeter counter", "svalue1" : "150700", "unit" : 0 } so, the actual value (sans decimal point) is in svalue1. If needed, 1000 is the correct divider, so the value displayed in Domoticz is 150.7

PatchworkBoy commented 8 years ago

Cool - ta... but which value - current flow rate, or total flow rate? It’s only sending one. At the moment I’m assuming that’s current flow rate??

PatchworkBoy commented 8 years ago

OK - back up current installation, and pull the mqtt-integration branch again... I’ve now added implicit water flow handling for both sensor types above, hopefully with correct units also. The brightness side of things I’ll have to leave to Ramon as I don’t actually HAVE any dimmers to diagnose with, and he wrote all of the dimming support in the plugin.

dmikhalsky commented 8 years ago

Sorry if I made it not clear. I have 2 data types coming from the water meter: flow and total consumption. Flow shows momentarily flow and with the latest commit is shown correctly in Eve. I haven't posted the JSON for it since it works but I can if needed. Total consumption meter shows (you guess it!) total consumption since the time the counter was installed. The figure in svalue1 is the one I need and the one visible on the physical hardware.

There is the third parameter (dayly consumption) that Domoticz calculate itself. The node attached to the hardware counter doesn't send it. I know it for sure since I designed it :-) And It seems not be available in mqtt output.

PatchworkBoy commented 8 years ago

Yep - got all that... latest commit should cover it correctly, for both your RFXMeter > RFXMeter Counter Device (IDX 66 - reading the Counter and CounterToday fields via HTTP, updating the Counter field from svalue1 via MQTT in realtime), and your General > Waterflow device (IDX 62 - reading just the Data field, updating just the data field from svalue1 via MQTT in realtime).

What I was trying to establish is: If you take the MQTT output for IDX66, and compare it to the JSON output for IDX66, which two fields match up. What does svalue1 from the MQTT correlate to in the JSON.

dmikhalsky commented 8 years ago

usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/Service.js:52 this.getCharacteristic(Characteristic.Name) || ^

TypeError: this.getCharacteristic is not a function at Service (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/Service.js:52:12) at new eDomoticzServices.WaterDeviceService (/usr/local/lib/node_modules/homebridge-edomoticz/lib/services.js:98:13) at Object.eDomoticzAccessory.getServices (/usr/local/lib/node_modules/homebridge-edomoticz/lib/domoticz_accessory.js:1249:31) at Server._createAccessory (/usr/local/lib/node_modules/homebridge/lib/server.js:357:36) at Server. (/usr/local/lib/node_modules/homebridge/lib/server.js:343:32) at /usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/util/once.js:15:19 at Object. (/usr/local/lib/node_modules/homebridge-edomoticz/index.js:203:41) at Request.self.callback (/usr/local/lib/node_modules/homebridge-edomoticz/node_modules/request/request.js:198:22) at emitTwo (events.js:87:13) at Request.emit (events.js:172:7)

PatchworkBoy commented 8 years ago

rolls eyes I forgot to add the new services to the inheritance patches. Repull index.js and should be fixed - sorry!

dmikhalsky commented 8 years ago

/usr/local/lib/node_modules/homebridge-edomoticz/lib/domoticz_accessory.js:1250 WaterMeterService.getCharacteristic(eDomoticzServices.Waterflow).on('get', this.getStringValue.bind(this)); ^

TypeError: Cannot read property 'on' of undefined at Object.eDomoticzAccessory.getServices (/usr/local/lib/node_modules/homebridge-edomoticz/lib/domoticz_accessory.js:1250:71) at Server._createAccessory (/usr/local/lib/node_modules/homebridge/lib/server.js:357:36) at Server. (/usr/local/lib/node_modules/homebridge/lib/server.js:343:32) at /usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/util/once.js:15:19 at Object. (/usr/local/lib/node_modules/homebridge-edomoticz/index.js:206:41) at Request.self.callback (/usr/local/lib/node_modules/homebridge-edomoticz/node_modules/request/request.js:198:22) at emitTwo (events.js:87:13) at Request.emit (events.js:172:7) at Request. (/usr/local/lib/node_modules/homebridge-edomoticz/node_modules/request/request.js:1082:10) at emitOne (events.js:82:20)

dmikhalsky commented 8 years ago

If you take the MQTT output for IDX66, and compare it to the JSON output for IDX66, which two fields match up. What does svalue1 from the MQTT correlate to in the JSON.

MQTT svalue1 "224500" partially correlates to JSON "Data" : "224.500 m3" or "Counter" : "224.500 m3" There is no 1:1 match. It looks like MQTT provides raw data, while JSON is more "formatted" or "as is in GUI"

rswilem commented 8 years ago

I've only just now read that you dragged me in on this one. Haha. Whoops. I won't fix anything with dimmers now though as it seems they're working perfectly now.

PatchworkBoy commented 6 years ago

Create a new issue if still exists in current version - originally raised under v1.x - we’re not on v2.x