Can you tell where is the error

Hello all.
I have a new rule that I need to implement, but it just dont work.
Values Pmon_V, Pmon_A… Pmon_K are all well updated, but the PowerAccu item is never updated :frowning:
Can you help me?

Thanks

Items:
Number PowerAccu “Acumulado Consumo Mês [%dW]”

rules:
rule “192.168.1.199 rec … Power Monitor"
when
Item PMon1_send changed
then
if (PMon1_send.state.toString.contains(“Monitor”)) {
var String[] buffer= PMon1_send.state.toString.split(”,")
var Double valor = new Double(buffer.get(4))
postUpdate(Pmon1_V,new Double(buffer.get(1)))
postUpdate(Pmon1_A,new Double(buffer.get(2)))
postUpdate(Pmon1_W,new Double(buffer.get(3)))
postUpdate(Pmon1_K,valor)

    if ( valor > (PowerAccu.state as DecimalType).intValue ) {
        postUpdate(PowerAccu,valor)
    }
     else {
         postUpdate(PowerConsDay,((PowerAccu.state as DecimalType).intValue))
         postUpdate(PowerAccu,valor)             
     }                      
} 

end

It is much easier to read code if you wrap it in code fences so the indentation and formatting is preserved.

```
code goes here
```

Has PowerAccu ever had a value? For example, does it appear as “-” on your sitemap? If so then you are probably seeing an error in your logs indicating that it can’t cast NULL to a DecimalType. Try:

if(PowerAccu.state != NULL && valor > (PowerAccu.state as DecimalType).intValue ) {

The .intValue is probably not needed but I kept it in.

Problem solved :slight_smile:
It was the NULL state of the object that was failing in the if condition.

Thanks