SMA Sunnyportal Homemanager

Retrieve the JSON data with the current plant data of your pv system from the SMA sunnyportal. The data is passed as javascript object in the payload of the message.

Change the following lines in the script node to fit your credentials:

var email = 'your email';

var password = 'your password';

[{"id":"8a4e3a5d.967608","type":"function","z":"c8cb51c3.86bc","name":"SMA Sunnyportal Homemanager","func":"var email = 'your email';\nvar password = 'your password';\n\nvar request=context.global.request\n\nvar jar = context.get('jar') || request.jar();\ncontext.set('jar',jar);\n\nnode.on('close', function() {\n    context.set('jar',null);\n});\n\nvar LoginURL = 'https://www.sunnyportal.com/Templates/Start.aspx';\nvar LoginRequestOpts = {\n    headers: {\n        'Host':'www.sunnyportal.com',\n        'Origin':'https://www.sunnyportal.com',\n        'Referer':'https://www.sunnyportal.com/Templates/Start.aspx',\n        'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36'\n    },\n    form:{\n        __EVENTTARGET:'',\n        __EVENTARGUMENT:'',\n        ctl00$ContentPlaceHolder1$Logincontrol1$txtUserName:email,\n        ctl00$ContentPlaceHolder1$Logincontrol1$txtPassword:password,\n        ctl00$ContentPlaceHolder1$Logincontrol1$LoginBtn:'Login',\n        ctl00$ContentPlaceHolder1$Logincontrol1$RedirectURL:'',\n        ctl00$ContentPlaceHolder1$Logincontrol1$RedirectPlant:'',\n        ctl00$ContentPlaceHolder1$Logincontrol1$RedirectPage:'',\n        ctl00$ContentPlaceHolder1$Logincontrol1$RedirectDevice:'',\n        ctl00$ContentPlaceHolder1$Logincontrol1$RedirectOther:'',\n        ctl00$ContentPlaceHolder1$Logincontrol1$PlantIdentifier:'',\n        ctl00$ContentPlaceHolder1$Logincontrol1$ServiceAccess:true,\n        ctl00$ContentPlaceHolder1$hiddenLanguage:'en-us'\n    },\n    strictSSL : false,\n\tjar : jar\n}\n\n\nvar DataURL = 'https://www.sunnyportal.com/homemanager';\nvar DataRequestOpts = {\n    headers: {\n        'Host':'www.sunnyportal.com',\n        'Referer':'https://www.sunnyportal.com/FixedPages/HoManLive.aspx',\n        'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36',\n        'X-Requested-With':'XMLHttpRequest'\n    },\n    strictSSL : false,\n\tjar : jar\n}\n\nfunction doData(){\n    request.get(DataURL,DataRequestOpts,function(err,response){\n        if(err){\n            doLogin();\n            return;\n        }\n                \n        if(response.statusCode != 200){\n            doLogin();\n            return;\n        }\n        \n        try{\n            var data = JSON.parse(response.body);\n        }\n        catch(err){\n            doLogin();\n            return;\n        }\n        \n        if(data.Timestamp === null){\n            doLogin();\n            return;\n        }\n\n        var newMsg = { payload: data };\n        node.send(newMsg);\n        \n    })\n}\n\nfunction doLogin(){\n    request.post(LoginURL, LoginRequestOpts, function (err, response) {\n        if(err){\n            return;\n        }\n\n        if(response.headers.location && response.headers.location=='/FixedPages/HoManLive.aspx'){\n            node.log(\"Login\");\n            doData();\n        }\n        else{\n            return;\n        }\n    })\n}\n\ndoData();","outputs":1,"noerr":0,"x":451.6666564941406,"y":108.66666412353516,"wires":[["7c9226b9.e83ce8","ccaf7d64.728c4"]]},{"id":"7c9226b9.e83ce8","type":"debug","z":"c8cb51c3.86bc","name":"","active":true,"console":"false","complete":"false","x":719.6666259765625,"y":107.66666412353516,"wires":[]},{"id":"5c3722d4.a7aafc","type":"inject","z":"c8cb51c3.86bc","name":"every 5 seconds","topic":"","payload":"","payloadType":"date","repeat":"5","crontab":"","once":true,"x":182.66665649414062,"y":108.66666412353516,"wires":[["8a4e3a5d.967608"]]}]

Flow Info

Created 8 years, 3 months ago
Updated 4 years, 2 months ago
Rating: 1 1

Owner

Actions

Rate:

Node Types

Core
  • debug (x1)
  • function (x1)
  • inject (x1)

Tags

  • SMA
  • sunnyportal
  • homemanager
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option