I wasn’t able to figure this out after a few hours, so I removed the 2.4 Mqtt binding and installed the 1.x legacy binding. it was very simple to get working. This was effortless and is what I had used in the past. I prefer to configure things by text and perhaps was missing something in PaperUI of the 2.4 binding.
Assumes you have installed Mosquitto already on your server. ( i used openhabian-config tool)
Got some errors with the sonoff.rules which I cannot figure out:
2019-01-06 22:15:20.699 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'sonoff.rules' has errors, therefore ignoring it: [7,36]: no viable alternative at input '“'
[7,37]: no viable alternative at input 'mqtt'
[7,48]: mismatched input ':' expecting 'end'
[14,6]: no viable alternative at input '“'
sonoff.rules
val sonoff_device_ids = newArrayList("sonoff*")
rule "Update Sonoff Status"
when
Time cron "0 0 4 1/1 * ? *" // Update twice a day at 4am
then
val actionsBroker = getActions(“mqtt”,“mqtt:broker:mosB”)
for (String device_id : sonoff_device_ids) {
actionsBroker.publishMQTT( “cmnd/” + device_id + “/status”, “2”)
logInfo("sonoff.rules", "Updating FW Item for Device: " + device_id )
}
end
rule “Sonoff Maintenance”
when
Item Sonoff_Action received command
then
logInfo(“sonoff.rules”, “Sonoff Maintenance on all devices: " + receivedCommand)
val actionsBroker = getActions(“mqtt”,“mqtt:broker:mosB”) // change to your broker name!
for (String device_id : sonoff_device_ids) {
switch (receivedCommand) {
case “restart” :
actionsBroker.publishMQTT( “cmnd/” + device_id + “/restart”, “1”)
case “queryFW” :
actionsBroker.publishMQTT( “cmnd/” + device_id + “/status”, “2”)
case “upgrade” : {
actionsBroker.publishMQTT( “cmnd/” + device_id +”/otaurl", “http://thehackbox.org/tasmota/release/sonoff.bin”)
actionsBroker.publishMQTT( “cmnd/” + device_id + “/upgrade”, “1”)
}
}
}
Sonoff_Action.postUpdate(NULL)
end
What would be the appropriate MQTT 2.4 version of this MQTT 1.13 item?
I guess all the errors obserrved are caused by the false “ instead of ". If you look closely at the code posted, the first string “sonoff*” is surrounded by the correct characters, the “mqtt” in line 7 NOT (more false characters to follow)!
and your item “Sonoff_Current_FW_Available” isn’t using mqtt at all! That item is using the http binding, which didn’t change at all!
? None. The http binding, which is a openhab1 binding, should be setup using the hhtp.cfg file.
You have most probably copied that item from somewhere, look there.
2019-01-07 22:09:34.581 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'sonoff.rules' has errors, therefore ignoring it: [7,36]: no viable alternative at input '“'
[7,37]: no viable alternative at input 'mqtt'
[7,48]: mismatched input ':' expecting 'end'
[14,6]: no viable alternative at input '“'
This is my sonoff.rules
val sonoff_device_ids = newArrayList("sonoffs")
rule "Update Sonoff Status"
when
Time cron "0 0 4 1/1 * ? *" // Update twice a day at 4am
then
val actionsBroker = getActions(“mqtt”,“mqtt:broker:mosB”)
for (String device_id : sonoff_device_ids) {
actionsBroker.publishMQTT( “cmnd/” + device_id + “/status”, “2”)
logInfo("sonoff.rules", "Updating FW Item for Device: " + device_id )
}
end
rule “Sonoff Maintenance”
when
Item Sonoff_Action received command
then
logInfo(“sonoff.rules”, “Sonoff Maintenance on all devices: " + receivedCommand)
val actionsBroker = getActions(“mqtt”,“mqtt:broker:mosB”)
for (String device_id : sonoff_device_ids) {
switch (receivedCommand) {
case “restart” :
actionsBroker.publishMQTT( “cmnd/” + device_id + “/restart”, “1”)
case “queryFW” :
actionsBroker.publishMQTT( “cmnd/” + device_id + “/status”, “2”)
case “upgrade” : {
actionsBroker.publishMQTT( “cmnd/” + device_id +”/otaurl", “http://thehackbox.org/tasmota/release/sonoff.bin”)
actionsBroker.publishMQTT( “cmnd/” + device_id + “/upgrade”, “1”)
}
}
}
Sonoff_Action.postUpdate(NULL)
end
2019-01-18 20:14:56.111 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Error during the execution of startup rule 'Update Sonoff Status': Instance is not an MQTTActions class.
I am using MQTT 2.4
I shifted the “val…” line to be before the rule
val sonoff_device_ids = newArrayList("sonoffs")
val actionsBroker=getActions("mqtt","mqtt:broker:mosB")
rule "Update Sonoff Status"
when
Time cron "0 0 20 * * ?" or
System started
then
for (String device_id : sonoff_device_ids) {
logDebug("sonoff.rules", "Updating FW Item for Device: " + device_id )
actionsBroker.publishMQTT("mosB", "cmnd/" + device_id + "/STATUS", "2")
}
end
Now I am getting this error.
2019-01-18 22:34:54.504 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'sonoff.rules', using it anyway:
The value of the local variable actionsBroker is not used
2019-01-18 22:34:54.557 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'sonoff.rules'
2019-01-18 22:34:59.803 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Error during the execution of startup rule 'Update Sonoff Status': Instance is not an MQTTActions class.
I guess you tired it with the “actionsBroker” declared within the rule as well.
Honestly,at the moment I have no clue.
How are your things and items defined? (if by files, please post)
Do you have mqtt binding (Ver 1) and/or mqtt Action (Ver 1) installed in your System?
Further questions:
The error about “is not an MQTTActions class” is reported very shortly after the error “in configuration model …”, which is probably raised while saving an actually incomplete file (for example during an edit).
Do you see another log entries with " Refreshing model ‘sonoff.rules’" after the last error? In this case the error would have been raised again while saving an actually incomplete file and I think the rule would be working.
Hi Jurgen,
I made sure the rule is not an incompleted save file.
I see this error again this time:
2019-01-18 22:34:59.803 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Error during the execution of startup rule 'Update Sonoff Status': Instance is not an MQTTActions class.
really scratching my head here to where the error is