[SOLVED] MCP23017 item and strange behaviour on Basic Interface

The environment:
i have latching/bistable relays and after hundred time read of this topic , i wrote the rule.

When i push for the first time the GF_Downstairs_Switch on BasicUI, the switch change his state and totally ignore the rule.
Then i repush the button , the switch don’t change his state.
At the third push the switch recognize the rule and switch TO OFF and after 1 sec. to ON.

WHY???

FILE.things

Thing mcp23017:mcp23017:chip20  "MCP23017 chip 20" [address=20,bus=1] {
        Type output_pin : output#A0 [default_state="HIGH"]

FILE.items

Switch		    GF_Downstairs_Switch 	       "Living room led switch"       <light>  	  	       (GF_Downstairs, gLight)  ["Lightning"] {channel="mcp23017:mcp23017:chip20:output#A0", autoupdate="false"}

FILE.rules

rule "pulse GF_Downstairs ON"
when
    Item GF_Downstairs_Switch received command ON 
then
    Thread::sleep(1000)
    GF_Downstairs_Switch.sendCommand(OFF)
   
end

Thanks to anyone would to help me.
Hi
Lorenzo.

OK, so presumably GF_Downstairs_Switch is supposed to work like a pushbutton, toggle some light’s state. Push-for-on, and push-for-off.

I note you’ve got autoupdate set false in your Item - that’s probably a good thing here, but only if you are getting correct feedback from the MCP23017 binding (about which I know nothing).
Bear in mind setting autoupdate false means that the Commands your rule sends get sent out by the binding but do not change the state of the Item directly.

Can you show us some event logs? I’d expect to see the Item getting updates.

I know nothing about this binding either except that there has been a lot of forum traffic talking about problems with this binding. Search to see if the problems reported match your problems here.

Video with log. i have an old usb camera, it doesn’t work anymore on debian…

The rule appear right, probably how saw @rlkoshak this binding have some issues…

My relays have double contact , first contact close 230V for the lamp, on second i would put 3 or 5 V to listen the state of relay as input on MCP23017.

Suggest for fix the binding?

Thanks
Lorenzo

OK, these are what I’d call pulse relays. You use with push-for-off, push-for-on wallswitches, yes?. And your MCP output simulates a pushswitch.

Two important things:
You have to release the pushswitch before you can push it again to change the light on/off.
The state of pushswitch, pressed or not-pressed, tells you nothing about the state of the light (why you have the extra contacts of course!)

I handle this with two separate Items, one represents the light and one represents the pushswitch.

Rough example -

Switch "myLight" <icon> {autoupdate="false" , somebinding="<extra contacts"}
Switch "myPulse"   {somebinding="output"}
rule "main light"
when
   Item myLight received command
then
   if (receivedCommand == ON && myLight.state != ON) {
      myPulse.sendCommand(ON)    // press the pushbutton
   } else if(receivedCommand == OFF && myLight.state == ON) {
      myPulse.sendCommand(ON)
   }
      // else we're already in desired state
end

rule "handle light change"
when
   Item myLight changed
then
   if (myPulse.state == ON) {
      myPulse.sendCommand(OFF)  // release the pushbutton
   }  else {
      // else unexpected, someone has pressed a real wallswitch
      // here you can take actions about manual changes
   }
end

You can instead use Expire binding on the myPulse Item to release it
expire=“1s, command=OFF”
but I prefer the rule which allows Openhab to notice people doing thngs.

I lost something during cloning…

FILE.items

Switch			GF_Downstairs_Light			   "Living room light"			  <light>			   (GF_Downstairs, gLight)                {channel="mcp23017:mcp23017:chip20:input#B0", autoupdate="false"}
Switch		        GF_Downstairs_Pulse        	       "Living room pulse"		          <pulse>  	  	       (GF_Downstairs, gPulse)  ["Lightning"]     {channel="mcp23017:mcp23017:chip20:output#A0"}
rule "main GF_Downstairs_Light"
when
	item GF_Downstairs_Light received command
then 
	if (receivedCommand == ON && GF_Downstairs_Light.state != ON) {
		GF_Downstairs_Pulse.sendCommand(ON)
	} else if(receivedCommand == OFF && GF_Downstairs_Lighe.state == ON) {
		GF_Downstairs_Pulse.sendCommand(OFF)
    }
end

rule "handle GF_Downstairs_Light change"
when
	Item GF_Downstairs_Light changed
then
	if (GF_Downstairs_Pulse.state == ON) {
		GF_Downstairs_Pulse.sendCommand(OFF)
	} else{
		
	}
end

LOG

2018-08-15 17:25:30.782 [ome.event.ItemCommandEvent] - Item 'GF_Downstairs_Light' received command ON

2018-08-15 17:25:31.327 [ome.event.ItemCommandEvent] - Item 'GF_Downstairs_Light' received command OFF

2018-08-15 17:25:32.600 [ome.event.ItemCommandEvent] - Item 'GF_Downstairs_Pulse' received command ON

2018-08-15 17:25:32.611 [vent.ItemStateChangedEvent] - GF_Downstairs_Pulse changed from NULL to ON

P.s.: expire bindings has the same behaviour from the solution used on first post.

First rule, both the pulse commands should be ON to “press the pushswitch”

EDIT - I have assumed ON makes your simulated pushswitch ‘active’, maybe the logic is inverted there as well.

yes. Pulse relays are drive from simple relays board . How you can see on FILE.things at the first post, the default state of the output_pin is “HIGH”.

rule "main GF_Downstairs_Light"
when
	item GF_Downstairs_Light received command
then 
	if (receivedCommand == ON && GF_Downstairs_Light.state != ON) {
		GF_Downstairs_Pulse.sendCommand(OFF)
	} else if(receivedCommand == OFF && GF_Downstairs_Light.state == ON) {
		GF_Downstairs_Pulse.sendCommand(ON)
    }
end

rule "handle GF_Downstairs_Light change"
when
	Item GF_Downstairs_Light changed
then
	if (GF_Downstairs_Pulse.state == OFF) {
		GF_Downstairs_Pulse.sendCommand(ON)
	} else{
		
	}
end

now work right when myPulse from ON state… with expire function…
the rules above doesn’t work.

Perhaps you don’t have expire binding installed.

Your last set of rules are a bit messed up, but you’ve got the general idea now.

Switch		    GF_Downstairs_Pulse 	       "Living room pulse"		      <pulse>  	  	       (GF_Downstairs, gPulse)  			  {channel="mcp23017:mcp23017:chip20:output#A0"}//, expire="1s, command=ON"}

work only with expires bindings/command.
when i comment expires function like code above doesn’t work anymore.

Why?

Thanks a lot
Lorenzo.

Sorry, it’s not clear to me what is working for you and what isn’t.

The ‘expire’ works like this;
The expiration time will be started or restarted every time an item receives an update or command other than the specified “expire” update/command.

In your case, if you use a rule to “un-push” your MCP output, then you don’t need to use expire at all.

I solved. Perhaps issue was on syntax

For the others ( this work on OH 2.3 and 2.4)

file.items

// pulse that control a double state relay
Switch          FF_Bedroom_Pulse               "Pulsante Luce"                <pulse>              (FF_Bedroom, gPulse)                                {channel="mcp23017:mcp23017:chip22:output#A1", expire="1s, command=OFF"} //C14 r11

//pulse that control a single state relay,  this relay control a DALI dimmerable LED driver. expire function was too slow (min 1s) for simple switch ON to OFF and reverse.

Switch          FF_ToiletMirrot_Pulse          "Pulsante Luce specchio"       <pulse>              (FF_Toilet, gPulse)                                 {channel="mcp23017:mcp23017:chip22:output#A4"} //, expire="1s, command=OFF"} //C12 R14a

file.rules


rule "pulse FF_ToiletMirrot_Pulse"
when
    Item FF_ToiletMirrot_Pulse received command ON 
then
    Thread::sleep(100)
    FF_ToiletMirrot_Pulse.sendCommand(OFF)
end

Thank you @rossko57
Bye Bye