openhab / openhab-addons

Add-ons for openHAB
https://www.openhab.org/
Eclipse Public License 2.0
1.86k stars 3.58k forks source link

DSMR binding for OH2 #1608

Closed metbril closed 6 years ago

metbril commented 7 years ago

@mvolaart Any chance you will port the DSMR 1.x binding to OH2?

Cc @martinvw

mvolaart commented 7 years ago

@rtvb Yes, i will port the binding. Untill now i have not done anything with OH2 so i have at this moment no idea what has to done and when it will be ready.

I will look into this.

martinvw commented 7 years ago

You should be able to use it already as it is. The only thing that does not yet work is auto discovery. But the basic configuration via the paper ui already works great. You must add your items manually and things are not supported.

mvolaart commented 7 years ago

I have my OH2 setup running now including the OH1 version of the binding running without problems.

I started developing the OH2 binding for DSMR.

I will post any updates regarding the development here.

RolandWijnen commented 7 years ago

@mvolaart Great that you wrote the DSMR binding! Very cool to connect my Smart Meter to OpenHAB. My meter is recognized. Just wondering how to define items manually. @martinvw can you tell me how to do this and what it looks like. Do you use smarthome designer to define the items or through the PaperUI. Still struggling to work with the system...

metbril commented 7 years ago

Just wondering how to define items manually.

@RolandWijnen The 1.x wiki has a perfectly working example that you can copy and paste to the designer or any other text editor. Just save your dsmr.items file to the appropriate items configuration folder.

https://github.com/openhab/openhab/wiki/DSMR-binding

BTW, you should better ask for support in the openHAB community forums:

http://community.openhab.org/

mvolaart commented 7 years ago

I have created a first version of the DSMR-binding voor OpenHAB 2. This version does not support Gas, Water, Heating and Cooling meters voor DSMR meters V4.x and V5 and Heating, Cooling and Generic Meter voor DSMR V3.

Please start the discussion regarding this alpha version on the OpenHAB forum: https://community.openhab.org/t/new-dsmr-binding-for-openhab-2/20369

[removed old download]

metbril commented 7 years ago

I will try to find some time to test the new binding but can/will only start using it in production once Gas has been implemented for my v4 meter. If you confirm this is on your roadmap soon, I will gladly be of help.

https://community.openhab.org/t/new-dsmr-binding-for-openhab-2/20369

mvolaart commented 7 years ago

Here is the version in which all meters should be supported [Removed old download]

mvolaart commented 7 years ago

Hereby a new version:

mvolaart commented 7 years ago

New version including some small fixes [Removed old download]

FutureCow commented 7 years ago

@mvolaart Gister geprobeerd met een nieuwe DSMR 5.0 meter, blijkbaar wil de binding iedere keer de meter opnieuw registreren, en krijg dus een bom volle log, maar er wordt uiteindelijke geen data toegevoegd. stukje debug log: DEBUG

mvolaart commented 7 years ago

@FutureCow Allereerst: bedankt voor het testen! De volle log laat zich verklaren doordat de meter enkele seconde zijn actuele data verstuurd waar de binding iets mee doet. Als de binding in combinatie met de meter goed werkt is het verstandig om de log waarde op INFO te zetten. Ik zie de volgende zaken:

  1. De binding heeft de apparaat en de m3-meter (ik denk gas?) gedetecteerd. Gebruik je de PaperUI dan zullen deze Things in de 'Inbox' zitten en kan je ze op deze manier toevoegen en koppelen aan Items. Als het goed is komt de data vervolgens binnen. Maak je gebruik van configuratie files? Ik ben nog bezig met een readme om ook dit goed te ondersteunen en ik moet deze werkwijze nog zelf verder doortesten.
  2. Ik zie dat de binding een van de waardes van de meter niet goed verwerkt. Dit is direct de reden waarom de binding de elektriciteitsmeter niet detecteert. Ik ga hier naar kijken.

English Thanks for testing! The amount of messages in the log is caused by the fact dat the meter sends it data every second. If the binding is working correctly it is recommended to set the log level for this binding to INFO.

Regarding the log file you send:

  1. I see the meter device and the m3-meter (probably gas?) is dectected correctly. If you use the PaperUI you will find these new things in your inbox. You can add them from there and link them to items. Then you will receive data for these meters. If your using configuration files then you need some additional information. I'm working on this. Furthermore i have to do some testing myself with manual configuration
  2. I see that there is a problem parsing the electricity values. This is the reason no electricity meter is detected. I will look into this.
metbril commented 7 years ago

Tried to install tonight:

  1. Stop openhab
  2. Uninstall dsmr1 by removing from addons.cfg
  3. Download binding https://github.com/openhab/openhab2-addons/issues/1608#issuecomment-274272319 to /usr/share/openhab2/addons folder
  4. Unzip binding and remove .zip
  5. Start openhab

Now the binding is installed (visible through bundle:list) but it doesn't show up in Inbox.

Is this due to me not using the Java serial drivers with openhab, but my native drivers?

(This is also an issue for the RFXCOM binding, that requires manual config of the serial device in the Thing definition)

Browsing the code, perhaps the bridge should be defined like this?

dsmr:dsmrBridge:usb [ serialPort="/dev/ttyUSB0" ]
FutureCow commented 7 years ago

@mvolaart

Thank you for your reaction. I'm using the PaperUI to add things. I see in the paperui:

but i don't get any information in the things. Above is my debug log, this is without debug(info): 23:13:24.586 [INFO ] [enhab.binding.dsmr.device.DSMRDevice] - Detected the following new meters: [Meter type: M3_V5_0, channel: 1, identification: G00325655028, Meter type: DEVICE_V5, channel: -1, identification: unknown_id] 23:13:24.595 [INFO ] [me.event.ThingStatusInfoChangedEvent] - 'dsmr:m3_v5_0:1_G00325655028' changed from ONLINE to OFFLINE 23:13:24.598 [INFO ] [smarthome.event.ThingUpdatedEvent ] - Thing 'dsmr:m3_v5_0:1_G00325655028' has been updated. 23:13:24.611 [INFO ] [smarthome.event.ThingUpdatedEvent ] - Thing 'dsmr:device_v5:default_unknown_id' has been updated. 23:13:24.614 [INFO ] [me.event.ThingStatusInfoChangedEvent] - 'dsmr:device_v5:default_unknown_id' changed from ONLINE to OFFLINE 23:13:25.559 [WARN ] [dsmr.device.cosem.CosemObjectFactory] - Received unknown Cosem Object(OBIS id: 1-0:99.97.0) 23:13:25.582 [INFO ] [enhab.binding.dsmr.device.DSMRDevice] - There are unhandled CosemObjects, start autodetecting meters 23:13:25.583 [INFO ] [enhab.binding.dsmr.device.DSMRDevice] - Detected the following new meters: [Meter type: M3_V5_0, channel: 1, identification: G00325655028, Meter type: DEVICE_V5, channel: -1, identification: unknown_id] 23:13:26.555 [WARN ] [dsmr.device.cosem.CosemObjectFactory] - Received unknown Cosem Object(OBIS id: 1-0:99.97.0) 23:13:26.580 [INFO ] [enhab.binding.dsmr.device.DSMRDevice] - There are unhandled CosemObjects, start autodetecting meters 23:13:26.581 [INFO ] [enhab.binding.dsmr.device.DSMRDevice] - Detected the following new meters: [Meter type: M3_V5_0, channel: 1, identification: G00325655028, Meter type: DEVICE_V5, channel: -1, identification: unknown_id] 23:13:27.564 [WARN ] [dsmr.device.cosem.CosemObjectFactory] - Received unknown Cosem Object(OBIS id: 1-0:99.97.0) 23:13:27.585 [INFO ] [enhab.binding.dsmr.device.DSMRDevice] - There are unhandled CosemObjects, start autodetecting meters 23:13:27.586 [INFO ] [enhab.binding.dsmr.device.DSMRDevice] - Detected the following new meters: [Meter type: M3_V5_0, channel: 1, identification: G00325655028, Meter type: DEVICE_V5, channel: -1, identification: unknown_id] etc.... (every second)

mvolaart commented 7 years ago

@rtvb it is indeed necessary to configure the serial port. I think your suggested thing configuration could work. I will also test manual configuration myself.

@FutureCow I have fixed two bugs that caused the behavior you saw in the log.

Hereby an updated version of the binding. [Removed old download]

mvolaart commented 7 years ago

@rtvb I have updated the documentation (see https://github.com/mvolaart/openhab2-addons/tree/master/addons/binding/org.openhab.binding.dsmr). It should help you setting up the manual configuration.

Furthermore i have fixed some minor bugs and made setting up configuration manually easier. [Removed old download]

metbril commented 7 years ago

Re: https://github.com/openhab/openhab2-addons/issues/1608#issuecomment-279238834

I will try the manual configuration soon and report back success or issues.

mvolaart commented 7 years ago

I have implemented a different version (compatible with the previous one) that has an event driven approach. [Removed old download]

mvolaart commented 7 years ago

Improved the event driven implementation and added discovery of DSMR bridges using the scan button of OH2 [removed old download]

mvolaart commented 7 years ago

Are you sure /dev/ttyUSB0 is the correct port? If so please check: http://docs.openhab.org/installation/linux.html

Where it is suggested to add EXTRA_JAVA_OPTS="-Dgnu.io.rxtx.SerialPorts=/dev/ttyUSB0

To /etc/default/openhab2

Kinds regards,

Marcel

Van: jhlweb [mailto:notifications@github.com] Verzonden: zondag 26 februari 2017 21:45 Aan: openhab/openhab2-addons openhab2-addons@noreply.github.com CC: mvolaart mvolaart@lipin.nl; Mention mention@noreply.github.com Onderwerp: Re: [openhab/openhab2-addons] DSMR binding for OH2 (#1608)

I added the OH2 binding to the addon folder en after also downloading the nrjavaserial binding it installed and started. But i got the ERROR message /dev/ttyUSB0 does not exsits. After settings the log the DEBUG i got this:

2017-02-26 21:39:28.111 [INFO ] [org.apache.felix.fileinstall ] - Installing bundle org.openhab.binding.dsmr;singleton:=true / 2.1.0.201702232024 2017-02-26 21:39:28.142 [DEBUG] [org.openhab.binding.dsmr ] - BundleEvent INSTALLED - org.openhab.binding.dsmr 2017-02-26 21:39:28.273 [DEBUG] [org.openhab.binding.dsmr ] - BundleEvent RESOLVED - org.openhab.binding.dsmr 2017-02-26 21:39:28.280 [DEBUG] [org.openhab.binding.dsmr ] - BundleEvent STARTING - org.openhab.binding.dsmr 2017-02-26 21:39:28.286 [DEBUG] [org.openhab.binding.dsmr ] - BundleEvent STARTED - org.openhab.binding.dsmr 2017-02-26 21:39:28.331 [DEBUG] [org.openhab.binding.dsmr ] - ServiceEvent REGISTERED - {org.eclipse.smarthome.config.discovery.DiscoveryService}={component.name=org.openhab.binding.dsmr.discovery.DSMRBridgeDiscoveryService, component.id=328, service.id=487, service.bundleid=236, service.scope=bundle} - org.openhab.binding.dsmr 2017-02-26 21:39:28.342 [DEBUG] [org.openhab.binding.dsmr ] - ServiceEvent REGISTERED - {org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory}={component.name=org.openhab.binding.dsmr.internal.DSMRHandlerFactory, component.id=329, service.id=488, service.bundleid=236, service.scope=bundle} - org.openhab.binding.dsmr 2017-02-26 21:39:28.383 [DEBUG] [ing.dsmr.internal.DSMRHandlerFactory] - samsungtv:tv is not a DSMR Meter thing or not a supported DSMR Meter thing 2017-02-26 21:39:28.384 [DEBUG] [ing.dsmr.internal.DSMRHandlerFactory] - DSMR Bridge Thing dsmr:dsmrBridge supported 2017-02-26 21:39:28.385 [DEBUG] [ing.dsmr.internal.DSMRHandlerFactory] - Searching for thingTypeUID dsmr:dsmrBridge 2017-02-26 21:39:28.398 [DEBUG] [org.openhab.binding.dsmr ] - ServiceEvent REGISTERED - {org.eclipse.smarthome.config.discovery.DiscoveryService}={service.id=489, service.bundleid=236, service.scope=singleton} - org.openhab.binding.dsmr 2017-02-26 21:39:28.408 [INFO ] [org.apache.felix.fileinstall ] - Started bundle: file:/volume1/public/openHAB2/addons/org.openhab.binding.dsmr-2.1.0-SNAPSHOT.jar 2017-02-26 21:39:28.789 [DEBUG] [nding.dsmr.handler.DSMRBridgeHandler] - Using configuration DSMRDeviceConfiguration(portName:/dev/ttyUSB0, fixedPortSettings:, lenientMode:false 2017-02-26 21:39:28.790 [DEBUG] [nding.dsmr.handler.DSMRBridgeHandler] - Starting DSMR device 2017-02-26 21:39:28.814 [DEBUG] [enhab.binding.dsmr.device.DSMRDevice] - Starting device and entering INITIALIZING state 2017-02-26 21:39:28.816 [DEBUG] [enhab.binding.dsmr.device.DSMRDevice] - Handle DSMRDeviceEvent INITIALIZE in state null 2017-02-26 21:39:28.853 [DEBUG] [nding.dsmr.handler.DSMRBridgeHandler] - Notifying Thing handler of change from null to INITIALIZING 2017-02-26 21:39:28.860 [DEBUG] [enhab.binding.dsmr.device.DSMRDevice] - Current DSMRDevice state INITIALIZING 2017-02-26 21:39:28.886 [DEBUG] [openhab.binding.dsmr.device.DSMRPort] - Opening port /dev/ttyUSB0 2017-02-26 21:39:28.901 [ERROR] [openhab.binding.dsmr.device.DSMRPort] - Port /dev/ttyUSB0 does not exists gnu.io.NoSuchPortException at gnu.io.CommPortIdentifier.getPortIdentifier(CommPortIdentifier.java:273)[234:com.neuronrobotics.nrjavaserial:3.12.1] at org.openhab.binding.dsmr.device.DSMRPort.open(DSMRPort.java:174)[236:org.openhab.binding.dsmr:2.1.0.201702232024] at org.openhab.binding.dsmr.device.DSMRDevice.handleInitializeDSMRDevice(DSMRDevice.java:333)[236:org.openhab.binding.dsmr:2.1.0.201702232024] at org.openhab.binding.dsmr.device.DSMRDevice.handleDeviceState(DSMRDevice.java:212)[236:org.openhab.binding.dsmr:2.1.0.201702232024] at org.openhab.binding.dsmr.device.DSMRDevice.access$1(DSMRDevice.java:199)[236:org.openhab.binding.dsmr:2.1.0.201702232024] at org.openhab.binding.dsmr.device.DSMRDevice$1.run(DSMRDevice.java:180)[236:org.openhab.binding.dsmr:2.1.0.201702232024] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)[:1.8.0_121] at java.util.concurrent.FutureTask.run(FutureTask.java:266)[:1.8.0_121] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[:1.8.0_121] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)[:1.8.0_121] at java.lang.Thread.run(Thread.java:745)[:1.8.0_121] 2017-02-26 21:39:28.905 [DEBUG] [enhab.binding.dsmr.device.DSMRDevice] - Handle port event DONT_EXISTS 2017-02-26 21:39:28.906 [DEBUG] [enhab.binding.dsmr.device.DSMRDevice] - Handle DSMRDeviceEvent CONFIGURATION_ERROR in state INITIALIZING 2017-02-26 21:39:28.908 [DEBUG] [nding.dsmr.handler.DSMRBridgeHandler] - Notifying Thing handler of change from INITIALIZING to CONFIGURATION_PROBLEM 2017-02-26 21:39:28.910 [WARN ] [nding.dsmr.handler.DSMRBridgeHandler] - Received unknown state CONFIGURATION_PROBLEM 2017-02-26 21:39:28.911 [DEBUG] [enhab.binding.dsmr.device.DSMRDevice] - Current DSMRDevice state CONFIGURATION_PROBLEM what did i do wrong?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/openhab/openhab2-addons/issues/1608#issuecomment-282585912 , or mute the thread https://github.com/notifications/unsubscribe-auth/AJ329E1fp5njBnbwtiRfm2IrSMrX79H3ks5rgeRPgaJpZM4LVSPt . https://github.com/notifications/beacon/AJ329Gn2Bsxy65SLIqxKkAGKB2bj84s9ks5rgeRPgaJpZM4LVSPt.gif

jhlweb commented 7 years ago

I saw that but I'm on a Synology NAS and there is no file openhab2 in etc/defaults/ do i have to make it and just add the line?

I also see something in this post https://github.com/openhab/openhab2-addons/issues/1562#issuecomment-267135624 that nrjavaserail will not work on 64 bit JVM

I hope that someone has nvjavaserail running on a Synology...

mvolaart commented 7 years ago

Fixed bug with changing comm port settings of the bridge thing [Removed old download]

mvolaart commented 7 years ago

Fixed two bugs:

jhlweb commented 7 years ago

@mvolaart the configuration of the port settings is now possible but they are not visible when you come back to re-edit the page.

mvolaart commented 7 years ago

@jhlweb Do you observe this behavior with the version of March 2, 2017 or later? Older version indeed have a probleem editing port settings

mvolaart commented 7 years ago

Fixed a bug with non compliant DSMR V3 meters.

[Removed old download]

jhlweb commented 7 years ago

Whit this version is't fixed.

Fixed a bug with non compliant DSMR V3 meters.

org.openhab.binding.dsmr-2.1.0-SNAPSHOT.zip

PS. Do you have any sample item, sitemaps, scripts, persistence or rules on what to save for statistics and how to display it? Inventing it all over again looks a bit pointless to me :)

metbril commented 7 years ago

Since the OH forum is currently down, I am posting over here.

I've got my manual setup working. Looking great.

One thing I noticed is, that the gas meter timestamp is missing. Since this value is only sent once an hour, that timestamp is different from the electricity timestamp. I use the timestamp for rules events, so it would be great if the gas timestamp will return in the OH2 binding.

mvolaart commented 7 years ago

Great you got your setup working. Did you find the cause of the problems you were experiencing?

About the date value. Thanks for reporting this. This was indeed missing in the OH2-version. I will repair this missing functionality.

metbril commented 7 years ago

My mistake. At first I renamed the zip to jar. When I unzipped it, it was working just fine.

Re the date: if it is not in the telegram itself, perhaps I could just use a rule that watches for a change of the meter value and set a timestamp myself (if I actually need it, which I don't other than for the trigger). That would keep the binding more clean don't you think?

mvolaart commented 7 years ago

The date is in the telegram. So i will add channels for this.

mvolaart commented 7 years ago

A new version with the following fixes:

marcel-kok commented 7 years ago

Hi,

I've installed the latest version (https://github.com/openhab/openhab2-addons/files/852212/org.openhab.binding.dsmr-2.1.0-SNAPSHOT.zip).

Discovery of items went great. Added the 2 things via the Inbox.

Both Things (Generic DSMR device, DSMR bridge on /dev/ttyUSB0) are online. Data is received, seen in TRACE log in openhab.log.

But no events are thrown, nor items are created.

Can you please help me how i can create the items?

Thanks, Marcel

mvolaart commented 7 years ago

I think there are multiple observations here that i think it is good to clarify:

  1. In the most basic setup i would expect 3 things (bridge, generic meter, electricity meter). To sort this out i would like to receive your trace log. Because of this there will be no electricity data to read out.
  2. Items are not created automatically. You have to add them manually and connect them to the available channel of a thing. In the Paper UI please go to the 'Thing' menu and open the Generic Meter Thing for example. I think it will show 3 channels ('Text Message', 'P1 Version' and 'Timestamp'). For each channel you can specify an existing or new item. The items you can have to add the items to a sitemap. Please refer to the general OH2 documentation how to achieve this. I would expect the items configured for the channels of the Generic Meter Thing should show data.
  3. The DSMR Bridge Thing does not have any channels. This is by design.
marcel-kok commented 7 years ago

Hi, Thanks for your reply.

see attachement for trace files

I tried some restarts and uninstall/installs.

Also removed the things from console. Now it doesn't discover any things anymore. The trace file show it's receiving some data.

Hope you can help.

openhab.zip

marcel-kok commented 7 years ago

Hi Marcel,

I added the 'Dutch Smart Meter' manually.

Soon after that. It discovered 'Generic DSMR device'

Which has 2 channels: Text Code and Text Message

trace.txt

When logging in level INFO is see this messages

2017-05-04 18:36:41.023 [INFO ] [ding.dsmr.internal.device.DSMRDevice] - Detected the following new meters: [] 2017-05-04 18:36:51.042 [INFO ] [ding.dsmr.internal.device.DSMRDevice] - There are unhandled CosemObjects, start autodetecting meters

I had it working before I trashed my sd card. Discovery then happened automatically. And events.log was showing changes from my energy meter

Thanks!

mvolaart commented 7 years ago

Thanks for your trace log. It contained the necessary information to find the cause of not receiving values.

From the trace log i see:

I have made a fix for this and attach a specific binding to this post which you can try (For some reason i cannot attach a zip file. I renamed it to .txt. Please rename the file to .zip and then unpack the including jar)

After you installed the new jar i would expect:

After adding the new things you can add new items to the channels in the regular way.

Please let me know if you are successfull or still experience problems. For my own information i would like to know which meter you have installed (brand, type).

org.openhab.binding.dsmr-2.1.0-SNAPSHOT.txt

marcel-kok commented 7 years ago

Hi,

Thanks!! It worked like a charm now. I didn't have time to test it earlier.

I think it's a:

Landys Gyr+

ZCF120ABd M40

metbril commented 6 years ago

What is the download link for the most recent version of the binding?

This is the last published link in this thread: https://github.com/openhab/openhab2-addons/issues/1608#issuecomment-287520729

Hilbrand commented 6 years ago

Here an update on the DSMR binding. I've finalized the work on this binding and created a new pull request #3720. Feel free to do some code reviews to get this binding merged :smile:

In the mean time the binding is available via the Eclipse market place. (If you don't see it directly in PaperUI, disable/enable market place in configuration to refresh the binding list).

The binding is compatible with openHAB version 2.4.0-SNAPSHOT. If you've had a previous version of this binding running, it's mostly compatible. Only data types with units have been converted to QuantityTypes. And there are some new refresh options. And you can now use the discovery process to discover the meters.

The binding should be fairly stable. If it doesn't detect during discovery it might show the raw dsmr data in the logging. This can help adding your device. Or else using log levels debug or even trace can help you with more detailed information on what might be wrong. But if it doesn't work for you please let me know and report your problems here.

Hilbrand commented 6 years ago

This issue can be closed. The binding has been merged! :tada: