[SOLVED] Habpanel button update

I need help, i can’t change the buttons status on my habpanel, with this rule:

rule "update tapparelle button status"

when

     Item tapparelle_notte received update 
	 
then 

     if (tapparella_notte.state==OFF){
	   tapparella_camera.postUpdate(OFF)
	   tapparella_bagno.postUpdate(OFF)
	 }
	 else{
	   tapparella_camera.postUpdate(ON)
	   tapparella_bagno.postUpdate(ON)
	 }
	 
	 end

thanks
Davide

I’m not really sure that this has anything to do with the status of the buttons on habpanel. The rule seems fine to me at a first glance.
Could you elaborate some more on what is going wrong according to you? Do these two items change according to your events.log?

I was on the wrong path. The item I am interested in monitoring is mqttSonoff5_2.
When it receives a numeric value == 100 it updates the status of the buttons to OFF
For all other numbers from 0 to 99 it updates the status of the buttons to ON.
I tried to write this rule:

rule "update shutters button status"

When

      Item mqttSonoff5_2 received command

then

      if ((receivedCommand as Number)! = 100) {
tapparella_bagno.postUpdate (ON)
tapparelle_tutte.postUpdate (ON)
tapparelle_notte.postUpdate (ON)
}
if ((receivedCommand as Number) == 100) {
tapparella_bagno.postUpdate (OFF)
tapparelle_notte.postUpdate (OFF)
}

end

but it gives me an error (could not CAST …) and it doesn’t work

This one is rather subtle, but you should remove the space between the ! and the = in this line:

if ((receivedCommand as Number)! = 100) {

to make it like this:

if ((receivedCommand as Number) != 100) {

In general, make sure you never have a space in a combined operator (like <=, >=, !=).
! by itself is also an operator, the NOT operator (so !true == false). For that operator to work, the command it works on ((receivedCommand as Number) in this case), should be a boolean, or should be something that can be casted to boolean, which is not the case for a Number.

1 Like

I’m on the right way. Now the Button State update it’s status, but only ON. But if the Item Sonoff 5 and Sonoff6 are at the same value 100 (the value that corresponding at the close) the button not update to OFF…why?
the rule:

rule "update tapparelle button status"

when

	Item Sonoff5  received command  or
	Item Sonoff6  received command 
		 
then 
    if(receivedCommand instanceof Number){
    if((Sonoff5.state !=100) || (Sonoff6.state !=100)){ 
	
	tapparelle_tutte.postUpdate(ON)
    }    
	 	
    if((Sonoff5.state == 100) && (Sonoff6.state == 100)){
	tapparelle_tutte.postUpdate(OFF)
	}
	}
	}
end 	
	

I suggest logging what is going on, so right after then, add:

    logInfo("SonoffTest","Sonoff5 state = " + Sonoff5.state.toString + " and Sonoff6 state = " + Sonoff6.state.toString)

Please check what that says and report back if the results still are unexpected.

from debugging I get this:

[se.smarthome.model.script.SonoffTest] - Sonoff5 state = 100 and Sonoff6 state = 89

but I gave the value 100 to both items, if later, for example, I give the value 50 to sonoff5 and 80 to the item sonoff6, then from the debug I get 100 both, but the status is changed and therefore the button remains OPEN . In practice it always gives me the previous value. If I want to get the CLOSED button I have to send the command 100 twice to the items.
I have also tried:

Sonoff5.PreviousState == 100

but nothing happens

Well at least than your rule is not doing something weird and unexplainable, it’s just the sonoffs that do that… :slight_smile:
I’m honestly not sure what causes that behaviour though. Are you interfacing with the Sonoffs via MQTT?

yes

Then I’d suggest using an MQTT monitoring tool or something alike to check what the actual states according to MQTT are, to make sure whether the issue is in the value that is being reported or in the handling of the value within either the MQTT binding or OpenHAB.

Now it works, I had to use “changed” which returns the current status. Thanks for your help

rule "update tapparelle button status"

when

	Item Sonoff5  changed  or
	Item Sonoff6  changed  or
	Item Sonoff8  changed 
		 
then
    //logInfo("SonoffTest","Sonoff5 state = " + Sonoff5.state.toString  + " and Sonoff6 state = " + Sonoff6.state.toString)          
    if((Sonoff5.state !=100) || (Sonoff6.state !=100) || (Sonoff8.state !=100)){ 	
	tapparelle_tutte.postUpdate(ON)
    }    	 	    
	if((Sonoff5.state > 98 ) && (Sonoff6.state > 98) && (Sonoff8.state > 98)){	
	tapparelle_tutte.postUpdate(OFF)
	}
	
	
end