[SOLVED] Powerswitch/Wattage monitoring Rule don´t work

  • Platform information:
    • Hardware: RaspberryPi 4B
    • OS: Openhabian
    • Java Runtime Environment: i dont find this information
    • openHAB version: 2.5.1
  • Issue of the topic: the rule dont work

the rule :

rule “RigRX480 neustart”

Time cron “0 0/1 * * * ?” // for testing 1min (15min original)
var State = RX480X5Power.state as DecimalType
if ((RX480X5Power.state == ON) && (State < “250”)) {

 createTimer(now.plusSeconds(6), [
    if (RX480X5Switch.state == OFF) RX480X5Switch.sendCommand(ON)


  • If logs where generated please post these here using code fences:

2020-02-21 12:10:00.008 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule ‘RigRX480 neustart’: Could not cast 216.134111 W to org.eclipse.smarthome.core.library.types.DecimalType; line 5, column 15, length 33

Iam a big noob and i struggled at setting up openhab, than i struggled at setting up samba, win10 is a little *****, than i struggled at getting visual Studio to run.
As you can read i struggled nearly everywhere and i dumped a lot of time in this easy looking project.

i have defined items:
Switch RX480X5Switch “Switch” {channel=“tplinksmarthome:hs110:4DA6F1:switch”}
Number:Power RX480X5Power “Wattage” {channel=“tplinksmarthome:hs110:4DA6F1:power”}

In the Paper UI i can see the switch and the Wattage output, but i dont get the rule to work.

1 Like

not sure but i think here

it must not be …Power but … Switch:

if ((RX480X5Switch.state == ON) && (State < “250”)) {

because the switch is asked to be on?

1 Like

I changed that but the error is the same:

Error during the execution of rule ‘RigRX480 neustart’: Could not cast 213.819957 W to org.eclipse.smarthome.core.library.types.DecimalType; line 5, column 15, length 33

1 Like

Should the power be less than 250W or 250kW or 250MW … ?
When dealing with units, you cannot simply compare with an ambiguous number.

1 Like

It sure should be 250W.
Thanks for the hint, i will look for that.

Edit: How can i define the “Watt” or cancel the “Watt”?

1 Like

Maybe like this?

if ((RX480X5Power.state == ON) && (State < "250" | "W")) 

Remove the Number:Power part of the item so it does not use the UoM e.g use Number RX480X5Power “Wattage” {channel=“tplinksmarthome:hs110:4DA6F1:power”}


Okay i changed the item to Number RX480X5Power “Wattage” {channel=“tplinksmarthome:hs110:4DA6F1:power”}.
Now the Watt is gone.
So far so good but i have a new error massage.

2020-02-21 16:41:00.015 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule ‘RigRX480 neustart’: An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.lib.NumberExtensions.operator_lessThan(java.lang.Number,java.lang.Number) on instance: null

1 Like

The error means the variable has no value so try changing the rule variable from DecimalType to Number like below.

var State = RX480X5Power.state as Number

1 Like

You are the best.
Thanks a lot for helping a noob :grinning:

1 Like

Glad you got it working, :+1: and that’s what the community is here for. :wink:

1 Like

It’s dumb to discard UoM information when available.

1 Like

Why are you texting?
I have a solution that works, i am fine.

You contributed nothing to the solution and feel superior with your knowledge without helping.
Don’t you have something better to do then trolling around in a forum?

Why? Because changing the source data to fit the rule is not a good approach. I would not wish later readers to fall in the same trap. Ways to make the rule fit the original data, with units, have already been given.