I recently switched to a dynamic energy contract. Given the current state of home automation automatically controlling the solar inverter should be a possibility right? So I went of to work with just a few minutes of NR experience and also very limited Javascript knowledge (but some general programming experience). The end result is a system that automatically controls your inverter and can even automatically adjust the maximum inverter power output to your current consumption (if your inverter supports that). I like to learn from others but I think it’s also important to contribute. I also hope to contribute to better use of green energy, doing my tiny part of good to the world. At least I’d like to think that I can contribute So here is my first ever repo. I chose Codeberg cause I don’t like big tech and I am a proponent of privacy and open source. Here’s the URL and after that a summary of the information in the readme. All feedback is welcome!
https://codeberg.org/RespectDifference/HA-SolarControl
Intro summary
I tried to do this agile, compact and at the same time semantic; technically as good as possible but I have not catered for edge cases. Use at your own risk. Spring will definitively test the system to see how it works with negative energy prices; consider this a beta for now.
Purpose
Control solar panels based on energy prices in such a way that consumption of self generated solar power is optimized while preventing the inverter from sending power to the grid when prices are negative. In specific case adjust maximum inverter power to current consumption. Secondary: retrieve data to show a graph with prices for today and tomorrow. Both processes start by getting prices from Tibber.
Prerequisits:
- Tibber as energy provider and personal API token. Alternatively another provider with API access, will require property modification in relevant nodes.
- Solis solar inverter connected to Home Assistant
- Separate solar panel calendar. Should be easy to add one.
- Node-red
- Custom Node Red do-node for iteration
Inner workings
First workflow:
- An inject node starts the workflow every hour between 13:00 and 17:00 if prices for tomorrow haven’t been requested yet for that day. Wether prices have been requested and received is a boolean and is reset every day to false at 00:01.
- If prices haven’t been requested, Node Red makes an API call to Tibber for the prices.
- From here the flow splits.
- One of two things it does is send the prices to a sensor in NR so the data is available for an Apex chart (or anything else you’d like).
- The other action is an iteration over the array with prices. For each hour:
- Check if time is not before 06:00. There will never be sun before 06:00.
- If after 06:00, continue to check if the array value is for hour 23. If so, the last array index has been reached. Set prices requested to true. Do not process prices at 23:00 as there will never be sun at that time. 3.If the above is not applicable, decide which working mode is applicable based on trade price: solar on, solar off or autotune. Schedule an appointment in the solar agenda, with summary describing solar on, solar off or solar autotune. Trade and total prices are also added for reference.
Second workflow:
- Start flow every hour between 06:00 and 22:00
- Get the calendar appointment for that specific our
- Get working mode for the inverter for that specific hour from the appointment
- Check if current state is different to what it should be
- If true, set new state. On, off or autotune.
Autotune
My special recipe. Autotune will calculate what your average consumption was in the last 10 seconds, every minute. Then it will set the inverter to not generate more power than that. And that will be done 59 times from the start of that relevant hour. Hurray (if I may say so myself)!
Apex Chart dashboard card
I also added my Apex Chart dashboard card. Install Apex Chart before using it.