Hello to all,
I changed the whole scritping to the 'wsignal' way to do it.
Also I noticed a mistake with the 'wind_max', which is not the Maximum windspeed, within the DSS. There it shows up as 10Min average windspeed, so I adapted the script.
No first we have a 'MainScript'
var baseurl = string('http://gw2000_IP/get_livedata_info')
glob wsignal default signal()
// Alle 60 Sekunden
on (every(60)) {
// Wetter einlesen
log('Wittboy wird gelesen')
var wittboy=json(httprequest({'url': baseurl}))
/*-------------------------------
wsignal is send to all scripted devices, which have to read the json response
- Wetterstation
- GlobalInputs
- Bodenfeuchten
-------------------------------*/
wsignal.send(wittboy)
}
follwowed by the init message of 'Wetterstation
{
'message': 'init',
'tag' : 'GW2000',
'protocol': 'json',
'group': 8, /* Joker */
'name': 'Wetterstation', /* initialer Name */
/* Definition der Wetter-Sensoren */
'sensors': [
/* S0 */ { 'id': 't_outside', 'sensortype': 1, 'usage': 2, 'group': 0, 'hardwarename': 'Ausentemperatur', 'min': -50, 'max': 100, 'resolution': 0.1, 'updateinterval': 120 },
/* S1 */ { 'id': 'm_outside', 'sensortype': 2, 'usage': 2, 'group': 0, 'hardwarename': 'Aussenfeuchte', 'min': 0, 'max': 100, 'resolution': 1, 'updateinterval': 120 },
/* S2 */ { 'id': 'windchill', 'sensortype': 1, 'usage': 0, 'group': 0, 'hardwarename': 'Windchill', 'min': -50, 'max': 100, 'resolution': 0.1, 'updateinterval': 120 },
/* S3 */ { 'id': 'vpd', 'sensortype': 18, 'usage': 0, 'group': 0, 'hardwarename': 'VPD', 'min': 0, 'max': 5, 'resolution': 0.001,'updateinterval': 120 },
/* S4 */ { 'id': 'dew_point', 'sensortype': 0, 'usage': 2, 'group': 0, 'hardwarename': 'Taupunkt', 'min': 0, 'max': 100, 'resolution': 0.1, 'updateinterval': 120 },
/* S5 */ { 'id': 'wind_speed', 'sensortype': 13, 'usage': 2, 'group': 0, 'hardwarename': 'Windgeschwindigkeit', 'min': 0, 'max': 300, 'resolution': 0.1, 'updateinterval': 120 },
/* S6 */ { 'id': 'wind_gust', 'sensortype': 23, 'usage': 2, 'group': 0, 'hardwarename': 'Gust', 'min': 0, 'max': 300, 'resolution': 0.1, 'updateinterval': 120 },
/* S7 */ { 'id': 'wind_max', 'sensortype': 13, 'usage': 0, 'group': 0, 'hardwarename': 'Wind Max', 'min': 0, 'max': 300, 'resolution': 0.1, 'updateinterval': 120 },
/* S8 */ { 'id': 'solar', 'sensortype': 3, 'usage': 2, 'group': 0, 'hardwarename': 'Sonne', 'min': 0, 'max': 100, 'resolution': 0.1, 'updateinterval': 120 },
/* S9 */ { 'id': 'uv_index', 'sensortype': 0, 'usage': 0, 'group': 0, 'hardwarename': 'UV Index', 'min': 0, 'max': 100, 'resolution': 0.1, 'updateinterval': 120 },
/* S10 */ { 'id': 'wind_deg', 'sensortype': 19, 'usage': 2, 'group': 0, 'hardwarename': 'Windrichtung', 'min': 0, 'max': 360, 'resolution': 1, 'updateinterval': 120 },
/* S11 */ { 'id': 'wind_deg_avg', 'sensortype': 19, 'usage': 0, 'group': 0, 'hardwarename': 'Windrichtung AVG', 'min': 0, 'max': 360, 'resolution': 1, 'updateinterval': 120 },
/* S12 */ { 'id': 't_inside', 'sensortype': 1, 'usage': 1, 'group': 0, 'hardwarename': 'Innentemperatur', 'min': 0, 'max': 100, 'resolution': 0.1, 'updateinterval': 120 },
/* S13 */ { 'id': 'm_inside', 'sensortype': 2, 'usage': 1, 'group': 0, 'hardwarename': 'Innenfeuchte', 'min': 0, 'max': 100, 'resolution': 1, 'updateinterval': 120 },
/* S14 */ { 'id': 'p_absolute', 'sensortype': 18, 'usage': 0, 'group': 0, 'hardwarename': 'Luftdruck absolut', 'min': 0, 'max': 1200, 'resolution': 0.1, 'updateinterval': 120 },
/* S15 */ { 'id': 'p_relative', 'sensortype': 18, 'usage': 1, 'group': 0, 'hardwarename': 'Luftdruck relative', 'min': 0, 'max': 1200, 'resolution': 0.1, 'updateinterval': 120 },
]
}
and the adapted script
function updateweatherstation()
{
try {
var i=0
// Wetterstation liefert aktuell 7 verschiedenen Listen.
// leider habe ich nicht heraus gefunden, wie ich über diese iterieren kann
// weswegen ich über jede einzelne iterieren
// -------- common_list --------------------------
log('common_list')
i=0
while (i < elements(wittboy.common_list)) {
log('common_list: [' + i + '] id=' + wittboy.common_list[i].id)
if (wittboy.common_list[i].id == '0x02'){message({'id': 't_outside', 'value': number(wittboy.common_list[i].val), "message": "sensor", 'tag':'GW2000'})}
if (wittboy.common_list[i].id == '0x07'){message({'id': 'm_outside', 'value': number(substr(wittboy.common_list[i].val,0,strlen(wittboy.common_list[i].val) - 1)), "message": "sensor", 'tag':'GW2000'})}
if (wittboy.common_list[i].id == '3' ){message({'id': 'windchill', 'value': number(wittboy.common_list[i].val), "message": "sensor", 'tag':'GW2000'})}
if (wittboy.common_list[i].id == '5' ){message({'id': 'vpd', 'value': number(substr(wittboy.common_list[i].val,0,strlen(wittboy.common_list[i].val) - 4))*10, "message": "sensor", 'tag':'GW2000'})}
if (wittboy.common_list[i].id == '0x03'){message({'id': 'dew_point', 'value': number(wittboy.common_list[i].val), "message": "sensor", 'tag':'GW2000'})}
if (wittboy.common_list[i].id == '0x0B'){
while (elements(WindSpeedSampleSet)>=numWindSpeedSamples) {
// zuviele Samples belegt, älteste löschen
unset WindSpeedSampleSet[0]
}
// Neues Sample aufnehmen
WindSpeedSampleSet[elements(WindSpeedSampleSet)] = number(substr(wittboy.common_list[i].val,0,strlen(wittboy.common_list[i].val) - 4))
// Durchschnitt aller Samples berechnen
var n = 0;
var avg = 0;
while (n<elements(WindSpeedSampleSet)) {
avg = avg + WindSpeedSampleSet[n]
n++
}
//Windspeed + 10 Minuten Durchschnitt
avg = avg / n
log('AVG: ' + avg)
log('AVG_Elements: ' + elements(WindSpeedSampleSet) )
log(WindSpeedSampleSet)
message({'id': 'wind_speed', 'value': number(substr(wittboy.common_list[i].val,0,strlen(wittboy.common_list[i].val) - 4)), "message": "sensor", 'tag':'GW2000'})
message({'id': 'wind_max', 'value': avg, "message": "sensor", 'tag':'GW2000'})
}
if (wittboy.common_list[i].id == '0x0C'){message({'id': 'wind_gust', 'value': number(substr(wittboy.common_list[i].val,0,strlen(wittboy.common_list[i].val) - 4)), "message": "sensor", 'tag':'GW2000'})}
if (wittboy.common_list[i].id == '0x19'){log('MaxTagesSpeed: ' + number(substr(wittboy.common_list[i].val,0,strlen(wittboy.common_list[i].val) - 4)) + ' -> in DSS nicht existent')}
if (wittboy.common_list[i].id == '0x15'){message({'id': 'solar', 'value': number(substr(wittboy.common_list[i].val,0,strlen(wittboy.common_list[i].val) - 4))*1000, "message": "sensor", 'tag':'GW2000'}) i++}
if (wittboy.common_list[i].id == '0x17'){message({'id': 'uv_index', 'value': number(wittboy.common_list[i].val), "message": "sensor", 'tag':'GW2000'}) i++}
if (wittboy.common_list[i].id == '0x0A'){message({'id': 'wind_deg', 'value': number(wittboy.common_list[i].val), "message": "sensor", 'tag':'GW2000'}) i++}
if (wittboy.common_list[i].id == '0x6D'){message({'id': 'wind_deg_avg', 'value': number(wittboy.common_list[i].val), "message": "sensor", 'tag':'GW2000'}) i++}
i++
}
// -------- wh25 --------------------------
log('wh25')
i=0
if (isvalid(wittboy.common_list[i].id)){
message({'id': 't_inside', 'value': number(wittboy.wh25[i].intemp), "message": "sensor", 'tag':'GW2000'})
message({'id': 'm_inside', 'value': number(substr(wittboy.wh25[i].inhumi,0,strlen(wittboy.wh25[i].inhumi) - 1)), "message": "sensor", 'tag':'GW2000'})
message({'id': 'p_absolute', 'value': number(wittboy.wh25[i].abs), "message": "sensor", 'tag':'GW2000'})
message({'id': 'p_relative', 'value': number(wittboy.wh25[i].rel), "message": "sensor", 'tag':'GW2000'})
i++
}
} catch {
return true
}
}
// Main program
glob wsignal default signal()
//var baseurl = string('http://192.168.1.155/get_livedata_info')
// Konfiguration
var numWindSpeedSamples = 10
// Implementation
var WindSpeedSampleSet // die Samples
WindSpeedSampleSet = [ ] // anfangs leer
on (wsignal) as wittboy {
// process the part of the wittboy json your're interested in this device
updateweatherstation()
}
/*
// Alle 180 Sekunden
on (every(60)) {
// Wetter einlesen
updateweatherstation()
}
*/
return true // es ist ok, dass das Script hier endet
Also the 'globalInputs are sligly changed
{
'message': 'init',
'protocol': 'json',
'name': 'GlobalInputs', /* initialer Name */
/* Definition der Wetter-Sensoren */
'inputs': [
/* S0 */ { 'id': 'srain_piezo', 'inputtype': 9, 'usage': 2, 'hardwarename': 'Regen', 'updateinterval': 120 },
]
}
Script:
function UpdateGlobalInputs()
{
try {
log('piezoRain')
log (wittboy.piezorain)
log ('aktueller Wert: ' + wittboy.piezorain[0].val)
var msg = {'message':'input', 'index':0 }
msg.value = if(wittboy.piezorain[0].val>0, 1, 0)
log(msg)
message(msg)
} catch {
log("Error in UpdateGlobalInputs: ")
}
}
// Main program
glob wsignal default signal()
on (wsignal) as wittboy {
// process the part of the wittboy json your're interested in this device
UpdateGlobalInputs()
}
return true
and the last for now is
{
'message': 'init',
'tag' : 'GW2000_Moist',
'protocol': 'json',
'group': 8, /* Joker */
'name': 'Bodenfeuchten', /* initialer Name */
/* Definition der Wetter-Sensoren */
'sensors': [
/* S0 */ { 'id': 'soil_00', 'sensortype': 2, 'usage': 2, 'group': 0, 'hardwarename': 'Hochbeet', 'min': 0, 'max': 100, 'resolution': 1,'updateinterval': 120 },
/* S1 */ { 'id': 'soil_01', 'sensortype': 2, 'usage': 2, 'group': 0, 'hardwarename': 'soil_01', 'min': 0, 'max': 100, 'resolution': 1,'updateinterval': 120 },
/* S2 */ { 'id': 'soil_02', 'sensortype': 2, 'usage': 2, 'group': 0, 'hardwarename': 'soil_02', 'min': 0, 'max': 100, 'resolution': 1,'updateinterval': 120 },
/* S3 */ { 'id': 'soil_03', 'sensortype': 2, 'usage': 2, 'group': 0, 'hardwarename': 'soil_03', 'min': 0, 'max': 100, 'resolution': 1,'updateinterval': 120 },
/* S4 */ { 'id': 'soil_04', 'sensortype': 2, 'usage': 2, 'group': 0, 'hardwarename': 'soil_04', 'min': 0, 'max': 100, 'resolution': 1,'updateinterval': 120 },
/* S5 */ { 'id': 'soil_05', 'sensortype': 2, 'usage': 2, 'group': 0, 'hardwarename': 'soil_05', 'min': 0, 'max': 100, 'resolution': 1,'updateinterval': 120 },
/* S6 */ { 'id': 'soil_06', 'sensortype': 2, 'usage': 2, 'group': 0, 'hardwarename': 'soil_06', 'min': 0, 'max': 100, 'resolution': 1,'updateinterval': 120 },
/* S7 */ { 'id': 'soil_07', 'sensortype': 2, 'usage': 2, 'group': 0, 'hardwarename': 'soil_07', 'min': 0, 'max': 100, 'resolution': 1,'updateinterval': 120 },
/* S8 */ { 'id': 'soil_08', 'sensortype': 2, 'usage': 2, 'group': 0, 'hardwarename': 'soil_08', 'min': 0, 'max': 100, 'resolution': 1,'updateinterval': 120 },
/* S9 */ { 'id': 'soil_09', 'sensortype': 2, 'usage': 2, 'group': 0, 'hardwarename': 'soil_09', 'min': 0, 'max': 100, 'resolution': 1,'updateinterval': 120 },
/* S10 */ { 'id': 'soil_10', 'sensortype': 2, 'usage': 2, 'group': 0, 'hardwarename': 'soil_10', 'min': 0, 'max': 100, 'resolution': 1,'updateinterval': 120 },
/* S11 */ { 'id': 'soil_11', 'sensortype': 2, 'usage': 2, 'group': 0, 'hardwarename': 'soil_11', 'min': 0, 'max': 100, 'resolution': 1,'updateinterval': 120 },
/* S12 */ { 'id': 'soil_12', 'sensortype': 2, 'usage': 2, 'group': 0, 'hardwarename': 'soil_12', 'min': 0, 'max': 100, 'resolution': 1,'updateinterval': 120 },
/* S13 */ { 'id': 'soil_13', 'sensortype': 2, 'usage': 2, 'group': 0, 'hardwarename': 'soil_13', 'min': 0, 'max': 100, 'resolution': 1,'updateinterval': 120 },
/* S14 */ { 'id': 'soil_14', 'sensortype': 2, 'usage': 2, 'group': 0, 'hardwarename': 'soil_14', 'min': 0, 'max': 100, 'resolution': 1,'updateinterval': 120 },
/* S15 */ { 'id': 'soil_15', 'sensortype': 2, 'usage': 2, 'group': 0, 'hardwarename': 'soil_15', 'min': 0, 'max': 100, 'resolution': 1,'updateinterval': 120 },
]
}
with script
function updatebodenfeuchte()
{
try {
var soillist = wittboy.ch_soil
var i=0
// -------- soil_list --------------------------
log('soil_list')
// log (soillist)
//log (elements(soillist))
i=0
while (i < elements(soillist)) {
if (isvalid(soillist[i].humidity)){message({'id': format('soil_%.2d', i), 'value': number(substr(soillist[i].humidity,0,strlen(soillist[i].humidity) - 1)), "message": "sensor", 'tag':'GW2000_Moist'})}
i++
}
}
catch {
log ('Failed Soil')
return true
}
}
// Main program
glob wsignal default signal()
on (wsignal) as wittboy {
// process the part of the wittboy json your're interested in this device
updatebodenfeuchte()
}
return true