Originally published here: 
https://openforce.com/blog/2020/05/13/solar-openhab/  this is an example of DIY Solar Automation with openHAB
The stars align
There are various hot topics at the moment that are undergoing massive transformation and development.
- Electric cars 
 
- Renewable energy 
 
- Home batteries 
 
- Smart homes
 
- Cloud data
 
- Smart electric grids  
 
- The environmental crisis
 
Combining these evolving themes has the potential to provide environmental and financial benefits that will transform our lives.
We have the challenges of fluctuating renewable energy production as 
well as consumption. Energy storage needs to be managed intelligently to
 make it cost effective. Smart decisions may require information like 
the weather forecast and the current market price of electricity. How 
can we master these new complex systems?
No doubt forward looking companies will be working on products to 
take advantage of the new opportunities created by this disruption.  
This article looks at a DIY approach to managing and automating home 
systems. 
openHAB the open Home Automation Bus
openHAB
 is an open source project that aims to reduce all things to a number or
 state so that they can be modeled, monitored and controlled across 
products, protocols and contexts. It has bindings to many “things” and 
it can run on a Raspberry PI. 
Using the openHAB bindings various devices can be combined to build 
smart systems.  Here we use the openHAB Fronious binding to get data 
from the inverter and MQTT messages to communicate with remote devices. 
 Grafana can be used to monitor the systems with dynamic charts. 
If you want to play along at home, here is a dockerized openHAB 
example with a mysql database and grafana charts.  It models a house 
with Solar Panels.  You will need a Fronious inverter with smart meter 
running on your network.
git clone https://github.com/dougculnane/openHAB_solar.git
Smart Solar Power
To
 get the best return on investment from a domestic solar power system 
you have to shift your electric consumption to use the energy your 
system produces. 
Changing personal behaviour to run dishwashers and washing machines 
when the sun shines helps a great deal but we can also automate systems.
Use PV power to heat water.
Heating
 a hot water tank requires a few kilowatts hours of energy. They are a 
kind of large energy store that is very simple and cheap.  Hot water can
 also be a useful luxury in a modern home.  Obviously we want to heat 
the water with the energy we produce rather than the expensive 
electricity we buy from the grid.
By controlling the thermostat using openHAB and developing rules that
 automatically adjust the thermostat temperature based on the current 
electric grid meter value, we can soak up some energy rather than 
exporting it to the grid.
Here you can see a good sunny day where the hot water tank stored 
about 3kWh between 12:00 and 13:00.  We can also see that manually 
putting on the dishwasher, washing machine and cooking during the day 
helps to match production with consumption.  The trigger for the hot 
water tank needs to be on the grid power measurement so it does not turn
 on while the oven is on etc.
Some days the production and consumption curves are not as 
predictable and so averaging out the measurements over a few minutes is 
needed in the rules to add a bit of stability to control decisions.
Electric car charging
Electric
 cars bring a huge battery to these connected systems.  Most of these 
mobile batteries are idle more than 90% of the time, and so slow 
charging could be used to soak up excess PV power.  With vehicle to grid
 technologies the night time consumption can be shifted to the day.
A mobile battery project is in my task back catalogue so hopefully I will be able to report on that soon.
The future
Hopefully
 this article has shown the potential for this smart approach.  Rules 
can be developed to balance the electrical grid, make money and/or 
increase comfort.  We all have different priorities that also evolve and
 change as new systems develop.  Maybe this DIY approach is not for 
everyone but becoming master of your domain can be a lot of technical 
fun.