Wallplug help with scene if consumption =< 5 wat turn off wallplug

Hi I have small problem with some scene. It doesn’t work.
The idea was that a wallplug should off when consumption go to 5 wat and less for 60 seconds
Can somebody send me correct code?

Switch	P2_Sypialnia_SzafkaNocna	"Szafka nocna"	{ zwave="72:command=switch_binary" }
Number	P2_Sypialnia_SzafkaNocna_Power	"Aktualne zuzycie energii elektrycznej [%.1f W]"	{ zwave="72:command=sensor_multilevel" }
Number	P2_Sypialnia_SzafkaNocna_Energy	"Calkowite zuzycie energii elektrycznej [%.2f KWh]"	{ zwave="72:command=meter" }
rule
when 
	Item P2_Sypialnia_SzafkaNocna_Power changed
then
	if(P2_Sypialnia_SzafkaNocna_Power.state <= 5) {
		timer_p2_sypialnia_szafkanocna = createTimer(now.plusSeconds(60)) [|
                sendCommand(P2_Sypialnia_SzafkaNocna,OFF)
            ]
	}
	else {
            if(timer_p2_sypialnia_szafkanocna!=null) {
                timer_p2_sypialnia_szafkanocna.cancel
                timer_p2_sypialnia_szafkanocna = null
            }
	}
end

You probably need to cast the state of the Power Item to a DecimalType.

if(P2_Sypialnia_SzafkaNocna_Power.state as DecimalType <= 5) {

Secondly, you only want to cancel the timer if the state is above 5. Otherwise you want to keep it running.

Unfortunately it doesn’t work. Still wallplug have not turn off when consumption go down 5 watts for 1 minute:(

Add logging so you can see better what is happening.

Error during the execution of rule ‘P2 Szafka nocna OFF < 5W’: The name ‘timer_P2_Sypialnia_SzafkaNocna’ cannot be resolved to an item or type.

my code is:

rule "P2 Szafka nocna OFF < 5W"
when
Item P2_Sypialnia_SzafkaNocna_Power changed
then
if(P2_Sypialnia_SzafkaNocna_Power.state as DecimalType < 5) {
timer_P2_Sypialnia_SzafkaNocna = createTimer(now.plusSeconds(60)) [|
sendCommand(P2_Sypialnia_SzafkaNocna,OFF)
]
}
else {
if(timer_P2_Sypialnia_SzafkaNocna!=null) {
timer_P2_Sypialnia_SzafkaNocna.cancel
timer_P2_Sypialnia_SzafkaNocna = null
}
}
end

You must declare and define your timer as a global var.

var Timer timer_P2_Sypialnia_SzafkaNocna = null

rule "P2 Szafka nocna OFF < 5w"
...

I found mistake and now it is working well. I added = sign before < sign

if(P2_Sypialnia_SzafkaNocna_Power.state as DecimalType =< 5)

rlkoshak thank you for helping me