May 30, 20233 yr After some experimenting, I've come up with a reliable way to turn various Sonoff Switches on/off based on current Sunsynk stats such as SOV, Grid load, Solar generation, time of day etc. It even has a simple dashboard I'm displaying on an old phone stuck to the wall so that the family knows when is a good time to fire up the washing machine, dishwasher etc. I have various rules (in a bash script) that looks at the Sunsynk stats every 5 minutes and takes decisions on what to turn on/off based on current conditions. This is especially useful if like me you have the entire house on essential load and want fine-grained control of where excess power is used, while minimising Eskom usage. Sonoff switches are like R150 so it does not break the bank to add this level of automation. For the geyser, I have a 20A Sonoff which is a bit more but not crazy price. In my basic searching, I'm not sure if anyone has done this before as I have seen posts about waiting for the Sunsynk smart switch to do this kind of thing. If this is novel and people would like to know how to get this right, please let me know and I'll do a write up. I didn't want to do a long post, only to find that I've reinvented the wheel.
May 30, 20233 yr Author Ok sure. Here goes. This assumes you know some basic linux. If not maybe this is not for you but perhaps I can help if needed: 1) Make sure your Sunsynk connect App is working and you know your username/password. 2) Make sure your Sonoff switches are working in the Ewelink app and you know your username/password. 3) Fire up an Ubuntu VM on AWS/Azure/GCP or even on a Pi or home PC. It can be really small like 512MB RAM and needs internet access 4) Install docker in the linux vm. Follow something like this: https://kinsta.com/blog/install-docker-ubuntu/ 5) Someone wrote a nodejs gateway to mimic the calls done by the Ewelink App see: https://github.com/DoganM95/Ewelink-Rest-Api-Server I leverage this as a way to control the Sonoff Switches. To run this listening on port 8089 run this. It needs your Ewelink username/password you registered in the App so it can call into Ewelink servers: docker run -d --restart=always -p 8089:3000 -e "EWELINK_USERNAME=yourusername" -e "EWELINK_PASSWORD=yourpassword" -e "EWELINK_REGION=eu" -e "PASSWORD_HASHING_ALGORITHM=sha512" -e "SERVER_MODE=prod" doganm95/ewelink-rest-api-server 6) Test you can turn a switch on like this (Replace "Your Switch Name" with the switch name as it appears in the Ewelink App): curl -m20 -sX POST "http://localhost:8089" -H "content-type: application/json" -d"{\"devicenameincludes\":[\"Your Switch Name\"],\"params\":{\"switch\":\"on\"}}" 7) Install a json parser utility: sudo apt install jq 8. In your home folder add the attached script.sh and make it executable with chmod +x ./script.sh 9) In the script set your Sunsynk connect username and password on rows 4 & 5 for SUNSYNK_USER and SUNSYNK_PASS. Then set SUNSYNK_PLANT on row 6 with the plant ID you see if you login to sunsynk connect in your browser. E.g. mine is 88663: 9) Create a cron schedule to run the script every 5 minutes: crontab -e -> then add a row like this: */5 * * * * /home/ubuntu/script.sh >> /home/ubuntu/solar.log 10) Edit the script to suit your needs and refer to your Sonoff switch names. I've got a simple example of a switch called "My Switch" that will turn on if we have excess power and Off if we don't. If you don't know what going on, ping me with your switch names and basic rules and I can help. You have a huge amount of control. I have some fairly complex rules around hour of day etc. 11) To see what the script is doing, run tail -f /home/ubuntu/solar.log I'd love it if this is useful to anyone so let me know if you need help and add any things I might have missed to make the instructions foolproof. My script generates a basic HTML page of the current status but I deleted that part as it just makes the script more complex than necessary. Anyone with basic bash scripting can go wild. If you comfortable with python or something else then use that - its really just some HTTP GET and POST commands surrounded with JSON parsing. script.sh
May 30, 20233 yr 1 hour ago, paulcb said: Ok sure. Here goes. This assumes you know some basic linux. If not maybe this is not for you but perhaps I can help if needed: 1) Make sure your Sunsynk connect App is working and you know your username/password. 2) Make sure your Sonoff switches are working in the Ewelink app and you know your username/password. 3) Fire up an Ubuntu VM on AWS/Azure/GCP or even on a Pi or home PC. It can be really small like 512MB RAM and needs internet access 4) Install docker in the linux vm. Follow something like this: https://kinsta.com/blog/install-docker-ubuntu/ 5) Someone wrote a nodejs gateway to mimic the calls done by the Ewelink App see: https://github.com/DoganM95/Ewelink-Rest-Api-Server I leverage this as a way to control the Sonoff Switches. To run this listening on port 8089 run this. It needs your Ewelink username/password you registered in the App so it can call into Ewelink servers: docker run -d --restart=always -p 8089:3000 -e "EWELINK_USERNAME=yourusername" -e "EWELINK_PASSWORD=yourpassword" -e "EWELINK_REGION=eu" -e "PASSWORD_HASHING_ALGORITHM=sha512" -e "SERVER_MODE=prod" doganm95/ewelink-rest-api-server 6) Test you can turn a switch on like this (Replace "Your Switch Name" with the switch name as it appears in the Ewelink App): curl -m20 -sX POST "http://localhost:8089" -H "content-type: application/json" -d"{\"devicenameincludes\":[\"Your Switch Name\"],\"params\":{\"switch\":\"on\"}}" 7) Install a json parser utility: sudo apt install jq 8. In your home folder add the attached script.sh and make it executable with chmod +x ./script.sh 9) In the script set your Sunsynk connect username and password on rows 4 & 5 for SUNSYNK_USER and SUNSYNK_PASS. Then set SUNSYNK_PLANT on row 6 with the plant ID you see if you login to sunsynk connect in your browser. E.g. mine is 88663: 9) Create a cron schedule to run the script every 5 minutes: crontab -e -> then add a row like this: */5 * * * * /home/ubuntu/script.sh >> /home/ubuntu/solar.log 10) Edit the script to suit your needs and refer to your Sonoff switch names. I've got a simple example of a switch called "My Switch" that will turn on if we have excess power and Off if we don't. If you don't know what going on, ping me with your switch names and basic rules and I can help. You have a huge amount of control. I have some fairly complex rules around hour of day etc. 11) To see what the script is doing, run tail -f /home/ubuntu/solar.log I'd love it if this is useful to anyone so let me know if you need help and add any things I might have missed to make the instructions foolproof. My script generates a basic HTML page of the current status but I deleted that part as it just makes the script more complex than necessary. Anyone with basic bash scripting can go wild. If you comfortable with python or something else then use that - its really just some HTTP GET and POST commands surrounded with JSON parsing. script.sh 3.26 kB · 0 downloads This is great for those who don't want to run Home Assistant or tinker with ESP devices... good one Edited May 30, 20233 yr by mzezman
May 31, 20233 yr Thanks for the post, any reason you aren't using some form of home automation instead?
May 31, 20233 yr Author 3 hours ago, spotity said: Thanks for the post, any reason you aren't using some form of home automation instead? Hi. To be honest the answer is that I was not aware of anything that could do this. If there is a simpler solution to control Sonoff switches based on Sunsynk data then please so share here for anyone who comes across this. I did some basic searching and didn't find anything hence the DIY solution.
June 1, 20233 yr On 2023/05/31 at 10:30 AM, paulcb said: Hi. To be honest the answer is that I was not aware of anything that could do this. If there is a simpler solution to control Sonoff switches based on Sunsynk data then please so share here for anyone who comes across this. I did some basic searching and didn't find anything hence the DIY solution. Absolutely, I am running home assistant on a Pi4 - eWelink integration via SonoffLan and then I make use of @Gary Waterworth's integration to Sunsynk using Nodered. Another option is to use Solar Assistant and the native integration between solar assistant and home assistant, but this obviously requires more PI's and config. From here you have endless possibilities including controlling your inverter. Home assistant gives you a dashboard which is very customizable. I use the Sunsynk card from @slipx on my dashboard, with a lot of automation to control what turns on and when (Geyserwise, Sonoffs, Appliances etc) Home assistants has steep learning curve initially, but there is a massive community that are willing to help - also considering the above, you are not an average user - you'll be more than okay 😅 Shout if you want to find out any other info and I'll be happy to answer.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.