calculations in rules

29 views
Skip to first unread message

Richard van der Wulp

unread,
Feb 4, 2019, 9:45:41 AM2/4/19
to OpenRemote

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
time1549234800
summary"Zwaar bewolkt gedurende de dag."
icon"cloudy"
sunriseTime1549264639
sunsetTime1549298135
moonPhase0.99
precipIntensity0.0686
------
With a Custon state sensor I get that number, and put that number in other virtual memories with %s format. That works.

But when I try to sum up these numbers, it does nothing.
There is no error in boot.log, velbus.log or drools.log.
Just a zero as a result for this new virtual value.

Any suggestions on how i can calculate with these numbers in a rule?
Any help is welcome,

Thank you

Richard


Names with EC are a virtual input command
Names with (E)SE are a (virtual) sensor

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("%s",correctedValueKB04));
 double correctedValueKB02 = Double.parseDouble($tKB01.toString());
 execute.command("035_04_EC_REGENB",String.format("%s",correctedValueKB02));
 double correctedValueKB06 = Double.parseDouble($tKB05.toString());
 execute.command("035_04_EC_REGENA",String.format("%s",correctedValueKB06));
 double correctedValueKB07 = (correctedValueKB02 + correctedValueKB04 + correctedValueKB06);
 execute.command("035_04_EC_REGENSOM",String.format("%s",correctedValueKB07));
end

Michal Rutka

unread,
Feb 4, 2019, 12:46:47 PM2/4/19
to Richard van der Wulp, OpenRemote
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
--
You received this message because you are subscribed to the Google Groups "OpenRemote" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openremotecommu...@googlegroups.com.
Visit this group at https://groups.google.com/group/openremotecommunity.
To view this discussion on the web visit https://groups.google.com/d/msgid/openremotecommunity/1edd77a4-cc72-47ef-84a3-3fbec7f429cd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Richard van der Wulp

unread,
Feb 5, 2019, 5:40:11 AM2/5/19
to OpenRemote

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"



Op maandag 4 februari 2019 18:46:47 UTC+1 schreef Michal Rutka:
To unsubscribe from this group and stop receiving emails from it, send an email to openremotecommunity+unsub...@googlegroups.com.

Richard van der Wulp

unread,
Feb 5, 2019, 5:57:20 AM2/5/19
to OpenRemote
scratch that. it seems to work now. I'll try some stuff, but it seems good now.
Thank you Michal again for your help!

Op dinsdag 5 februari 2019 11:40:11 UTC+1 schreef Richard van der Wulp:
Reply all
Reply to author
Forward
0 new messages