Help with a simple MQTT ON OFF to SONOFF/TASMOTA (Solved)

1st attempt at SONOFF Basic Tasmota on/off but can’t get it to work in rule?
Salient Elements.


Thing says offline, but I can turn it on and off from control panel?

MQTT explorer sees the message and light goes on and off from cntl panel and console

Haven’t got a clue on sending a command. Kind of thought the whole idea behind items was to abstract the thing but the basic “sendCommand” doesn’t seem to work?

Anybody got any examples for helping me?

Solution: I was suspicious that an item was created to abstract the physical layer(thing). Indeed, that was the case. The “thing” was working correctly from the control panel and the Basic UI but I couldn’t get a rule to work. Simple, just send it a command and let the thing take care of the correct messaging!

Can you show the complete rule and items? I can not make out what your using for a trigger but you do not need mqtt actions binding to turn ON/OFF a switch.

Using EspEasy firmware but would work same as tasmota for communication:

rule "Garage Door Convert"
when
    Item ESP_Easy_Door received update
then
    if (ESP_Easy_Door.state as Number == 1){
        Garage_Door.sendCommand(ON)
        Garage_Status.postUpdate(CLOSED)
    }
    else { 
        Garage_Door.sendCommand(OFF)
        Garage_Status.postUpdate(OPEN)
    }
end


rule "Garage Door Last Updated"
    when
      Item ESP_Easy_Door changed 
    then
      Garage_update.postUpdate( new DateTimeType() )
end

Turn on/off a light using Cron job as a trigger.

rule "Smart Plug ON"

when
    Time cron "0 15 07 ? * MON,TUE,WED,THU,FRI *"
then
    Smart_Plug.sendCommand(ON)
end



rule "Smart Plug OFF"

when
    Time cron "0 30 18 ? * MON,TUE,WED,THU,FRI *"    // OFF at 6:30 Mon-Fri
then
    Smart_Plug.sendCommand(OFF)
end

Thanks for the reply, I have many rules working, it’s the use of MQTT that I’m having issues with?

If you need help with your MQTT setup please post what you have already in terms of MQTT Broker ( mosquito or the embedded one), how did you create the things and items ( using PaperUI for both or files for both or one of them/ in case of files, please post the related content), which openHAB version are you using.

Regarding the use of MQTT action in a rule , as posted by @H102 you do not need the action for the purpose you are trying to do. It doesn’t work because you are sending a “stat” message which should be posted by the device. In order to command a switch you would need a “cmnd” message to the topic " cmnd/tasmota_C19E3F/POWER" with the content “ON”.

I just noticed your reply when I was tagged by @opus. :upside_down_face: As opus mentioned be mindful of the topic used.

Here is a sonoff device with tasmota using a Thing file example:

Thing topic sonoff11 "Living Room Light" @ "Living Room" {
    Channels:
        Type switch : power       "Power"         [ stateTopic="stat/sonoff11/POWER", commandTopic="cmnd/sonoff11/POWER" ]
        Type number : temperature "Temperature"   [ stateTopic="tele/sonoff11/SENSOR", transformationPattern="JSONPATH:$.SI7021.Temperature" ]
        Type number : humidity    "Humidity"      [ stateTopic="tele/sonoff11/SENSOR", transformationPattern="JSONPATH:$.SI7021.Humidity" ]
    }

BTW it’s recommended to use PaperUI for Things and files for Items.

Item file for Thing example above:

Switch LivingRoom_Light "Living Room Light" <light>  ["Lighting"] { channel="mqtt:topic:pibroker:sonoff11:power" }
Number LivingRoom_Light_Temp "Temperature [%.1f °F]"      <temp>             { channel="mqtt:topic:pibroker:sonoff11:temperature" }
Number LivingRoom_Light_Humidity    "Humidity [%.1f %%]"    <humidity>       { channel="mqtt:topic:pibroker:sonoff11:humidity" }

Hope this helps.

Thanks, maybe I was not totally clear, my fault. I have the ability to turn on and off the thing with an mqtt message and I can use the control on the paper UI to turn it on and off. I know it is getting the correct message because the MQTT explorer is showing it. What I can’t figure out is how to send the “item” a command like on or off. There is some stuff in the docs about mqtt actions etc but don’t get that to work. Do I simple send the item a command, or must it be in the mymqtt actions format?
cds

Thanks for the info, I’m still confused. How do I send a command message to the topic. If the item is responding to both internal and external mqtt commands I confused about how the rule parts work.
My first thought was since an item is linked to a thing aka abstracted then can’t I send
"myitem.sendCommand(ON) and it translate it to a mqtt message as defined by the thing?

Or is there some special syntax for sending a mqtt message to a topic? stand alone or inside a rule?

That’s it.
An Item has no idea what kind of technology it might be linked to.
Any command sent to an Item gets passed to any channels that you might have linked to the Item.
The channel, and associated Thing “translate” the openHAB command into whatever the technology needs - here, for the MQTT binding, a topic and payload. For some other binding, a stream of hex or a packet of data…

But you just send the Item “ON” from rule or UI.

In addition to what @rossko57 posted, the mqtt action in a rule would be needed if you do NOT have a çreated channel.

Is your Generic MQTT Thing still offline?