To be able to use the azimut and elevation within the evaluator I found a way to read that data from the Solar_Computer directly from the DSS.
Here is my script:
{
'message': 'init',
'tag' : 'SolarRechner',
'protocol': 'json',
'group': 8, /* Joker */
'name': 'SolarRechner', /* initialer Name */
/* Definition der Sensoren */
'sensors': [
/* S0 */ { 'id': 'sr_azimuth', 'sensortype': 0, 'usage': 0, 'group': 0, 'hardwarename': 'SR_Azimuth', 'min': 0, 'max': 360, 'resolution': 0.01, 'updateinterval': 120 },
/* S1 */ { 'id': 'sr_elevation', 'sensortype': 0, 'usage': 0, 'group': 0, 'hardwarename': 'SR_Elevation', 'min': -90, 'max': 90, 'resolution': 0.01, 'updateinterval': 120 },
]
}
The script itself is comming now:
function getSunAziElev()
{
/* https://forum.plan44.ch/d/57-import-digitalstrom-sensor-values-into-plan44/4 Quelle des Scripts*/
/* Get session token. Please note a session token is valid for only 180 seconds */
/* Note the "!" before the URL, this disables certificate checking */
var resACCESS
var resJSON
log('GetValues: %s', format('!https://%s:8080/json/apartment/getSensorValues?id=%s&groupid=%s&token=%s', dssip, zone_id, group_id , token))
try {
/* Retrive the sensor values from digitalSTROM with the help of the session token */
/* correct call look like: */
/* !https://dss.local:8080/json/apartment/getSensorValues?id=0&groupid=0&token=sessiontoken*/
/* on first call token is not yet available and will be requested in the catch block */
resJSON = json(geturl(format('!https://%s:8080/json/apartment/getSensorValues?id=%s&groupid=%s&token=%s', dssip, zone_id, group_id , token)))
log (" DSS-Import_Sensorvalues Access JSON reply = %s", resJSON)
var azimuth = resJSON.result.outdoor.sunazimuth.value
var elevation = resJSON.result.outdoor.sunelevation.value
log ('Azimuth: %3.2f', azimuth)
log ('Elevation: %3.2f', elevation)
message({'id': 'sr_azimuth', 'value': azimuth, "message": "sensor", 'tag':'SolarRechner'})
message({'id': 'sr_elevation', 'value': elevation, "message": "sensor", 'tag':'SolarRechner'})
}
catch {
log('We need session token first')
resACCESS = json(geturl(format('!https://%s:8080/json/system/loginApplication?loginToken=%s', dssip, logintoken)))
token = resACCESS.result.token
log ("DSS-Import_Sensorvalues Access Token reply = %s", resACCESS)
getSunAziElev() // No it should work, so we call the function again to get the values
}
}
/* Main program */
/*HowTo generate a token? */
/* Juster enter https://<yourdss>:8080/json/system/requestApplicationToken?applicationName=YourAppName*/
/* In the json answer you get the token, which you have to copy to logintoken*/
/* In the DSS itself on the system tab system/Zugriffsberechtigung you to place a hook for Access accepted */
var logintoken = 'ab6e4e5d8fe784c8b6ad7c8ad32703a3f44f93ee0e530a1a217b7ce0171f2284'; /* [my permanent token] */
var dssip = '192.168.1.210'; /* digitalstrom IP-Adress */
var zone_id = '0'; /* Room number as defined in digitalStrom */
var group_id = '0'; /* Room number as defined in digitalStrom */
var token = 'notyetset';
/* Call the sequence every 120 seconds */
on (every(120)) {
log ('--Start of getSunAziElev--')
getSunAziElev()
}
return true
The result will be th acual calculated value from the dss.
With the message block at the are additionaly written back to the dss.
I would like to avoid that, but for the moment I do not know how to just get the values
as just P44 "internal sensor values", which would then be fine for usage inside the evaluator.