DSMR binding for Austrian Smart Meters

At the moment, I’m using the project already discussed earlier in this thread
tknaller/smarty_dsmr_proxy.

I add the additional encryption key via the parameter -a (see also decrypt.py#L75)

default="3000112233445566778899AABBCCDDEEFF", help="Additional authenticated data"

The default key seems to just work, if only 1 key is given by the energy supplier (like e.g. in the Netherlands)!

Afterwards I’m transferring the data to MQTT via the project DSMR2MQTT

If it’s possible to add the 2nd encryption key also somewhere in this binding, then I think a communication directly from openhab would be possible…

Did you succeed in connecting the SAGEMCOM to openhab?
(same city, same infrastructure…)

That was the information about the 2nd key I was looking for. Thanks. This seems fairly easy to add. I’ll add this to the binding and will provide a jar for you to test in the near future. What version of openHAB are you running?

Sounds good.
I’m running version 3.3.0

Br

Good morning Simon!

Yeah, data transfer is running (E-Netze Steiermark SAGEMCOM SmartMeter via P1 port).
But at the moment via a workaround (with smarty_dsmr_proxy and DSMR2MQTT) and not directly with the openHAB addOn. You can contact me directly if you need additional information!

But as for as I see, we should get it to work with the openHAB Addon in the near future…

I’ve build a kar file with the an extra configuration parameter additionalKey. If you had the smarty bridge thing created via the UI you need to recreate it to see the new parameter. Kar files are very version specific. I’ve built the kar file for openHAB 3.3.0 core (based on openHAB 3.4.0-SNAPSHOT add-ons code), and expect it to only work for 3.3.0: Release DSMR 3.3.0 updated version · Hilbrand/openhab-addons · GitHub Just drop the file in the addons directory and it should be seen by openHAB. It could be it doesn’t show up in installed bindings, but you should be able to add a bridge/thing in discovery.

Just tried - without success :frowning:

I saw in your commit that you used different spellings of additionalKey. Maybe this is the problem?
In the configuration you write additionalnKey (github link), later additionallKey (github link) and so on?!?

Error message in the log:

[WARN ] [.dsmr.internal.device.SmartyDecrypter] - Decrypting smarty telegram failed:
javax.crypto.AEADBadTagException: Tag mismatch!
        at com.sun.crypto.provider.GaloisCounterMode.decryptFinal(GaloisCounterMode.java:623) ~[?:?]
        at com.sun.crypto.provider.CipherCore.finalNoPadding(CipherCore.java:1116) ~[?:?]
        at com.sun.crypto.provider.CipherCore.fillOutputBuffer(CipherCore.java:1053) ~[?:?]
        at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:853) ~[?:?]
        at com.sun.crypto.provider.AESCipher.engineDoFinal(AESCipher.java:446) ~[?:?]
        at javax.crypto.Cipher.doFinal(Cipher.java:2260) ~[?:?]
        at org.openhab.binding.dsmr.internal.device.SmartyDecrypter.decrypt(SmartyDecrypter.java:216) [bundleFile:?]
        at org.openhab.binding.dsmr.internal.device.SmartyDecrypter.processCompleted(SmartyDecrypter.java:193) [bundleFile:?]
        at org.openhab.binding.dsmr.internal.device.SmartyDecrypter.parse(SmartyDecrypter.java:106) [bundleFile:?]
        at org.openhab.binding.dsmr.internal.device.DSMRTelegramListener.handleData(DSMRTelegramListener.java:75) [bundleFile:?]
        at org.openhab.binding.dsmr.internal.device.connector.DSMRBaseConnector.handleDataAvailable(DSMRBaseConnector.java:116) [bundleFile:?]
        at org.openhab.binding.dsmr.internal.device.connector.DSMRSerialConnector.handleDataAvailable(DSMRSerialConnector.java:317) [bundleFile:?]
        at org.openhab.binding.dsmr.internal.device.connector.DSMRSerialConnector.serialEvent(DSMRSerialConnector.java:276) [bundleFile:?]
        at org.openhab.core.io.transport.serial.rxtx.RxTxSerialPort$1.serialEvent(RxTxSerialPort.java:82) [bundleFile:?]
        at gnu.io.RXTXPort.sendEvent(RXTXPort.java:834) ~[bundleFile:5.2.1.OH1]
        at gnu.io.RXTXPort.eventLoop(Native Method) [bundleFile:5.2.1.OH1]
        at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:108) [bundleFile:5.2.1.OH1]

My configuration:

UID: dsmr:smartyBridge:0b2ad74b60
label: Smarty Meter
thingTypeUID: dsmr:smartyBridge
configuration:
  decryptionKey: xxxxx
  serialPort: /dev/ttyUSB0
  receivedTimeout: 30
  additionalnKey: xxxxx

Hopefully this is enough information to have a look at…

BR from Austria,

MW

Doh :man_facepalming: sorry about that. I’ve updated the binding with the correct naming (same link, only different kar file name to download from there).

Again no luck :frowning:

2022-09-05 21:21:38.555 [WARN ] [dsmr.internal.device.SmartyDecrypter] - Decrypting smarty telegram failed:
javax.crypto.AEADBadTagException: Tag mismatch!
        at com.sun.crypto.provider.GaloisCounterMode.decryptFinal(GaloisCounterMode.java:623) ~[?:?]
        at com.sun.crypto.provider.CipherCore.finalNoPadding(CipherCore.java:1116) ~[?:?]
        at com.sun.crypto.provider.CipherCore.fillOutputBuffer(CipherCore.java:1053) ~[?:?]
        at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:853) ~[?:?]
        at com.sun.crypto.provider.AESCipher.engineDoFinal(AESCipher.java:446) ~[?:?]
        at javax.crypto.Cipher.doFinal(Cipher.java:2260) ~[?:?]
        at org.openhab.binding.dsmr.internal.device.SmartyDecrypter.decrypt(SmartyDecrypter.java:216) [bundleFile:?]
        at org.openhab.binding.dsmr.internal.device.SmartyDecrypter.processCompleted(SmartyDecrypter.java:193) [bundleFile:?]
        at org.openhab.binding.dsmr.internal.device.SmartyDecrypter.parse(SmartyDecrypter.java:106) [bundleFile:?]
        at org.openhab.binding.dsmr.internal.device.DSMRTelegramListener.handleData(DSMRTelegramListener.java:75) [bundleFile:?]
        at org.openhab.binding.dsmr.internal.device.connector.DSMRBaseConnector.handleDataAvailable(DSMRBaseConnector.java:116) [bundleFile:?]
        at org.openhab.binding.dsmr.internal.device.connector.DSMRSerialConnector.handleDataAvailable(DSMRSerialConnector.java:317) [bundleFile:?]
        at org.openhab.binding.dsmr.internal.device.connector.DSMRSerialConnector.serialEvent(DSMRSerialConnector.java:276) [bundleFile:?]
        at org.openhab.core.io.transport.serial.rxtx.RxTxSerialPort$1.serialEvent(RxTxSerialPort.java:82) [bundleFile:?]
        at gnu.io.RXTXPort.sendEvent(RXTXPort.java:834) ~[bundleFile:5.2.1.OH1]
        at gnu.io.RXTXPort.eventLoop(Native Method) [bundleFile:5.2.1.OH1]
        at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:108) [bundleFile:5.2.1.OH1]

I currently start the python script with following command-line, if this helps:

 /smarty_dsmr_proxy/decrypt.py E7E235650CCE6A383ED4849C9E087D16 -a A54FFB0357D0EF0A13A11A8209BC4695 --serial-input-port=/dev/ttyUSB0 --serial-output-port=/dev/pts/1

I’ll send you test data via a personal message.

As a followup, the DSMR binding update to add support for a 2nd key as mentioned above has been updated and confirmed by @mwildbolz to work with 2 keys.

1 Like

Will this change be implemented in the official repository? What’s your plan regarding a pull request?

Thanks a lot for your support,
MW

I’m not within E-Netze Steiermark but E-Werk Gösting (Graz).
I think that the Smart Meters are the same. Encryption seems to be the same (AES-128-GCM).

Within your command line:

/smarty_dsmr_proxy/decrypt.py E7E235650CCE6A383ED4849C9E087D16 -a A54FFB0357D0EF0A13A11A8209BC4695 --serial-input-port=/dev/ttyUSB0 --serial-output-port=/dev/pts/1

Is the first key the so called GUEK and the second key the so called GAK?

I don’t like to use openHAB but to store it as daily csv-files to detect energy leaks using suitable code snippets.

best regards,
beta-L-user

Do you know where i get these 2 encryption keys for my Landis-Gyr 450?
Can i get them from Energie Steiermark, where i got my smart meter from?

Br

Hi!

yes that’s right. First is the GUEK, and the second one (the additional one) is called GAK!
You have to get them form E-Werk Gösting in this case!

Br

Hi Eric!

If you are in the net region of E-Netze Steiermark you get these 2 keys from
portal.e-netze.at

You can find them under “Anschlussobjektdaten” - “Gerätekonfiguration” and then you have to click at the edit button:

And then there is the button to show the keys:

As additional information:
It can take up to 6 month after installation of the smart meter till you can activate the P1 Interface (Kundenschnittstelle)!

BR
MW

Thanks for the fast answer.
Unfortunately I don’t have the “Gerätekonfiguration” option yet, but I got the Smart Meter installed for more than a year now…

I guess I’ll have to call the hotline then…

The good thing is now, that i don’t have to search the internet anymore for a solution :smiley:

Hi @hilbrand!
Short question to the kar file:
I recognized, that on an OpenHAB reload (or machine restart) the kar file does not work automatically.
I have to remove the file from the addons-folder and insert it, then all runs smoothly.

Do you have an idea what’s wrong in this case?
Or could I already switch to another build of OpenHAB with this changes already included?

Thanks a lot,
MW

I don’t know why it doesn’t reload. I would not suspect the binding itself to be the problem. Might be a startup issue of openHAB. The changes are already available per openHAB 3.4.0.M2. So you could switch to that version.

Hello!

First of all, thanks for this great work implementing the second key für austrian smart meters.
I already tried to connect the new binding (updatet version - openHAB Milestone) with my Sagemcom T210-D in Austria and it works nearly without problems.

I only have the problem, that the connection to the bridge get lost after a few seconds, then the bridge gets online again automatically for a few seconds, and so on and on… (see log below)

Does anybody have an idea, what could be the reason for this behaviour?
“Failed to decrypt P1 telegram due to invalid encryption key” like in the log can’t be the reason in my opinion because the item values gets refreshed when bridge is online…

Many Thanks and best regards!
Christian

2022-10-30 21:39:26.865 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'dsmr:smartyBridge:SmartMeter_Bridge' changed from OFFLINE (COMMUNICATION_ERROR): Failed to decrypt P1 telegram due to invalid encryption key to ONLINE
2022-10-30 21:39:26.870 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'dsmr:electricity_smarty_v1_0_austria:SmartMeter_Bridge:SmartMeter' changed from OFFLINE (BRIDGE_OFFLINE) to OFFLINE
2022-10-30 21:39:26.893 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ElectricityMeterAustria_Timestamp' changed from NULL to 2022-10-30T21:38:32.000+0100
2022-10-30 21:39:26.901 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ElectricityMeterAustria_DeliveryTariff0' changed from NULL to 17434.121 kWh
2022-10-30 21:39:26.905 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ElectricityMeterAustria_DeliveryTariff1' changed from NULL to 13826.994 kWh
2022-10-30 21:39:26.908 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'dsmr:electricity_smarty_v1_0_austria:SmartMeter_Bridge:SmartMeter' changed from OFFLINE to ONLINE
2022-10-30 21:39:26.911 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ElectricityMeterAustria_DeliveryTariff2' changed from NULL to 3607.127 kWh
2022-10-30 21:39:26.913 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ElectricityMeterAustria_ActualPowerDelivery' changed from NULL to 0.369 kW
2022-10-30 21:39:26.915 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ElectricityMeterAustria_TotalImportedEnergyQ' changed from NULL to 2.669 kvarh
2022-10-30 21:39:54.129 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ElectricityMeterAustria_Timestamp' changed from 2022-10-30T21:38:32.000+0100 to 2022-10-30T21:38:52.000+0100
2022-10-30 21:39:54.154 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ElectricityMeterAustria_DeliveryTariff0' changed from 17434.121 kWh to 17434.124 kWh
2022-10-30 21:39:54.163 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ElectricityMeterAustria_DeliveryTariff1' changed from 13826.994 kWh to 13826.997 kWh
2022-10-30 21:39:54.167 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ElectricityMeterAustria_ActualPowerDelivery' changed from 0.369 kW to 0.39 kW
2022-10-30 21:40:54.141 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ElectricityMeterAustria_Timestamp' changed from 2022-10-30T21:38:52.000+0100 to 2022-10-30T21:39:52.000+0100
2022-10-30 21:40:54.159 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ElectricityMeterAustria_DeliveryTariff0' changed from 17434.124 kWh to 17434.13 kWh
2022-10-30 21:40:54.161 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ElectricityMeterAustria_DeliveryTariff1' changed from 13826.997 kWh to 13827.003 kWh
2022-10-30 21:40:54.163 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ElectricityMeterAustria_ActualPowerDelivery' changed from 0.39 kW to 0.404 kW
==> /var/log/openhab/openhab.log <==
2022-10-30 21:41:26.901 [WARN ] [dsmr.internal.device.SmartyDecrypter] - Decrypting smarty telegram failed: 
javax.crypto.AEADBadTagException: Tag mismatch!
	at com.sun.crypto.provider.GaloisCounterMode.decryptFinal(GaloisCounterMode.java:623) ~[?:?]
	at com.sun.crypto.provider.CipherCore.finalNoPadding(CipherCore.java:1116) ~[?:?]
	at com.sun.crypto.provider.CipherCore.fillOutputBuffer(CipherCore.java:1053) ~[?:?]
	at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:853) ~[?:?]
	at com.sun.crypto.provider.AESCipher.engineDoFinal(AESCipher.java:446) ~[?:?]
	at javax.crypto.Cipher.doFinal(Cipher.java:2260) ~[?:?]
	at org.openhab.binding.dsmr.internal.device.SmartyDecrypter.decrypt(SmartyDecrypter.java:217) [bundleFile:?]
	at org.openhab.binding.dsmr.internal.device.SmartyDecrypter.processCompleted(SmartyDecrypter.java:194) [bundleFile:?]
	at org.openhab.binding.dsmr.internal.device.SmartyDecrypter.parse(SmartyDecrypter.java:107) [bundleFile:?]
	at org.openhab.binding.dsmr.internal.device.DSMRTelegramListener.handleData(DSMRTelegramListener.java:75) [bundleFile:?]
	at org.openhab.binding.dsmr.internal.device.connector.DSMRBaseConnector.handleDataAvailable(DSMRBaseConnector.java:116) [bundleFile:?]
	at org.openhab.binding.dsmr.internal.device.connector.DSMRSerialConnector.handleDataAvailable(DSMRSerialConnector.java:317) [bundleFile:?]
	at org.openhab.binding.dsmr.internal.device.connector.DSMRSerialConnector.serialEvent(DSMRSerialConnector.java:276) [bundleFile:?]
	at org.openhab.core.io.transport.serial.rxtx.RxTxSerialPort$1.serialEvent(RxTxSerialPort.java:82) [bundleFile:?]
	at gnu.io.RXTXPort.sendEvent(RXTXPort.java:834) ~[bundleFile:5.2.1.OH1]
	at gnu.io.RXTXPort.eventLoop(Native Method) [bundleFile:5.2.1.OH1]
	at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:108) [bundleFile:5.2.1.OH1]
==> /var/log/openhab/events.log <==
2022-10-30 21:41:26.912 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'dsmr:smartyBridge:SmartMeter_Bridge' changed from ONLINE to OFFLINE (COMMUNICATION_ERROR): Failed to decrypt P1 telegram due to invalid encryption key
2022-10-30 21:41:26.919 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'dsmr:electricity_smarty_v1_0_austria:SmartMeter_Bridge:SmartMeter' changed from ONLINE to OFFLINE (BRIDGE_OFFLINE)
2022-10-30 21:41:26.946 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ElectricityMeterAustria_Timestamp' changed from 2022-10-30T21:39:52.000+0100 to NULL
2022-10-30 21:41:26.950 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ElectricityMeterAustria_ActualPowerDelivery' changed from 0.404 kW to NULL
2022-10-30 21:41:26.954 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ElectricityMeterAustria_DeliveryTariff0' changed from 17434.13 kWh to NULL
2022-10-30 21:41:26.957 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ElectricityMeterAustria_DeliveryTariff1' changed from 13827.003 kWh to NULL
2022-10-30 21:41:26.961 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ElectricityMeterAustria_DeliveryTariff2' changed from 3607.127 kWh to NULL
2022-10-30 21:41:26.964 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ElectricityMeterAustria_TotalImportedEnergyQ' changed from 2.669 kvarh to NULL
2022-10-30 21:41:36.941 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'dsmr:smartyBridge:SmartMeter_Bridge' changed from OFFLINE (COMMUNICATION_ERROR): Failed to decrypt P1 telegram due to invalid encryption key to ONLINE
2022-10-30 21:41:36.947 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'dsmr:electricity_smarty_v1_0_austria:SmartMeter_Bridge:SmartMeter' changed from OFFLINE (BRIDGE_OFFLINE) to OFFLINE
2022-10-30 21:41:36.977 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ElectricityMeterAustria_Timestamp' changed from NULL to 2022-10-30T21:40:42.000+0100
2022-10-30 21:41:36.984 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ElectricityMeterAustria_DeliveryTariff0' changed from NULL to 17434.135 kWh
2022-10-30 21:41:36.988 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ElectricityMeterAustria_DeliveryTariff1' changed from NULL to 13827.008 kWh
2022-10-30 21:41:36.993 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'dsmr:electricity_smarty_v1_0_austria:SmartMeter_Bridge:SmartMeter' changed from OFFLINE to ONLINE
2022-10-30 21:41:37.000 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ElectricityMeterAustria_DeliveryTariff2' changed from NULL to 3607.127 kWh
2022-10-30 21:41:37.010 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ElectricityMeterAustria_ActualPowerDelivery' changed from NULL to 0.397 kW
2022-10-30 21:41:37.013 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ElectricityMeterAustria_TotalImportedEnergyQ' changed from NULL to 2.669 kvarh
2022-10-30 21:41:54.168 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ElectricityMeterAustria_Timestamp' changed from 2022-10-30T21:40:42.000+0100 to 2022-10-30T21:40:52.000+0100
2022-10-30 21:41:54.196 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ElectricityMeterAustria_DeliveryTariff0' changed from 17434.135 kWh to 17434.136 kWh
2022-10-30 21:41:54.208 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ElectricityMeterAustria_DeliveryTariff1' changed from 13827.008 kWh to 13827.009 kWh
2022-10-30 21:41:54.211 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ElectricityMeterAustria_ActualPowerDelivery' changed from 0.397 kW to 0.389 kW
2022-10-30 21:42:54.178 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ElectricityMeterAustria_Timestamp' changed from 2022-10-30T21:40:52.000+0100 to 2022-10-30T21:41:52.000+0100
2022-10-30 21:42:54.199 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ElectricityMeterAustria_DeliveryTariff0' changed from 17434.136 kWh to 17434.143 kWh
2022-10-30 21:42:54.213 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ElectricityMeterAustria_DeliveryTariff1' changed from 13827.009 kWh to 13827.016 kWh
2022-10-30 21:42:54.216 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ElectricityMeterAustria_ActualPowerDelivery' changed from 0.389 kW to 0.471 kW