New Teleinfo Binding - Tester and Feedback welcome

Hi @ysc,
Thank you for your feedback !

Can you add an issue in my GitHub please ? https://github.com/nokyyz/openhab2-addons/issues
Iā€™m implementing a Retry mechanism to prevent this invalid data. The teleinfo reading will be suspend during 1 minute and resume after this pause. After 5 unsuccess retries, the binding will stop the reading definitively.
What do you think about that ?

I have some times a similar issue but for the moment I cannot find the steps to reproduce. For my part, this error throws on Enedis HC/HP switch. I have created an issue on GitHub to try to solve it : https://github.com/nokyyz/openhab2-addons/issues/7
Can we continue the discussion in this Github issue?

1 Like

Sounds good, not even sure the 1-minute suspend and abandon after 5 retries is not necessary but it canā€™t hurt :slight_smile:

You are right :slight_smile: In the ā€œcorrupted framesā€ case, the binding will go to the next frame without pause. The suspend and retry mechanism is mostly for timeout and I/O errors.
I think that this fix will be implemented shortly. After some tests, I will post a new version in this thread.
See you soon

Iā€™m sharing the Ruby script I wrote today in the meantime. To be perfectly clear - I still would like a TĆ©lĆ©info binding in openHAB, of course :slight_smile: , but since in my case the data is not collected on my main instance, I have to transmit it somehow, hence the MQTT-based solution: this script will expose the meter as a Homie MQTT device. You need the mqtt and teleinfo gems installed (sudo gem install mqtt, sudo gem install teleinfo).
If you decide to use it, alter the variables at the beginning of the script to your needs, including the TƩlƩinfo properties you want from your meter (different models provide different properties, you have to familiarize yourself with those first).

#!/usr/bin/env ruby

require 'teleinfo'
require 'mqtt'

$device = '/dev/ttyUSB0'
$broker_host = '192.168.1.141'
$homie_device = 'linky'
$homie_node = 'teleinfo'
$homie_type = 'PowerMeter'
$homie_name = 'Linky'
$teleinfo_properties = {
  :base => { :name => 'Base Tariff Energy', :unit => 'kWh', :type => 'integer', :kilo => true },
  :papp => { :name => 'Apparent Power', :unit => 'VA', :type => 'integer' },
  :iinst => { :name => 'Instantaneous Intensity', :unit => 'A', :type => 'integer' }
}

MQTT::Client.connect($broker_host) do |c|
  # Publish device descriptions
  c.publish("homie/#{$homie_device}/$homie", "4.0.0", true)
  c.publish("homie/#{$homie_device}/$name", $homie_name, true)
  c.publish("homie/#{$homie_device}/$state", "ready", true)
  c.publish("homie/#{$homie_device}/$nodes", $homie_node, true)
  c.publish("homie/#{$homie_device}/$extensions", "", true)

  c.publish("homie/#{$homie_device}/#{$homie_node}/$name", $homie_name, true)
  c.publish("homie/#{$homie_device}/#{$homie_node}/$type", $homie_type, true)
  c.publish("homie/#{$homie_device}/#{$homie_node}/$properties", $teleinfo_properties.keys.join(','), true)
  $teleinfo_properties.each { |k,v|
    c.publish("homie/#{$homie_device}/#{$homie_node}/#{k.to_s}/$name", v[:name], true)
    c.publish("homie/#{$homie_device}/#{$homie_node}/#{k.to_s}/$datatype", v[:type], true)
    c.publish("homie/#{$homie_device}/#{$homie_node}/#{k.to_s}/$unit", v[:unit], true)
  }

  teleinfo = Teleinfo::Parser.new(File.open($device, 'r'))
  teleinfo.each { |f|
    puts f.to_json
    $teleinfo_properties.each { |k,v|
      if v[:kilo] then
        c.publish("homie/#{$homie_device}/#{$homie_node}/#{k.to_s}", f.to_hash[k] / 1000.0, true)
      else
        c.publish("homie/#{$homie_device}/#{$homie_node}/#{k.to_s}", f.to_hash[k], true)
      end
    }

    #c.publish('linky/teleinfo', f.to_json)
  }
end

My OpenHAB server is close to my electricity meter :slight_smile:

To simplify your architecture, have you try the Serial port over IP method ?
Some links:

Hi all, @pakutz79, @srsr, @ysc,
Here is the new release (Beta 20191029-2235) : https://github.com/nokyyz/openhab2-addons/releases/tag/beta-20191029-2235
This release try to fix binding crashs on random I/O errors (see https://github.com/nokyyz/openhab2-addons/issues/7) and invalid/corrupted frame errors.

Any feedback will be welcome !

Hi @nokyyz
Thanks for your work !
I use your binding on openhab 2.5.0.M3 on docker with the previous (Alpha 20191015-1958) version. My teleinfo hardware is a Cartelectronic like @ysc. It works well but I noticed several issues/enhancements:

  • Same issue than @ysc [ERROR] [nternal.serial.TeleinfoReceiveThread] - Got invalid frame The groupLine seems corrupted (integrity not checked) during receiving. exiting thread.. I will try the new beta version next week.
  • Rules auto updating seems to be broken when using your binding: need a restart of my docker image to take into account modifications in my .rules files.
  • Could this binding directly support a ser2net device? For example with a device address like ip:port instead of /dev/ttyXXX. With that my docker image could be independent of the harware where he is running. Enocean binding seems to already support this.

Thanks @hollysaiqs for your feedback !

Yes, the beta-20191029-2235 version should fix this issue :slight_smile:

Iā€™m using OpenHAB 2.5.0-M1 on Docker (ā€˜openhab/openhab:2.5.0.M1-amd64-debianā€™ image). I will check it in the next few days. I am very surprised that this problem is due to my teleinfo bindingā€¦

I think OpenHAB supports the rfc2217 feature natively. If you want to try/test, I can update the binding configuration to replace Serial port dropdown list to a simple text field.
Ok ?

For my information, can you give me some details about your electricty meter ? single-phase or tree-phase ? your pricing option (Base, HC, Tempo, EJP) ?

Thx

Hi @nokyyz,

My electricity meter is single phased and my pricing option is HC.
A text field instead of dropdown list would be great!
No time to test the new version for the momentā€¦

Hi all, @pakutz79, @srsr, @ysc, @hollysaiqs
Here is the new release (Beta 20191104-2035) : https://github.com/nokyyz/openhab2-addons/releases/tag/beta-20191104-2035
Release note:

Any feedback will be welcome !

1 Like

Hi @nokyyz,
I am testing the new release and I am trying to have a working rfc2217 configuration. I receive this error:

[rial.TeleinfoSerialControllerHandler] - An error occurred during serial port connection. Detail: "gnu.io.UnsupportedCommOperationException"
org.eclipse.smarthome.io.transport.serial.UnsupportedCommOperationException: gnu.io.UnsupportedCommOperationException
	at org.eclipse.smarthome.io.transport.serial.rxtx.RxTxSerialPort.enableReceiveThreshold(RxTxSerialPort.java:157) ~[?:?]
	at org.openhab.binding.teleinfo.internal.serial.TeleinfoSerialControllerHandler.openSerialPortAndStartReceiving(TeleinfoSerialControllerHandler.java:176) [243:org.openhab.binding.teleinfo:2.5.0.201911041935]
	at org.openhab.binding.teleinfo.internal.serial.TeleinfoSerialControllerHandler.access$5(TeleinfoSerialControllerHandler.java:148) [243:org.openhab.binding.teleinfo:2.5.0.201911041935]
	at org.openhab.binding.teleinfo.internal.serial.TeleinfoSerialControllerHandler$1.run(TeleinfoSerialControllerHandler.java:89) [243:org.openhab.binding.teleinfo:2.5.0.201911041935]
	at java.util.TimerThread.mainLoop(Timer.java:555) [?:?]
	at java.util.TimerThread.run(Timer.java:505) [?:?]
Caused by: gnu.io.UnsupportedCommOperationException
	at gnu.io.rfc2217.TelnetSerialPort.enableReceiveThreshold(TelnetSerialPort.java:948) ~[?:?]
	at org.eclipse.smarthome.io.transport.serial.rxtx.RxTxSerialPort.enableReceiveThreshold(RxTxSerialPort.java:155) ~[?:?]
	... 5 more

Here is my ser2net.conf:
5001:telnet:0:/dev/ttyUSB0:1200 7DATABITS EVEN 1STOPBIT remctl

Where is my mistake?
Do I need to add something to my docker image configuration?

Hi @hollysaiqs,
I could not test the RFC2217 featureā€¦ After some searchs on this forum, have you try with RAW option instead of Telnet ? E.g:
5001:telnet:0:/dev/ttyUSB0:1200 7DATABITS EVEN 1STOPBIT remctl
->
5001:raw:0:/dev/ttyUSB0:1200 7DATABITS EVEN 1STOPBIT remctl

Hi @nokyyz,
With raw option, I receive this error:

[ERROR] [rial.TeleinfoSerialControllerHandler] - An error occurred during serial port connection. Detail: "gnu.io.UnsupportedCommOperationException"
org.eclipse.smarthome.io.transport.serial.UnsupportedCommOperationException: gnu.io.UnsupportedCommOperationException
	at org.eclipse.smarthome.io.transport.serial.rxtx.RxTxSerialPort.enableReceiveThreshold(RxTxSerialPort.java:157) ~[?:?]
	at org.openhab.binding.teleinfo.internal.serial.TeleinfoSerialControllerHandler.openSerialPortAndStartReceiving(TeleinfoSerialControllerHandler.java:176) [243:org.openhab.binding.teleinfo:2.5.0.201911041935]
	at org.openhab.binding.teleinfo.internal.serial.TeleinfoSerialControllerHandler.initialize(TeleinfoSerialControllerHandler.java:74) [243:org.openhab.binding.teleinfo:2.5.0.201911041935]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:?]
	at org.eclipse.smarthome.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:152) [133:org.openhab.core:2.5.0.M3]
	at org.eclipse.smarthome.core.internal.common.Invocation.call(Invocation.java:53) [133:org.openhab.core:2.5.0.M3]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
	at java.lang.Thread.run(Thread.java:748) [?:?]
Caused by: gnu.io.UnsupportedCommOperationException
	at gnu.io.rfc2217.TelnetSerialPort.enableReceiveThreshold(TelnetSerialPort.java:948) ~[?:?]
	at org.eclipse.smarthome.io.transport.serial.rxtx.RxTxSerialPort.enableReceiveThreshold(RxTxSerialPort.java:155) ~[?:?]
	... 12 more

During my searchs I didnā€™t see anyone who succeeds in making rfc2217 worksā€¦ Everybody seems to use socat instead. Does rfc2217 actually work on openhab?

No idea :sweat_smile:
And what is the result with socat command ?

I have a working socat configuration in my openhab docker image. I have to manually launch the socat command inside the docker:

socat pty,link=/dev/ttyUSB21 tcp:192.168.0.21:5001,reuseaddr,keepalive,connect-timeout=5,keepcnt=5,keepidle=5,keepintvl=5

It seems to work because I can see teleinfo data when I launch cat /dev/ttyUSB21
Now openhab send me this error:

[ERROR] [rial.TeleinfoSerialControllerHandler] - No port identifier for '/dev/ttyUSB21'

Any idea?

[edit]
It works :grinning: with socat command

socat pty,link=/dev/ttyUSB21,raw,user=openhab,group=dialout,mode=777 tcp:192.168.0.21:5001,reuseaddr,keepalive,connect-timeout=5,keepcnt=5,keepidle=5,keepintvl=5
1 Like

Good job @hollysaiqs !

In this case, what is the value of Serial port parameter in Teleinfo Serial Configuration configuration ?

Thanks @nokyyz,
The value of Serial Port is /dev/ttyUSB21 (socat emulates an USB hardware). No need to have rfc2217 with socat, sorry for asking a functionality which was finally useless (for me).
I am currently trying to automate socat launching when running the docker image.

Is there any chance this binding will be official in openhab 2.5.0? Release seems to be closeā€¦

It remains to write the documentation (iā€™m struggling :neutral_face:), to merge/synchronize with the last source code of official openhab-addons github and then create a pull request :sweat:

So, what is the command line to broadcast your Teleinfo serial port on TCP/IP ? I think it would be interesting to specify it in the binding documentationā€¦