The MUSH-MACHINE: Rule triggering on mqtt values, storing and displaying it

Trigger the rule by changing the value if item_co2 with the rest api

And you are using tasmota aren’t you?

then:

Switch ventil “Entlüftung” (LR,gLight) { mqtt=">[ohbroker:cmnd/ventilator/POWER:command:*:default], <[ohbroker:stat/ventilator/POWER:state:default]" }

Yes, the switch I´m using is a sonoff TH.

According to the thread: Publishing From Rule to MQTT - #19 by therealone I now installed mqtt_action and alterd the rule as follows …
but still doesnt react.

var Timer timer

rule "Too much CO2"
when
    Item_co2 received update
then
    if (Item_CO2_.value > 700) {
        if (timer === null) {
            ventil.postUpdate("ON")   // updates an item, sending MQTT
            publish("ohbroker", "ventil", "ON") // sends MQTT command
                                                           //Item_Ventil.sendCommand(ON)                     //turn on the vent
            timer = createTimer(now.plusMinutes(10), [ |  //start and create the timer
                    Item_Ventil.sendCommand(OFF)            //end of timer action
                    timer = null                          //reset the timer
            ] )
        }
    }
end

postUpdate does NOT send the MQTT
All you need to do is: ventil.sendCommand(ON) and you don’t need to use the action

Last update of the rule after I found a typer CO2 in the code but that was just one problem, as the rule still doesnt trigger the item ventil. (i also set down the triggerlevel to 700 ppm as I dont want the sensor beeing overstressed with my breath…

I also still wonder as I tried to trigger the switch manually via mqtt-spy by topic:

cmnd/ventilator/POWER

with data “ON” which perfectly turned it on, resp. “OFF” to turn it off
hmmmm…

var Timer timer

rule "Too much CO2"
when
    Item_co2 received update
then
    if (Item_co2_.value > 700) {
        if (timer === null) {
            ventil.sendCommand(ON)
                                                          //Item_Ventil.sendCommand(ON)                     //turn on th$
            timer = createTimer(now.plusMinutes(10), [ |  //start and create the timer
                    ventil.sendCommand(OFF)               //end of timer action
                    timer = null                          //reset the timer
            ] )
        }
    }
end

item.value doesn’t exist, you need to use state:

rule "Too much CO2"
when
    Item_co2 received update
then
    val co2value = Item_co2.state as Number
    if (co2value > 700) {
        if (timer === null) {
            ventil.sendCommand(ON)
                                                          //Item_Ventil.sendCommand(ON)                     //turn on th$
            timer = createTimer(now.plusMinutes(10), [ |  //start and create the timer
                ventil.sendCommand(OFF)                   //end of timer action
                timer = null                              //reset the timer
            ] )
        }
    }
end

It seems that the command simply doesnt work at all.
Therefore I created another test rule to see if i can adress the item ventil directly by timer. The rule should toggle the switch every 3 sec

rule "Cron 3 Minuten"
when
    Time cron "0 0/5 * * * ?"
then
    ventil.sendCommand(ON)
    createTimer(now.plusSeconds(3)) [| ventil.sendCommand(OFF) ]
end

that works fine… but the rule to measure co2 and then fires the switch still wont… hmmm.

Hey!!! Sucess I got it working! Final rule as follows: :man_dancing:

var Timer timer

rule "Too much CO2"

when
    Item co2 changed
then

    if (co2.state > 1500) {
        if (timer === null) {
            ventil.sendCommand(ON)
                                                          //Item_Ventil.sendCommand(ON)                     //turn on th$
            timer = createTimer(now.plusMinutes(1), [ |  //start and create the timer
                ventil.sendCommand(OFF)                   //end of timer action
                timer = null                              //reset the timer
            ] )
        }
    }
end