MQTT Problem Tablet Display ON

Hello,

I have a problem with one of my rules and I try to turn my tablet-display “ON” via MQTT. The switch works without problems when I run it from the mobile phone app. The display turns on normally, but the rule does not work.

I have created the following rule (“off” work, “on” dont work)

rule "Tablet automatisch einschalten"
when
	Item kue_motion changed to ON
then
	if (kue_tab_display.state == OFF && nog_tag.state == ON)
	sendCommand(kue_tab_display, ON)
	logInfo("Tablet.anschalten", "Tablet wurde eingeschaltet")
end

rule "Tablet automatisch ausschalten"
when
	Item kue_motion changed to OFF
then
	if (kue_tab_display.state == ON)
	sendCommand(kue_tab_display, OFF)
	logInfo("Tablet.anschalten", "Tablet wurde ausgeschaltet")
end
Switch    kue_motion                "Motion Status"                             <multisensormobile> (gKue)                              {channel="mihome:sensor_motion:78xxxxxxxxxxx0:158xxxxxxxxxxxb:motion"}
Switch    kue_tab_display          "Tablet Display an"                                              (gKue)                              {mqtt=">[broker:cmnd/status/display/tablet:command:*:default], <[broker:tele/status/display/tablet:state:default]"}

thanks for help :slight_smile:

What’s nog_tag?

Do you see the logInfo line “Tablet wurde eingeschaltet”?
Do you see the MQTT message to switch on the tablet display?

I would use one rule to do that:

rule "Tablet ein- und ausschalten"
when
    Item kue_motion changed
then
    if (kue_motion.state != kue_tab_display.state)
        kue_tab_display.sendCommand(kue_motion.state)
    logInfo("tablet","Tablet wurde {}geschaltet",if(kue_motion.state == OFF) "aus" else "ein")
end

This one is very short but would not take account of nog_tag. This one will:

rule "Tablet ein- und ausschalten"
when
    Item kue_motion changed
then
    if (kue_motion.state != kue_tab_display.state) {
        if (kue_motion.state == OFF) {
            kue_tab_display.sendCommand(OFF)
            logInfo("tablet","Tablet wurde ausgeschaltet")
        }
        else if(nog_tag.state == ON) {
            kue_tab_display.sendCommand(ON)
            logInfo("tablet","Tablet wurde eingeschaltet")
        }
    }
end

I used the method item.sendCommand(value) as this should always be preferred over the action.

Thanks for the Answer. I would test it later at Home.

nog_tag is a Switch for my presence at Home. I want that the rule is only active when I’m at home.

No, I do not see any entries from the ON rule in logs or action from mqtt, only from the OFF rule.

Tablet MQTT Client get also only the „OFF“-Message from the rule

So the rule is never triggered. (as there are no curly brackets after if statement, only the first command after the if statement will be affected; the logInfo should always be executed, whenever the rule is triggered.)

Do you see any log lines in events.log for the item kue_motion for the state ON?

thanks for response

it works now. nog_tag is an item for my Gigaset BLE day. The rule is to activate the tablet display only when I’m at home.

rule "Tablet ein- und ausschalten"
when
    Item kue_motion changed
then
    if (kue_motion.state != kue_tab_display.state && nog_tag.state == ON) {
        if (kue_motion.state == OFF) {
            kue_tab_display.sendCommand(OFF)
            logInfo("tablet","Tablet wurde ausgeschaltet")
        }
        else if(kue_motion.state == ON) {
            kue_tab_display.sendCommand(ON)
            logInfo("tablet","Tablet wurde eingeschaltet")
        }
    }
end

big thanks

Please be aware that this rule would not switch the display off if presence state is already OFF. If this is ok for you, you could use the first rule and simply add the nog_tag.state as in your actual rule…

Thanks for the tip, but the display is otherwise automatically after 20 minutes turn off. The tablet is set to turn it off after 20 min. I’ll test this rule first, maybe I’ll correct it again.