calculations in rules

Hi

Can I ask you a question about rules, data from HTTP and calculations?

In
openremote I have some rules with using data and making calculations. Als some rules about retreiving data via an HTTP API request and putting
it in a log. The rules with calculations are working with data from my Velbus system. Now I want to make a new other rule to use data from an API request. But there is a problem

I have trouble with the rule below. Everything works, except for the last two rules.

With this request command :
$.daily.data[0].precipIntensity

I get 0.0686 from this api file:

---- section from JSON api request—

daily

summary
“De hele week lichte regen met temperaturen stijgend tot 11°C op zaterdag.”
icon
“rain”
data

0

time
1549234800
summary
“Zwaar bewolkt gedurende de dag.”
icon
“cloudy”
sunriseTime
1549264639
sunsetTime
1549298135
moonPhase
0.99
precipIntensity
0.0686

You are printing floats using string format. Strange that it even works with tKB* sensors. Anyway, try to use the float format, %f instead of %s and tell how it goes.

Kind regards,
Michal Rutka

Hi

Thank Michal. I changed the %s into an %f.

But it did not change anything what i can see in the result.

Below the rule and the result in Drools.log. Only the first working part is visuable in the log. Not the last to sentences.

Any ideas?

Thank you

Richard

rule “B2 Bewatering – doorschuiven gevallen regen per dag en invullen vandaag”
timer (cron:2 31 3 * * ?)
when
Event( source == “035_04_EST_SE_WATERSYSMETHTTPSW”, value == “on” )
CustomState (source == “035_04_ESE_REGENA”, $tKB01 : value);
CustomState (source == “035_04_ESE_REGENB”, $tKB03 : value);
CustomState (source == “035_04_ESE_HTTP_VANDAAGREGEN”, $tKB05 : value);
then
double correctedValueKB04 = Double.parseDouble($tKB03.toString());
execute.command(“035_04_EC_REGENC”,String.format("%f",correctedValueKB04));
double correctedValueKB02 = Double.parseDouble($tKB01.toString());
execute.command(“035_04_EC_REGENB”,String.format("%f",correctedValueKB02));
double correctedValueKB06 = Double.parseDouble($tKB05.toString());
execute.command(“035_04_EC_REGENA”,String.format("%f",correctedValueKB06));
double correctedValueKB07 = (correctedValueKB02 + correctedValueKB04 + correctedValueKB06);
execute.command(“035_04_EC_REGENSOM”,String.format("%f",correctedValueKB07));
end

DEBUG 2019-02-05 10:01:20,801 (Drools): rule “B2 Bewatering – doorschuiven gevallen regen per dag en invullen vandaag” // (package org.openremote.controller.model.event)
Declarations
Declaration: “$tKB01: 0.015200”
Declaration: “$tKB03: 0.0584”
Declaration: “$tKB05: 0.0152”
LHS objects(antecedents)
Class: “Switch”
Fields:
Event Name: “035_04_EST_SE_WATERSYSMETHTTPSW”
Event Value: “on”
Class: “CustomState”
Fields:
Event Name: “035_04_ESE_REGENA”
Event Value: “0.015200”
Class: “CustomState”
Fields:
Event Name: “035_04_ESE_REGENB”
Event Value: “0.0584”
Class: “CustomState”
Fields:
Event Name: “035_04_ESE_HTTP_VANDAAGREGEN”
Event Value: “0.0152”

scratch that. it seems to work now. I’ll try some stuff, but it seems good now.

Thank you Michal again for your help!