Per my home solar project, I needed a method to collect data from both my batteries and inverters, in near-real-time, with no dependency on the internet.
Since, my inverter's connection relies on cloud applications to move data around, I decided to give Solar Assistant a try after reading of its support for the solark-12k.
Note- I orignally had this unit, however, during troubleshooting steps, I replaced it with another adapter.
I personally prefer the first one with the blinking tx/rx lights. It assisted with debugging. Also- the case on the bottom adapter started to fall apart.
Note, You really only need a 16G MicroSD card. I just happened to have a pile of 256G ones laying around. So- if you want to save a few bucks, you can get a smaller one.
A 64G card will never run out of room for this use-case.
If... your inverter is reading the status of your battery, this will allow you to "split" the serial connection and allow solar-assistant to read your inverter, while your inverter reads your battery.
If, you don't plan on using your inverter to read the serial data from your battery, you can skip this item. In my case, my inverter does not have support for reading my battery.
The plug on the solark uses typical RJ45/Ethernet wiring. Of the 8 wires in the cable, you can use either Orange+OrangeStripe, or Brown+BrownStripe. Both pairs are essentially the same. As well, green+greenStripe are both ground.
First of all, lets create a configmap containing the various configuration files we need to expose to mosquitto MQTT.
mqtt_configs.yaml
kind:ConfigMapmetadata:name:mqtt-configsnamespace:home-automationapiVersion:v1data:solar_assistant.conf:>connection SolarAssistantremote_username your_user_goes_hereremote_password your_password_goes_hereaddress 10.1.2.3 <-- Put the IP of your solar-assistant here.topic # intopic solar_assistant/# out mosquitto.conf:>persistence truepersistence_location /mosquitto/data/include_dir /mosquitto/config/conf.dlistener 1883 0.0.0.0password_file /etc/mosquitto/password_filepassword_file:>## Contents Obmitted.
In the above configuration, the secret needed is the solar_assistant.conf file. It contains the configuration needed to broker messages from the solar-assistant mqtt server, to this local mqtt server.
For obvious security purposes, the contents of my file will not be included here.
Next up, you will optionally need persistent storage. If you do not want/need persistent storage, update the mosquitto.conf file above, set persistence false and remove the persistence_location
2G is likely overkill for this need. Adjust as you please.
Finally, here is the stateful set manifest
mqtt.yaml
apiVersion:apps/v1kind:StatefulSetmetadata:labels:app:mqttname:mqttspec:replicas:1serviceName:mqttselector:matchLabels:app:mqtttemplate:metadata:labels:app:mqttspec:volumes:-name:datapersistentVolumeClaim:claimName:mqtt-data-name:configconfigMap:name:mqtt-configsdefaultMode:420containers:-name:mqttimage:eclipse-mosquitto:latestvolumeMounts:-name:datamountPath:"/mosquitto/data"-name:configmountPath:"/mosquitto/config/mosquitto.conf"subPath:mosquitto.conf-name:configmountPath:"/mosquitto/config/conf.d/solar-assistant.conf"subPath:solar_assistant.conf-name:configmountPath:"/etc/mosquitto/password_file"subPath:password_fileports:-name:mqttcontainerPort:1883-name:websocketcontainerPort:9001---apiVersion:v1kind:Servicemetadata:name:mqttspec:selector:app:mqttports:-name:mqttport:1883protocol:TCPtargetPort:mqtt-name:websocketport:9001protocol:TCPtargetPort:websockettype:LoadBalancerloadBalancerIP:10.140.5.6##Set your own exposed IP here. Or, change to nodeport. or- however you wish to expose MQTT.
At this point, you should have all of the pieces required to configure this within Kubernetes.
To note- this was not intended to be the end-all guide on how to configure MQTT in kubernetes. Just- enough information for you to update your MQTT instance to work.
After following the directions, you should end up with something like this:
Now- before you get excited to go and see your fancy energy dashboard.... You need to wait. It will take an hour or two before home-assistant starts displaying data on its energy dashboard.
While you are waiting, feel free to build out a few real-time dashboards.
In the above dashboard, you can see the energy dashboard panels still shows no data at all. (Even an hour later!)
On the bottom, I setup two sections. "Fast" metrics, and "Slow" metrics.
The kWh metrics are pretty slow to update. Since, the energy usage dashboards are also pretty slow to update, this is not an issue.
The "fast" metrics, have update intervals in the seconds. If you wish to build a real-time dashboard, use these!
After, waiting an hour or two- you should be presented with a working energy dashboard.
Here is a screenshot of solar-assistant's home page