Run command with rule on service stater to tasmota

(Didier) #1

How can i send command status 0 / status 5 using rule when the service start?

0 Likes

(Stuart Hanlon) #2

Hi

Have you read this resource?

Search for “System started”

0 Likes

(Sascha Billian) #3

And please be more specific. I’m guessing you’re talking about MQTT, but only since you are mentioning Tasmota:

1 Like

(Didier) #4

Got it.

Thanks to this https://community.openhab.org/t/using-sonoff-power-switches-with-tasmota-firmware-and-openhab2-mqtt2-binding/59969/54?u=sldm

val sonoff_device_ids = newArrayList("sonoffs")
val actions = getActions("mqtt","mqtt:broker:myMQTTBroker")

rule "Update Sonoff Status"

    Time cron "0 0 0/1 1/1 * ? *" or
	System started

then

    for (String device_id : sonoff_device_ids) {
        logDebug("sonoff.rules", "Updating Status Item for Device: " + device_id )
        actions.publishMQTT("cmnd/" + device_id + "/STATUS", "2")
        actions.publishMQTT("cmnd/" + device_id + "/STATUS", "5")
    }
    
end
1 Like