Dutch smart meters can only deliver electricity stats on imported and exported electricity from and to the grid. PV inverters sometimes have an API or RS-232 or other interface to deliver information on generated energy.

Years ago I had an Arduino Mega running with a modified version of an early version of Solarmeter by Harold65. I kept extending the code to provide more information and integrate better in my domotica setup. This has been running for some years until we moved to a new home. The older code can still be found here.

Recently we’ve installed solar panels on our home and although the inverter is delivered including an app, it is more fun to build something yourself. Additionally there is no API available to integrate with my domotica system. The original Solarmeter software is not updated anymore and my older version is not compatible with recent smart meters in the Netherlands. The Arduino Mega runs into its limits and cannot keep up with the data transfer of the new smart meters.

In my new setup, data of our smart meter is read by DSMRReader which runs on a Raspberry Pi. DSMRReader can send the data using MQTT. Additionally this data is also uploaded to pvoutput.org.

I was planning to use the Arduino Mega in a stripped version for only reading the S0 pulses from a kWh meter which is connected to the solar panel installation.

On the day the solar panels were installed, it turned out that we could re-use the cables to the washing machine. This would save us drilling holes. The ‘downside’ was that the kWh meter is now installed in the addict and I did not foresee a wired network connection near the washing machine ;-). I have to use WiFi now.

I had an Arduino Yun laying around for years, but never used it. This was the moment to start tinkering. The Arduino Yun is a board with a 32u4 microcontroller and a Linux processor and native Ethernet and WiFi onboard. The microcontroller is used to count the pulses of the S0 kWh meter and generates the Actual, Peak, Today generated and Total generated numbers. This is what the microcontroller is good at. The microcontroller can trigger (Python) scripts on the Linux part and send data to those scripts. The Linux processor will handle sending this data to MQTT, PvOutput and also provide a simple API to set initial values for ‘Total generated’. The Arduino Yun is equipped with a SDCard reader. In the original software the Today generated and Total generated numbers were stored in EEPROM. In the new version this is stored in individual files on the SDCard. 

Prepare Arduino Yun:
Follow the setup steps described on the Arduino website:

Download my source code from GitHub: https://github.com/arvdsar/S0_PVOutput_MQTT_Yun

Update the userdefs.h with your own information (like PVOutput API key).  Upload the sketch to your Arduino Yun.
In the repository you find a folder: Linux Side. You have to copy those files to the SD card on the Yun. Instead of copying, I just copy and past the contents in new files on the Arduino. You can update them right away with your details.

Connect to your Arduino Yun using SSH:
# ssh root@IP_of_arduino
Enter your password (same as in the Yun web interface)

Go to the correct location on SD card:
# cd /mnt/sda1

To make sure that the nano editor works:
# TERM=xterm-color

Edit sendmqtt.py file:
# nano sendmqtt.py

Copy and paste the contents of the file from the repository and meanwhile update with your information (IP Address and credentials of your MQTT server.)

Do the same for pvoutput.py and localtime.py.
Next, change file permissions of the files:

# chmod 755 sendmqtt.py 
# chmod 755 pvoutput.py
# chmod 755 localtime.py

Create a folder for the files that contain the total and today values from the script:
# mkdir store 

Setup additional software on the Arduino:
I got some of the step below from this site:  https://forum.arduino.cc/index.php?topic=544274.0;wap2

install Mosquitto on Linux (on the Yun)
# opkg update
# opkg install mosquitto mosquitto-client libmosquitto 
# wget \
https://pypi.python.org/packages/source/p/pip/pip-6.0.8.tar.gz#md5=2332e6f97e75ded3bddde0ced01dbda3\  –no-check-certificate
# easy_install pip-6.0.8.tar.gz
# pip install paho-mqtt
# pip install requests

Now you should be ready to run. Make sure the time is set properly on your Arduino. You can do that using the web interface of the Yun. The time is taken from the linux side of the Yun and synced to the Arduino side.

On PVOutput.org you officially have to deliver the generation values first (solar energy) and the NET values (from the smartmeter) later. In that case PVOutput will do the proper calculations. This seems to be okay most of the time, although so now and then I get a power usage of 0w but overall the totals are correct.

The values from DSMRreader and the Arduino are collected in Node-Red where I can forward the information to Domoticz, Grafana, Blynk and Complicated