[SOLVED] Rule Problem with openmqttgateway

Hello, i have a problem to create this rule:

rule "Kueche_An-Aus"

when
    Item Kueche received command
then
val actions = getActions("mqtt","mqtt:broker:ddd907c2")
val hexon = "{"value":1398XXX}"
val hexoff = "{"value":1398XXX}" 
   if (receivedCommand == ON)
   {
   actions.publishMQTT("home/OpenMQTTGateway_ESP8266_RF/commands/MQTTto433","hexon" )
}
else if (receivedCommand == OFF){
  actions.publishMQTT("home/OpenMQTTGateway_ESP8266_RF/commands/MQTTto433","hexoff" )
} 
 end

My Problem the payload is : {“value”:1398XXX}
and in this script i became this error in the log

2019-10-14 19:57:28.234 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘Kueche_An-Aus’: The name ‘value’ cannot be resolved to an item or type; line 7, column 16, length 5

When i write the Payload 1398XXX in this script, the script is working fine.
But this is a non working payload for openmqttgateway.

i hope anyone can help me
sorry for my bad english

val String hexon = '{"value":1398XXX}'
val String hexoff = '{"value":1398XXX}'

Hello, thank for your help :slight_smile: ,
but now i have follow error im OH-Log:

The value of the local variable hexon is not used

The value of the local variable hexoff is not used

2019-10-14 20:48:06.346 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model ‘kueche_anaus.rules’

Yes because they are not used
Look at your code carefully

What Vincent is telling you is that the INFO message is normal when the rule file is loaded and it finds a value declared but not used. It does not harm anything and your rule will work as intended.

I twit :slight_smile:
i have my error :slight_smile:

for openhab user with the same Problem:

this is the working Code:

And very thanks to vzorglub

rule "Kueche_An-Aus"

when
    Item Kueche received command
then
val actions = getActions("mqtt","mqtt:broker:ddd907c2")
val String hexon = '{"value":1398XXX}'
val String hexoff = '{"value":1398XXX}'
   if (receivedCommand == ON)
   {
   actions.publishMQTT("home/OpenMQTTGateway_ESP8266_RF/commands/MQTTto433", hexon )
}
else if (receivedCommand == OFF){
  actions.publishMQTT("home/OpenMQTTGateway_ESP8266_RF/commands/MQTTto433", hexoff )
} 
 end

Well done for finding the bug.
It was easy and I figured you would be able to find it yourself. Better to learn that way
You were using the names of the variables inside quotes which made them string
Being strings the system told you the variables were not used…

Thanks for your code. It would be worth tidying up a bit, especially the indents…
For example:

rule "Kueche_An-Aus"
when
    Item Kueche received command
then
    val actions = getActions("mqtt","mqtt:broker:ddd907c2")
    val String hexon = '{"value":1398XXX}'
    val String hexoff = '{"value":1398XXX}'
    if (receivedCommand == ON) {
        actions.publishMQTT("home/OpenMQTTGateway_ESP8266_RF/commands/MQTTto433", hexon )
    } else if (receivedCommand == OFF) {
        actions.publishMQTT("home/OpenMQTTGateway_ESP8266_RF/commands/MQTTto433", hexoff )
    } 
end

Neat. Easy to read.

Please tick the solution mark.

As there are only two options for the received command, you could use a ternary operator as well:

rule "Kueche_An-Aus"
when
    Item Kueche received command
then
    val actions = getActions("mqtt","mqtt:broker:ddd907c2")
    val String hexon = '{"value":1398XXX}'
    val String hexoff = '{"value":1398XXX}'
    actions.publishMQTT("home/OpenMQTTGateway_ESP8266_RF/commands/MQTTto433", if (receivedCommand == ON) hexon else hexoff)
end