Water meter reading via NFC

Yesterday the local water company installed a new remote readable water meter in my house. The meter made by Zenner and the type is DE-20-MI001-PTB011.

I searched technical data for the meter and found out that the meter communicates via LoRa to the water company servers. But the meter also has NFC. I was able read the NFC with my phone(NFC tools). NFC data included the meter S/N, date/time, Total water consumption, temperature, battery status, etc. NFC tools shows the Payload in UTF8, hex and ascii.

My question is that can I use ESPHome+PN532 nfc module to read the water consumption and temperature data and send it via mqtt to Homeassistant? Can the PN532 module be mounted permanently to the water meter housing and can I define the read interval in the configuration to be for example 1 hour?

Any help would be appreciated.

1 Like

Well Ive seen nfc readers for passive nfc tags, so reading is not the issue. The message to the broker timed sounds also like a simple timer. I see no issue
Iā€™m interested in this!

As implemented the PN532 will only read a tag once, and wonā€™t re-read it unless the tag is removed then replaced. Depending on how the meter operates this may be an issueā€¦

EDIT: just had a thought - if you only wanted a reading an hour, use deep sleep.

I tested this and when the ESP wakes from deep sleep it re-reads the tag. So again depending on the meter this may work.

I was also thinking same thing that it will read the tag only once. Deep sleep might be the solution for that. Thankā€™s for testing that. I need to order one PN532 and test it with my meter will it work.

Is the template sensor way to go for sending the nfc payload to mqtt? I have not used that before and need to learn it.

Or a few template sensors, depending on the records in the NDEF message. This code reads the first 2 NDEF records and publishes them to template sensors:

text_sensor:
  - platform: template
    name: "NDEF data 1"
    id: ndef_payload1
  - platform: template
    name: "NDEF data 2"
    id: ndef_payload2

i2c:
  sda: 21
  scl: 22
  scan: true
  id: bus_a

pn532_i2c:
  update_interval: 1s
  on_tag:
    then:
      - lambda: |-
          if (tag.has_ndef_message()) {
            auto message = tag.get_ndef_message();
            auto records = message->get_records();
            std::string payload1 = records[0]->get_payload();
            std::string payload2 = records[1]->get_payload();
            id(ndef_payload1).publish_state(payload1);
            id(ndef_payload2).publish_state(payload2);
          }
1 Like

Thank you for the example code. I will try it and let you know if it works.

Hi,

I just want to thank you for this thread. I have exactly the same situation as @puuhapet
I had RFID-RC522 on hand but quickly realized that itā€™s not able to read tag contents. So I ordered a few PN532 readers.
For testing purposes I went to my water meter and copied the NFC contents to another tag with my phone. So far so good.

With the help from @zoogara I got my esp32 configured with i2c. However when I try to read a tag my ESP32 crashes :S

I was able to get some data out of my POC tag like so before it crashed. It was not able to send any information to HA however

11:36:47][V][pn532_i2c:049]: Reading response of length 18
[11:36:47][V][nfc.ndef_message:009]: Building NdefMessage with 300 bytes
[11:36:47][V][nfc.ndef_message:073]: Adding record type T = Ultrasonic Water Meter
S/N:
Time: 2023-11-06 07:00
Vol: 4.329 mĀ³
KDate: 2024-01-01
KVol: ā€“ mĀ³
2023-11-01: 3.614 mĀ³
2023-10-16: 1.328 mĀ³
2023-08-23: 0.000 mĀ³
Temp: 12.9 Ā°C
FVol: 4.329 mĀ³
RVol: 0.000 mĀ³
Battery: 2039
FW: 1.07.9.1791
CRC 57801

WARNING vesimittari.local: Connection error occurred: [Errno 104] Connection reset by peer
INFO Processing unexpected disconnect from ESPHome API for vesimittari.local
WARNING Disconnected from API

Any Idea what might be going on here? Did you @puuhapet get this to work?
I have a fall back plan to use rpi but itā€™s a bit overkill imo.

Hmm possibly an issue with your lambda? Post your yaml and maybe someone can spot the cause.

1 Like

Hereā€™s my relevant YAML. Thanks for the lambda suggestion. Iā€™ll try search and learn more about these lambda functions. This esp32 world is all new to me :slight_smile:

i2c:
  sda: GPIO18
  scl: GPIO19
  scan: true

pn532_i2c:
  update_interval: 1s
  on_tag:
    then:
      - lambda: |-
          if (tag.has_ndef_message()) {
            auto message = tag.get_ndef_message();
            auto records = message->get_records();
            std::string payload1 = records[0]->get_payload();
            std::string payload2 = records[1]->get_payload();
            id(ndef_payload1).publish_state(payload1);
            id(ndef_payload2).publish_state(payload2);
          }

text_sensor:
- platform: template
  name: "NDEF data 1"
  id: ndef_payload1
- platform: template
  name: "NDEF data 2"
  id: ndef_payload2

Not your yaml by the look. Maybe the PN532 component library has issues with lots of data fields. What happens if you read a tag with only a couple of fields defined?

1 Like

Thanks for the suggestion. I wrote a tag with a simple text ā€œHello world!ā€. Unfortunately the same result.
I also tried a different PN532 but the result was the same
Then I updated ESPhome to 2023.10.6 from 2023.9.someversion but no changes
I have a bunch of these small ESP-WROOM-32 boards so I will try another one just in case. Unfortunately life gets in the way of tinkering so it will take some time until I can try this.

[09:59:22][W][component:214]: Component pn532 took a long time for an operation (0.13 s).
[09:59:22][W][component:215]: Components should block for at most 20-30ms.
[09:59:22][V][pn532:274]: Reading ACKā€¦
[09:59:22][V][pn532:285]: ACK valid: YES
[09:59:22][V][pn532_i2c:043]: Reading response
[09:59:22][V][pn532:290]: Sending NACK for retransmit
[09:59:22][V][pn532_i2c:049]: Reading response of length 11
[09:59:22][D][pn532:308]: Mifare classic
[09:59:22][V][pn532:274]: Reading ACKā€¦
[09:59:22][V][pn532:285]: ACK valid: YES
[09:59:22][V][pn532_i2c:043]: Reading response
[09:59:22][V][pn532:290]: Sending NACK for retransmit
[09:59:22][V][pn532_i2c:049]: Reading response of length 2
[09:59:23][V][pn532:274]: Reading ACKā€¦
[09:59:23][V][pn532:285]: ACK valid: YES
[09:59:23][V][pn532_i2c:043]: Reading response
[09:59:23][V][pn532:290]: Sending NACK for retransmit
[09:59:23][V][pn532_i2c:049]: Reading response of length 18
[09:59:23][V][pn532:274]: Reading ACKā€¦
[09:59:23][V][pn532:285]: ACK valid: YES
[09:59:23][V][pn532_i2c:043]: Reading response
[09:59:23][V][pn532:290]: Sending NACK for retransmit
[09:59:23][V][pn532_i2c:049]: Reading response of length 2
[09:59:23][V][pn532:274]: Reading ACKā€¦
[09:59:23][V][pn532:285]: ACK valid: YES
[09:59:23][V][pn532_i2c:043]: Reading response
[09:59:23][V][pn532:290]: Sending NACK for retransmit
[09:59:23][V][pn532_i2c:049]: Reading response of length 18
[09:59:23][V][pn532:274]: Reading ACKā€¦
[09:59:23][V][pn532:285]: ACK valid: YES
[09:59:23][V][pn532_i2c:043]: Reading response
[09:59:23][V][pn532:290]: Sending NACK for retransmit
[09:59:23][V][pn532_i2c:049]: Reading response of length 18
[09:59:23][V][nfc.ndef_message:009]: Building NdefMessage with 30 bytes
[09:59:23][V][nfc.ndef_message:073]: Adding record type T = Hello world!
WARNING vesimittari.local: Connection error occurred: [Errno 104] Connection reset by peer
INFO Processing unexpected disconnect from ESPHome API for vesimittari.local
WARNING Disconnected from API
WARNING Canā€™t connect to ESPHome API for vesimittari.local: Error connecting to (ā€˜192.168.1.155ā€™, 6053): [Errno 111] Connect call failed (ā€˜192.168.1.155ā€™, 6053) (SocketAPIError)
INFO Trying to connect to vesimittari.local in the background
INFO Successfully connected to vesimittari.local

Ok - thatā€™s weird - all I can suggest now is you have a hardware issue somewhere - maybe double check the wiring and the dip switches.

Shame because it looks like the concept will work based on the data you have shown.

1 Like

I finally received my PN532. I tried with ESP32 dev and wemos D1 mini board in SPI mode and did not get it working. I also tried creating a simple Hello-text with my phone like @jonixx. The ESPhome log shows that the PN532 recognises the tag as Mifare classic but is not able to read the content. The log is not showing anything when trying to read the water meter.

NFC tool shows the tag type as Mifare Ultra. Is the PN532 and ESPhome able to read this type of tag?

Iā€™m using ESPhome version 2023.11.3

Hi Tuomas,

I have just received the exact same water meter, so in case youā€˜ve made any progress it would be interesting to hear more about your findings.

Hello

I havenā€™t got it working. My ESPhome+PN532 is not able to read the water meter tag and I donā€™t know why. I have not had motivation to work on this. Iā€™m open for ideas.

I just got a similar meter by Zenner. Also interested in this, but at least my meter doesnā€™t give any NFC detection when I try to read it with NFC Toolsā€¦

I just got the same meter, Zenner. Any progress?

No progress with ESPhome+PN532. I can read the meter with my phone and NFC tools. I have tried to find a way to use my old phone and automate the nfc reading and send the data with mqtt to homeassistant. With Tasker I can do the reading of the nfc but I have not found a way to send the data with mqtt.

1 Like