[SOLVED] State of Homematic Item toggle at runtime

Tags: #<Tag:0x00007f616eb9aba0> #<Tag:0x00007f616eb9a8f8> #<Tag:0x00007f616eb9a790>

Dear Community,
since a couple of weeks started to configure my smart home setup. I got a lot of homematic stuff in my house (mostly switches) to controll other items. By reading my log view in the browser in order to figuring out where the problem is located I saw that the status of an homematic item ist toogleing.

For example:
In my rule I catch:

rule "LightOn"
when Item switch5_6_short changed from OFF to ON
then
exampleItem.send(ON)
end

The result will be that the Item switches from OFF to ON and a couple of seconds later the State will change from ON to OFF, without doing anything.

So in this case a changed the rule trigger to:

when Item switch5_6_short change

that was working fine for this case but did not solve my problem totally.

I bought a homematic 6 item switch in order to manage my lighting setup in the living room. The goal was to switch between different color setups with a switch case statement

rule "Lichtsteuerung EG++"
    when Item switch_wohnzimmer_5_6fach_UL_kurz changed
then

switch(colorSceneCounterKueche.toString){
        case "0":{
            logInfo("davor",colorSceneCounterBad.toString)
            LSTv_Color.send(leseLicht)
            LSKueche_Color.send(leseLicht)
            LIWohnSofa_Color.send(leseLicht)
            LSSofa_Color.send(leseLicht)
            LBWohnSchrank_Color.send(leseLicht)

            colorSceneCounterKueche=colorSceneCounterKueche + 1
            logInfo("dannach",colorSceneCounterKueche.toString)
        }
        case "1":{
            logInfo("davor",colorSceneCounterBad.toString)
            LSTv_Color.send(spaLicht1)
            LSKueche_Color.send(spaLicht2)
            LIWohnSofa_Color.send(spaLicht2)
            LSSofa_Color.send(spaLicht1)
            LBWohnSchrank_Color.send(spaLicht2)
            colorSceneCounterKueche = colorSceneCounterKueche + 1
            logInfo("dannach",colorSceneCounterKueche.toString)
        }
        case "2":{
            logInfo("davor",colorSceneCounterBad.toString)
            LSTv_Color.send(sunsetLicht1)
            LSKueche_Color.send(sunsetLicht2)
            LIWohnSofa_Color.send(sunsetLicht2)
            LSSofa_Color.send(sunsetLicht1)
            LBWohnSchrank_Color.send(sunsetLicht2)
            colorSceneCounterKueche = colorSceneCounterKueche + 1
            logInfo("dannach",colorSceneCounterKueche.toString)
        }
        case "3":{
            logInfo("davor",colorSceneCounterBad.toString)
            LSTv_Color.send(springLicht)
            LSKueche_Color.send(springLicht)
            LIWohnSofa_Color.send(springLicht)
            LSSofa_Color.send(springLicht)
            LBWohnSchrank_Color.send(springLicht)
            colorSceneCounterKueche = colorSceneCounterKueche + 1
            logInfo("dannach",colorSceneCounterKueche.toString)
        }
        case "4":{
            logInfo("davor",colorSceneCounterKueche.toString)
            LSTv_Color.send(nordLicht)
            LSKueche_Color.send(nordLicht)
            LIWohnSofa_Color.send(nordLicht)
            LSSofa_Color.send(nordLicht)
            LBWohnSchrank_Color.send(nordLicht)
            colorSceneCounterKueche = colorSceneCounterKueche + 1
            logInfo("dannach",colorSceneCounterKueche.toString)
        }
        case "5":{
            logInfo("davor",colorSceneCounterKueche.toString)
            LSTv_Color.send(tropicalLicht1)
            LSKueche_Color.send(tropicalLicht2)
            LIWohnSofa_Color.send(tropicalLicht1)
            LSSofa_Color.send(tropicalLicht2)
            LBWohnSchrank_Color.send(tropicalLicht2)
            colorSceneCounterKueche = 0
            logInfo("dannach",colorSceneCounterKueche.toString)
        }
        default:{
            logInfo("davor",colorSceneCounterKueche.toString)
            colorSceneCounterKueche=0
            LSTv_Color.send(leseLicht)
            LSKueche_Color.send(leseLicht)
            LIWohnSofa_Color.send(leseLicht)
            LSSofa_Color.send(leseLicht)
            LBWohnSchrank_Color.send(leseLicht)
            colorSceneCounterKueche = colorSceneCounterKueche + 1
            logInfo("dannach",colorSceneCounterKueche.toString)
        }
    }
end

The Problem is in this case that the Item will change his state twice and I am not able to run throw the listet states because the homematic switch jump over cases.

019-07-20 11:22:29.485 [vent.ItemStateChangedEvent] - switch_wohnzimmer_5_6fach_UL_kurz changed from OFF to ON
==> /var/log/openhab2/openhab.log <==
2019-07-20 11:22:29.497 [INFO ] [eclipse.smarthome.model.script.davor] - 5
==> /var/log/openhab2/events.log <==
2019-07-20 11:22:29.515 [ome.event.ItemCommandEvent] - Item 'LSTv_Color' received command 17,64,49
==> /var/log/openhab2/openhab.log <==
2019-07-20 11:22:29.525 [INFO ] [lipse.smarthome.model.script.dannach] - 0
==> /var/log/openhab2/events.log <==
2019-07-20 11:22:29.531 [ome.event.ItemCommandEvent] - Item 'LSKueche_Color' received command 333,35,49
2019-07-20 11:22:29.538 [ome.event.ItemCommandEvent] - Item 'LIWohnSofa_Color' received command 17,64,49
2019-07-20 11:22:29.543 [ome.event.ItemCommandEvent] - Item 'LSSofa_Color' received command 333,35,49
2019-07-20 11:22:29.552 [ome.event.ItemCommandEvent] - Item 'LBWohnSchrank_Color' received command 333,35,49
2019-07-20 11:22:29.554 [nt.ItemStatePredictedEvent] - LSTv_Color predicted to become 17,64,49
2019-07-20 11:22:29.558 [nt.ItemStatePredictedEvent] - LSKueche_Color predicted to become 333,35,49
2019-07-20 11:22:29.573 [vent.ItemStateChangedEvent] - LSTv_Color changed from 198,94,54 to 17,64,49
2019-07-20 11:22:29.589 [vent.ItemStateChangedEvent] - LSKueche_Color changed from 198,94,54 to 333,35,49
2019-07-20 11:22:29.594 [nt.ItemStatePredictedEvent] - LIWohnSofa_Color predicted to become 17,64,49
2019-07-20 11:22:29.598 [vent.ItemStateChangedEvent] - LIWohnSofa_Color changed from 197,100,54 to 17,64,49
2019-07-20 11:22:29.602 [nt.ItemStatePredictedEvent] - LSSofa_Color predicted to become 333,35,49
2019-07-20 11:22:29.605 [vent.ItemStateChangedEvent] - LSSofa_Color changed from 198,94,54 to 333,35,49
2019-07-20 11:22:29.608 [nt.ItemStatePredictedEvent] - LBWohnSchrank_Color predicted to become 333,35,49
2019-07-20 11:22:29.617 [vent.ItemStateChangedEvent] - LBWohnSchrank_Color changed from 197,100,54 to 333,35,49
2019-07-20 11:22:31.382 [vent.ItemStateChangedEvent] - LIWohnSofa_Dimmer changed from 54 to 49
2019-07-20 11:22:31.391 [vent.ItemStateChangedEvent] - LIWohnSofa_Color changed from 17,64,49 to 16,63,49
2019-07-20 11:22:31.479 [vent.ItemStateChangedEvent] - switch_wohnzimmer_5_6fach_UL_kurz changed from ON to OFF
==> /var/log/openhab2/openhab.log <==
2019-07-20 11:22:31.490 [INFO ] [eclipse.smarthome.model.script.davor] - 0
==> /var/log/openhab2/events.log <==
2019-07-20 11:22:31.496 [ome.event.ItemCommandEvent] - Item 'LSTv_Color' received command 36,75,100
2019-07-20 11:22:31.499 [ome.event.ItemCommandEvent] - Item 'LSKueche_Color' received command 36,75,100
2019-07-20 11:22:31.511 [nt.ItemStatePredictedEvent] - LSTv_Color predicted to become 36,75,100
==> /var/log/openhab2/openhab.log <==
2019-07-20 11:22:31.517 [INFO ] [lipse.smarthome.model.script.dannach] - 1```


Do I make anything wrong? Does anyone got the same issue? I thought it is a factory issue but all my items are doing the same.

Thanks for any support

Best Felix

Simply check the switch state:

rule "Lichtsteuerung EG++"
when
    Item switch_wohnzimmer_5_6fach_UL_kurz changed
then
    if(switch_wohnzimmer_5_6fach_UL_kurz.state == ON) {
        // do some stuff
    }
end

is colorSceneCounterKueche a global var?

The first parameter of logXxxx(string,string) is not meant as a normal string, but this is the name of the logger. You could switch the behavior of the logger per logger. So the correct logger command is more like that:

logInfo("lichtsteuerung","Davor: {}",colorSceneCounterBad)

or

logInfo("lichtsteuerung","Davor: " + colorSceneCounterBad.toString)

Please also notice the simplicity of printing vars :wink:

The .send() is not correct either, it’s .sendCommand()

The rule could be less complex and a bit shorter:

var Number colorSceneCounterKueche = 0

rule "Lichtsteuerung EG++"
    when Item switch_wohnzimmer_5_6fach_UL_kurz changed
then
    if(switch_wohnzimmer_5_6fach_UL_kurz.state != ON) return;

    logInfo("lichtEG","Davor: {}",colorSceneCounterKueche)
    switch(colorSceneCounterKueche){
        case 1: {
            LSTv_Color.sendCommand(spaLicht1)
            LSKueche_Color.sendCommand(spaLicht2)
            LIWohnSofa_Color.sendCommand(spaLicht2)
            LSSofa_Color.sendCommand(spaLicht1)
            LBWohnSchrank_Color.sendCommand(spaLicht2)
        }
        case 2: {
            LSTv_Color.sendCommand(sunsetLicht1)
            LSKueche_Color.sendCommand(sunsetLicht2)
            LIWohnSofa_Color.sendCommand(sunsetLicht2)
            LSSofa_Color.sendCommand(sunsetLicht1)
            LBWohnSchrank_Color.sendCommand(sunsetLicht2)
        }
        case 3: {
            LSTv_Color.sendCommand(springLicht)
            LSKueche_Color.sendCommand(springLicht)
            LIWohnSofa_Color.sendCommand(springLicht)
            LSSofa_Color.sendCommand(springLicht)
            LBWohnSchrank_Color.sendCommand(springLicht)
        }
        case 4: {
            LSTv_Color.sendCommand(nordLicht)
            LSKueche_Color.sendCommand(nordLicht)
            LIWohnSofa_Color.sendCommand(nordLicht)
            LSSofa_Color.sendCommand(nordLicht)
            LBWohnSchrank_Color.sendCommand(nordLicht)
        }
        case 5: {
            LSTv_Color.sendCommand(tropicalLicht1)
            LSKueche_Color.sendCommand(tropicalLicht2)
            LIWohnSofa_Color.sendCommand(tropicalLicht1)
            LSSofa_Color.sendCommand(tropicalLicht2)
            LBWohnSchrank_Color.sendCommand(tropicalLicht2)
        }
        default: {
            colorSceneCounterKueche = 0
            LSTv_Color.sendCommand(leseLicht)
            LSKueche_Color.sendCommand(leseLicht)
            LSSofa_Color.sendCommand(leseLicht)
            LIWohnSofa_Color.sendCommand(leseLicht)
            LBWohnSchrank_Color.sendCommand(leseLicht)
        }
    }
    colorSceneCounterKueche += 1
    logInfo("lichtEG","Danach: {}",colorSceneCounterKueche)
end

Hi @Udo_Hartmann,
thnx for your support and clean code instruction :slight_smile: the if statement solve my status toggle issue - but what I recognize is, that the homematic wireless protrocoll got an heavy delay. The time I press the button and the I see a statement in the log file of openhab is very long (1-2 seconds). I am using the CCU2 and a raspPi V3 which run the openhab.

Is this every time you press a button? When a rule is executed for the first time, it has to be compiled, so first execution of a rule might take a while. openHAB will cache the compiled code until next openHAB startup or change of rules code.

Hi @Udo_Hartmann,
you are right. This happend only be restarting the openhab system and executing for the first time. The color change is working also efficient right now.

Thnx for your support

Best Felix