Wow, that is a great feature, thanks for sharing! But would it work with logging in though? For that, you would need several steps. It might be possible, but I have not delved into the link that you shared, as I was already thinking on different possibilities. The reasons:
- It seemed like scan_interval did not allow for quick polling (in my case, 5s; not sure if this is a bug though…)
- Even if scan_interval would work, using CasperJS was not quick enough to actually get through all the steps in 5s and timeouts were a common occurence
So I had to look for different possibilities. I have found the node osmosis webscraper, which is a lot quicker than CasperJS, but also a bit less intuitive. Also, because of some less than expert programming on the side of SMA, it was not possible to actually get into the Sunny Portal. Banging my head against the Sunny Portal, I decided to take a look at the inverter to see if that was any easier.
And indeed it seems like the good people at SMA are better at making their inverter webserver that that of their website. Turns out that you only need two server calls for getting the necessary data. Be aware, this works for me as I have a new Sunny Boy 2.5. If you try this, I think you have to have Webconnect from SMA on your inverter.
The first call is to get a session ID:
curl -X POST -H "Connection: keep-alive" -H "Content-Length: 37" -H "Accept: application/json" -H "Accept-Encoding: gzip, deflate" -H "Content-Type: application/json" -H "Cache-Control: no-cache" -H '{"right":"usr","pass":"[[YOUR_PASSWORD]]"}' "http://[[INVERTER_IP]]/dyn/login.json"
You will receive the follow response containing a session id:
{
"result": {
"sid": "_-s_pfe_sQO_5ce5"
}
}
With the session ID, you can retrieve data:
curl -X POST -H "Connection: Keep-alive" -H "Content-Length: 37" -H "Accept: application/json" -H "Accept-Encoding: gzip, deflate" -H "Content-Type: application/json" -H "Cache-Control: no-cache" -H '{"destDev":[],"keys":["6100_40263F00"]}' "http://[[INVERTER_IP]]/dyn/getValues.json?sid=_-s_pfe_sQO_5ce5"
In this example, I only request the current power with the key “6100_40263F00”. If you want different values, you can just add these to the keys. To see which key is which value, you can check the id in the HTML code when you login to your inverter with your browser.
Using these requests, I have created a NodeJS application which runs the second request every 5 seconds. It also does some error handling, as sometimes a request does not successfully receive a session id. When it gets a value, it uses the Restful API from HA to write the value to a template sensor.
There are several reasons why I have decided to create a separate system for collecting the information:
- I want data to be written to InfluxDB at a certain point. Now that I have the current power being sent to HA, it is a matter of creating a new request that also sends it to InfluxDB.
- I want to collect more data from the inverter, but at different time intervals (I don’t need to check every 5 seconds how much we collected yesterday ).
- I am still considering sending the data through a MQTT broker (because I want to learn how it works, and throwing data directly to the Restful API which forcefully changes the value just feels dirty…).
- I am considering requesting different sources of data (for example getting the amount of money that I am saving, for which I need to get the price per kW from my energy provider).
An image on two different states which were changed by the NodeJS script:
Any views on this are highly appreciated! And if you need more information on my work, let me know, I am more than happy to help. I am curious if this also works for other people.