Rules for Tasmota Maintenance

Good afternoon everybody,
First of all, sorry for my rusty English …
my system is as follows:
Raspberry PI3
Openhab 2.5
MQTT: mosquito
I use the binding-mqtt1 - 1.14.0 version (waiting to migrate to the binding-mqtt - 2.5.4 version)

I looked at some documentation but I just can’t get a maintenance rule for devices that use tasmota to work.
the device uses the following topic to go on power off:
openhabianpi-mqtt:tasmota/ingresso/luci/luce_ingresso/cmnd/power:command:*:default

I created, as suggested by a guide I found, the following code:

Item

String Sonoff_Action "Tasmota Action" <tasmota_basic>

sitemap

Switch item=Sonoff_Action mappings=[restart="Restart", queryFW="Query FW", upgrade="Upgrade FW"]

Rules

`val tasmota_device_ids = newArrayList(
“tasmota-A00EEA”,
//… add all your modules here!
“tasmota-E8A6E4”
)
// OR
// Work with the grouptopic, addressing ALL modules at once
//val tasmota_device_ids = newArrayList(“tasmotas”)

rule “Tasmota Maintenance”
when
Item Sonoff_Action received command
then
logInfo(“tasmota.rules”, "TasmotaMaintenance on all devices: " + receivedCommand)
for (String device_id : tasmota_device_ids) {
switch (receivedCommand) {
case “restart” :
publish(“broker”, “cmnd/” + device_id + “/restart”, “1”)
case “queryFW” :
publish(“broker”, “cmnd/” + device_id + “/status”, “2”)
case “upgrade” : {
publish(“broker”, “cmnd/” + device_id + “/otaurl”, “http://thehackbox.org/tasmota/tasmota.bin”)
publish(“broker”, “cmnd/” + device_id + “/upgrade”, “1”)
}
}
}
Sonoff_Action.postUpdate(NULL)
end`

But I can’t understand exactly how to enter the values ​​that I set in tasmota …

Could you please give me a hand?
I thank you in advance

Please use How to use code fences when posting code, logs, and config files.

It’s really helpful to link to these so we can get a better idea of what you are trying to do. There are tons of incorrect tutorials out there too.

I don’t think you can have that comment in the definition of the newArrayList. Delete that //... add all your... line.

Do you have the MQTT Action installed? It’s separately installable.

Without proper formatting I’m, not sure I can help much more.

1 Like

hank you for the answer,
sorry for the code but it is one of the first posts that I send. The MQTT action is installed [MQTT Action (1.x) action-mqtt - 1.14.0].
Regardless of the tutorial what I would like to do is send via mqtt to the device openhabianpi-mqtt:tasmota/ingresso/luci/luce_ingresso/
he restart 1 command.
I can easily create the button to insert it in the sitemap and send the command to start a rule, but I can not build the rule that contains the command …
Thanks again for the help

If your mqtt binding and mqtt action are working ( which migth not be if loaded in a false sequence) and you add your tasmota items to the above posted rule (either seperatly or via the group ) that should be all you need.

I can’t understand how to correctly enter the command MQTT publish
with the wishes of my device

rule “Tasmota Maintenance”
when
Item Sonoff_Action received command
then
logInfo(“tasmota.rules”, “TasmotaMaintenance on all devices: " + receivedCommand)
switch (receivedCommand) {
case “restart” :
publish(”{mqtt=", “>[openhabianpi-mqtt:tasmota/ingresso/luci/luce_ingresso/cmnd/”, “restart”, “1]}”)
case “queryFW” :
publish(“broker”, “cmnd/” + “/status”, " 2")
case “upgrade” : {
publish(“broker”, “cmnd/” + “/otaurl”, “http://thehackbox.org/tasmota/tasmota.bin”)
publish(“broker”, “cmnd/” + “/upgrade”, “1”)
}
}
Sonoff_Action.postUpdate(NULL)
end

Putting in random parameters won’t help; you haven’t seen that as an example anywhere.

Looks a bit better …but …
Is your broker actually named “broker”?
This is something you defined in your mqtt.cfg file, like
broker.url = xxxx

You can’t, that’s to say, in MQTT you can only publish to broker using a topic, which your remote device needs to subscribe to.
I think you are actually allowed to have a colon in your topic like
openhabianpi-mqtt:tasmota
but is that really what your tasmota device subscribes to? It’s unusual.
It’s not at all like the topics in your first post involving device-id.

I think you’ll find a tool like mqtt.fx very useful, you can ask the broker what messages it actually sees.

I just can’t get there …
In the broker.url file the value is

mosquitto.url = tcp: //192.168.1.112: 1883

But I can’t find a solution, isn’t it that you could indicate a code example for the Publish line for resetting the tasmota?

Okay, so your defined broker is named “mosquitto”
You’d use that with publish() like so -

publish("mosquitto",...

Next, you need to put the topic you want to publish to.
If I’m reading your example properly was
tasmota/ingresso/luci/luce_ingresso/cmnd/restart
so you’d put that in

publish("mosquitto", "tasmota/ingresso/luci/luce_ingresso/cmnd/restart", ...

Lastly,you’d need a payload for the topic.
Again,using your example, that would be “1” I think?

publish("mosquitto", "tasmota/ingresso/luci/luce_ingresso/cmnd/power", "1")

I have no idea if the topic and payload are correct, these things are decided by the tasmota and how you set that up.

It works perfectly !! I just couldn’t understand what to enter in the broker field! as often happens the solution was under the eyes and I didn’t see it !!
Thanks so much for the help!