Norwegian HAN sensors

As I could not find any usable code to get the Norwegian AMS HAN interface translated into homeassistant, I thought I would give it a go :smiley:
Here it is:

As I wrote in the README, I have only tested the code on a Kamstrup 3phase meter.
I can add support for other type of meters later, but I need someone with the actual meters to test and supply feedback.
For it to work, you need a MBus serial reader.
Please give feedback, and use github for issues and bugs.
And keep in mind, I am not a experienced python coder :slight_smile:

5 Likes

@turbokongen I’ve tested your component for a few days with this MBUS to USB slave module connected to a usb port on my NUC and a Kamstrup single phase meter. It worked “out of the box” with no issues or bugs at all.
For now it runs in parallel with my old NodeMCU-to-MQTT solution, which will soon be retired thanks to you :slight_smile:

Thank you for sharing. Any plans for making it available in HACS?

Thank you! Good to hear that the code is working on single phase meters as well.
HACS, I have not used that, but at a quick glance, I might have to consider adding it in there. I will se what I can do.

You can now add my repository to HACS.

I have also updated it to use config_flow instead of YAML setup.
A change in the entity_id has been made, to support multiple instances.
The device registry has also been implemented.

1 Like

Hi,

I just got my HAN port opened and testing this for the first time.
The MBUS adapter is connected to the USB port, however I get the error msg as seen below.
Any ide of what is going on?

Blockquote
2020-01-08 18:18:44 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Norwegian AMS for ams
Traceback (most recent call last):
File “/usr/local/lib/python3.7/site-packages/serial/serialposix.py”, line 265, in open
self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
FileNotFoundError: [Errno 2] No such file or directory: ‘/dev/ttyUSB0’
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/config_entries.py”, line 192, in async_setup
hass, self
File “/config/custom_components/ams/init.py”, line 66, in async_setup_entry
hub = AmsHub(hass, entry)
File “/config/custom_components/ams/init.py”, line 98, in init
timeout=DEFAULT_TIMEOUT)
File “/usr/local/lib/python3.7/site-packages/serial/serialutil.py”, line 240, in init
self.open()
File “/usr/local/lib/python3.7/site-packages/serial/serialposix.py”, line 268, in open
raise SerialException(msg.errno, “could not open port {}: {}”.format(self._port, msg))
serial.serialutil.SerialException: [Errno 2] could not open port /dev/ttyUSB0: [Errno 2] No such file or directory: ‘/dev/ttyUSB0’
2020-01-08 18:18:56 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Norwegian AMS for ams
Traceback (most recent call last):
File “/usr/local/lib/python3.7/site-packages/serial/serialposix.py”, line 265, in open
self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
FileNotFoundError: [Errno 2] No such file or directory: ‘/dev/ttyUSB0’
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/config_entries.py”, line 192, in async_setup
hass, self
File “/config/custom_components/ams/init.py”, line 66, in async_setup_entry
hub = AmsHub(hass, entry)
File “/config/custom_components/ams/init.py”, line 98, in init
timeout=DEFAULT_TIMEOUT)
File “/usr/local/lib/python3.7/site-packages/serial/serialutil.py”, line 240, in init
self.open()
File “/usr/local/lib/python3.7/site-packages/serial/serialposix.py”, line 268, in open
raise SerialException(msg.errno, “could not open port {}: {}”.format(self._port, msg))
serial.serialutil.SerialException: [Errno 2] could not open port /dev/ttyUSB0: [Errno 2] No such file or directory: ‘/dev/ttyUSB0’

@oleandor Have you solved this? If not and if you are using Hass.io, press the Hardware button in Hass.io system menu. The USB-port your MBUS reader is connected to should be in the list.
I have tested this plugin with several MBUS readers and sometimes the reader connects as /dev/ttyUSB1.
In your error msg it looks like HA doesn’t find anything connected to /dev/ttyUSB0…

This is the MBUS slave I’m using, and it do show in the Hardware section in Hassio, as show below.
Hmmm…
Have you tried this adapter? If so, do you remember how the lights were, when it worked? On my adapter, one light is blinking and the other is off.
What will the senor(s) be called in Hassio?

I may be wrong but I think it’s your Conbee II (if it’s a usb-stick?) that shows up as /dev/ttyUSB0.
I haven’t testet your HAN-reader because I couldn’t figure out the one not to buy…


At the moment I’m using this HAN reader together with a standard TTL2USB-card (I have also tested some homespun stuff and it all seems to work fine with this plugin).

In HA it shows up as /dev/ttyUSB0:
usb0
The Integration looks like this:
integrations
And the sensors shows up like:

I don’t know which HAN-reader @turbokongen has testet. But we ask, and maybe he has an idea of whats wrong with yours.

I use this reader:


I actually have one of that reader in your picture lying around. Let me try to find it and see if I can get it up and running.
Right out of my memory I belive that adapter needs ODD parity. But let me see if I can find it.

Well, found the adapter and tested it.
It is recognized, but it can’t deliver the expected data. Only getting invalid packets.
However it is loaded, so your error is that you use the wrong USB port.

@oleandor Sorry I didn’t ask at the beginning. Your meter is a Kamstrup meter? I don’t think @turbokongen has implemented readers for Aidon and Kaifa meters yet… in case you didn’t noticed.

If someone has a Aidon or Kaifa meter, please send me the packages for them. I’ll be happy to implement decoders for them as well in the module.
It would also be nice if we can make a list of working and NON working usb modules to use with the library.
I’ve updated the readme with the three modules from this thread.

This plugin is exactly what I’ve been looking for!

I have Kaifa meter. Got the USB FC722 adapter from Aliexpress.
The HAN-port on my meter has not been opened yet, but will have it done next week.

Here is a datastream example from a Kaifa meter:
https://www.dropbox.com/s/a02ma2o6nb6i7w9/HAN%20data%20stream%202017-2-14.pdf?dl=0

@turbokongen You may add this mbus-reader to the list of known working modules. It’s the same brand as the one you have tested. This one has signal isolation. I use it together with this micro-usb FTDI.
With a little help of a precision knife and a drop of Loctite All Plastics glue it fits into a small plastic enclosure.

Thank you for the latest updates. No more heavy cpu- and memory use. My system is now running smoothly on low temperature.

system

I sure will add that adapter to the list.
Can you please tell me the git vversion you are running?
I’ve been trying to find that memory leak, but unsucsessful, and have made a lot of commits.
Maybe the memory use was due to the CPU use?
Really nice to hear it’s working good.
That’s a really nice and clean compination you have made there!

Thank you. It’s nice to have some pastime :slightly_smiling_face:
I’m running version 1.01. You may be right that the increase of memory use was related to the cpu use. Running the early releases, I experienced much the same as Hellowlol and thomasja27 have reported on Git. On my NUC I had an increase of cpu use from 5 to around 30%, and system temperature increased to around 55-60 degrees C. I also experienced a slight increase of memory use to around 20-25%.
But it’s all gone now as far as I can see.

Good to hear. Thanks for the feedback :100:

Hi, thanks for great software.
I have 2 questions:

1: my kaifa 3 phase meter it say 0 volts on ams_voltage_l2, is this something in you module or is it something wrong in my meter? or is it that Im on a 230 volt system (not 400)

im using this mbus module:

2: another issue, migth be that I use a pi3, but the software runs for about 1 hour, then stops, while measurement comes in it is a load of 1.4 to 1.9, when it stops measure, load drops to 0.1

is the pi 3 just to small or is there something else.

the pi that has the mbus adapter only runs the norwegian han sensor, nothing else.
last log entry

2020-03-21 15:21:26 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for ams which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant.
2020-03-21 15:22:01 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 425, in _async_add_entity
    raise HomeAssistantError(msg)
homeassistant.exceptions.HomeAssistantError: Entity id already exists: sensor.ams_active_power_import_none. Platform ams does not generate unique IDs
2020-03-21 15:43:30 WARNING (MainThread) [asyncio] socket.send() raised exception.
2020-03-21 15:43:31 WARNING (MainThread) [asyncio] socket.send() raised exception.
2020-03-21 15:43:31 WARNING (MainThread) [asyncio] socket.send() raised exception.
2020-03-21 15:43:31 WARNING (MainThread) [asyncio] socket.send() raised exception.
2020-03-21 15:43:31 WARNING (MainThread) [asyncio] socket.send() raised exception.
2020-03-21 15:43:31 WARNING (MainThread) [asyncio] socket.send() raised exception.`

Seems like a very interesting project - thanks for sharing @turbokongen

I am stuck with a Kamstrup Omnipower three-phase meter. Any ideas to what my options are then? (I am quite a novice in power meters like this, so any help greatly appreciated).

Thanks!

The project works with all the Norwegian smart meters.
If you don’t have a smart meter you could use optical sensor or a inductive sensor to monitor usage.
My project does not cover those options.