Simple rule isn't working?

hello, i have made this simple rule, but it won’t work?

var int VOL

rule "test"
when
Item MQTT_command received update
then
VOL = MQTT_command.state
sendCommand(dimmer_item, VOL)
end

when i do this, it works:

var int VOL

rule "test"
when
Item MQTT_command received update
then
VOL = MQTT_command.state
sendCommand(dimmer_item, 10)
end

what is it that i do wrong?

Does this work?

var int VOL

rule "test"
when
	Item MQTT_command received update
then
	VOL = (MQTT_command.state as DecimalType).intValue
	sendCommand(dimmer_item, VOL)
end

PS: Please use the preformatted tex or blockquotes to paste code, makes it simpler to read. :wink:

nopen also try this

var int VOL

rule "test"
when
	Item MQTT_command received update
then
	VOL = (MQTT_command.state.intValue
	sendCommand(dimmer_item, VOL)
end

and this is also not working

hmmmm I testet this successfully:

var int debugInt

rule "dimmer test"
when
    Item debugDimmer_1 received update
then
    debugInt = (debugDimmer_1.state as DecimalType).intValue
    logInfo("debug Dimmer", debugInt.toString)
    sendCommand(debugDimmer_2, debugInt)
end

Maybe add some logging to see where it fails.

EDIT:

even this works:


rule "dimmer test"
when
    Item debugDimmer_1 received update
then
    debugInt = debugDimmer_1.state
    // logInfo("debug Dimemr", debugInt.toString)
    sendCommand(debugDimmer_2, debugInt)
end

please add this to your rule:
logInfo("testrule", MQTT_command.state.toString)

and show us what you get.

maybe a silly question, but where is the loginfo result goes to?

I now using mails to debug :smirk:

the problem has to be in the Item “MQTT_command” this is a string. has this state to be converted

Please, whenever possible, use the Method and not the Action :slight_smile:

dimmeritem.sendCommand(VOL)

should work at first place.

See sendCommand() Documentation for further explanation

In question of logging: All logs go to openhab.log as a default. Of course you could change this behavior.

I also tried that but notting.
In my testmails i can see that the value of VOL is changing, but the line with the “sendCommand” is not executed.

only when i send a number to the item it works, when i try to send the variable the line is not executing

edit:
when I change the “MQTT_command” item from a string to a number item it works (but it has to be a string) so i think i have to convert the contens of the VOL variable?

Sorry, missed that part. please change the var to

VOL = (MQTT_command.state as DecimalType).intValue

I also tried that, when I do that, that line isn’t executed (so there goes no value to VOL)

when I just do:

VOL = MQTT_command.state

the value is send to VOL

I have a similar rule which is working. Try this?

rule "test"
when
	Item MQTT_command received update
then
	var Number VOL = MQTT_command.state as DecimalType
	sendCommand(dimmer_item, VOL)
end

when I change:

var Number VOL = MQTT_command.state

to:

var Number VOL = MQTT_command.state as DecimalType

that line is not getting executed anymore!?

maybe I do some wrong declaration of the variable?

now it is:

var int VOL

and this is outside the rules (global)

edit:
I just see that you do a Number declaration in the rule, I just tested that but it is also not execute that line

It may be helpful if you post the definition of your “MQTT_command” and “dimmer_item” items.