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.
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.
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.
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.
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.
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.
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.
// 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