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
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.
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
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