Hi All,
I am trying to clean up my rules and I am using Visual Stude Code with the OH Extension.
I have a particular are that seems to throw an error, I think OH 2.2 may be executing the code correctly but cannoty be certain, in any case for the sake of cleanness and education I would really like to get to the bottom of why the rule is trowing errors.
rule "BR1 Humid.State"
when
Item BR1_Humid received update
then
// set initial values if undefined
if (BR1_Max_Humid.state == NULL) postUpdate(BR1_Max_Humid, Humid_Max_Init)
if (BR1_Min_Humid.state == NULL) postUpdate(BR1_Min_Humid, Humid_Min_Init)
// no errors above here
if (BR1_Humid.state < BR1_Min_Humid.state { postUpdate(BR1_Humid_State, "DRY") }
if (BR1_Humid.state < BR1_Tgt_Humid.state && BR1_Humid.state > BR1_Min_Humid.state) { postUpdate(BR1_Humid_State, "NORMAL") }
if (BR1_Humid.state > BR1_Tgt_Humid.state && BR1_Humid.state < BR1_Max_Humid.state) { postUpdate(BR1_Humid_State, "DAMP") }
if (BR1_Humid.state > BR1_Max_Humid.state) { postUpdate(BR1_Humid_State, "WET") }
// end of errors
end
The items used are defined as such:
Number BR1_Humid "Humidity [%.1f %%]" <climate> (gBR1_Humid, chartpersist) { mqtt="<[MQTT:tasmota/BR1SO1/tele/SENSOR:state:JSONPATH($.SI7021.Humidity)]" }
Number BR1_Max_Humid "Max Humidity [%d %%]" (gBR1_Humid, statepersist)
Number BR1_Tgt_Humid "Tgt Humidity [%d %%]" (gBR1_Humid, statepersist)
Number BR1_Min_Humid "Min Humidity [%d %%]" (gBR1_Humid, statepersist)
Essentially I am checking a sensor reading against a set of use set thresholds.
They are all declared as Numbers, yet I get these errors in my IDE checker.
file: 'file:///p%3A/rules/humid-states.rules'
severity: 'Error'
message: 'Type mismatch: cannot convert from DecimalType to boolean'
at: '12,6'
source: ''
code: 'org.eclipse.xtext.xbase.validation.IssueCodes.incompatible_types'
and
file: 'file:///p%3A/rules/humid-states.rules'
severity: 'Error'
message: 'The method or field intVal is undefined for the type DecimalType'
at: '12,39'
source: ''
code: 'org.eclipse.xtext.diagnostics.Diagnostic.Linking'
and still on the same line:
file: 'file:///p%3A/rules/humid-states.rules'
severity: 'Error'
message: 'missing ')' at '{''
at: '12,93'
source: ''
code: 'org.eclipse.xtext.diagnostics.Diagnostic.Syntax'
On the other erroring lines I get just the one error for each of them:
file: 'file:///p%3A/rules/humid-states.rules'
severity: 'Error'
message: 'Type mismatch: cannot convert from State to Number'
at: '13,24'
source: ''
code: 'org.eclipse.xtext.xbase.validation.IssueCodes.incompatible_types'
This is driving me nuts, the error changes when I try things but no matter what I cannot get a clean sheet.
Any help or pointers appreciated.
Paul
[EDIT] Solved by Kevinhab - Thanks.