[SOLVED] Know lamp state from his latching relay

openhab2
mcp23017
latching-relay
Tags: #<Tag:0x00007fe058104858> #<Tag:0x00007fe0581046a0> #<Tag:0x00007fe058104538>

(Lorenzo S.) #1

I’m on openhab 2.4.0-1.

i would know the lamp state on sitemap based on second contact of his latching relay.
Schema

I’m not sure about PULL_DOWN setting ( i have read here and my case appear as PULL_DOWN ). Could anyone confirm this?

How can i change the icon lamp on sitemap from this input? ( I saw on other topics with a support contact )

This my item example
items

Switch          GF_Dining_Light                "Luce Elisse"                  <light>              (GF_Dining, gLight)                 ["Lightning"]   {channel="mcp23017:mcp23017:chip20:input#B4", autoupdate="false"}         //C1r3L5
Switch          GF_Dining_Pulse                "pulsante Luce Elisse"         <wallswitch>         (GF_Dining, gPulse)                                 {channel="mcp23017:mcp23017:chip20:output#A4"} 

without cable connected on input pin, the lamp state on sitemap should be to off.

thanks to anyone who wants to help me
Hi Lorenzo


(Lorenzo S.) #2

I have change first switch to contact, but nothing change.
Hi


(Rossko57) #3

You’re not telling us much about what your problem is.

Let’s go one step at a time.
Your Contact Item should tell you the state of the pulse relay. So poke the button on the relay to make it operate, and look for updates in the events.log

If that’s not working, you look at the hardware and biding configuration.


(Lorenzo S.) #4

sorry, I express myself badly.
I would like the light bulb icon to be off.
After switch to on when relay close circuit.

regards
Lorenzo


(Rossko57) #5

Okay, so your Contact is working? But you don’t like the icon?

copy some icon to icons/classic/ as myfunnyicon.svg or .png, whichever you use.
copy the “light bulb off” that you want to myfunnyicon-closed.svg / png

Update the Item to use <myfunnyicon>
Now when the Item is state CLOSED it will show the bulb off icon.
Otherwise it will show the other one.

Sometimes with small edits to Items, like icons, you will need to reboot the system to get it working right.


(Lorenzo S.) #6
Contact         GF_Dining_Light                "Luce Elisse"                   <myfunnyicon>        (GF_Dining, gLight)                 ["Lightning"]   {channel="mcp23017:mcp23017:chip20:input#B4"}         //C1r3L5
Switch          GF_Dining_Pulse                "pulsante Luce Elisse"          <wallswitch>         (GF_Dining, gPulse)                                 {channel="mcp23017:mcp23017:chip20:output#A4"}  // }  // , expire="1s, command=ON"}   //C1r3

I change light-off.svg to myfunnyicon.svg and light.svg to myfunnyicon-closed.svg
Result

Many thanks @rossko57, tomorrow will plug the cable to input and will test.

p.s.: after first restart some things didn’t work ( es. rule to set wallswitch to on )


(Lorenzo S.) #7

Nothing…
Icon didn’t change

Event.log

Things


Thing mcp23017:mcp23017:chip24  "MCP23017 chip 24" [address=24,bus=1] {
    Type output_pin : output#A0 [default_state="HIGH", active_low="y"]
    Type output_pin : output#A1 [default_state="HIGH", active_low="y"]
    Type output_pin : output#A2 [default_state="HIGH", active_low="y"]
    Type output_pin : output#A3 [default_state="HIGH", active_low="y"]
    Type output_pin : output#A4 [default_state="HIGH", active_low="y"]
    Type output_pin : output#A5 [default_state="HIGH", active_low="y"]
    Type output_pin : output#A6 [default_state="HIGH", active_low="y"]
    Type output_pin : output#A7 [default_state="HIGH", active_low="y"]
        
    Type input_pin : input#B0 [pull_mode="PULL_DOWN"]
    Type input_pin : input#B1 [pull_mode="PULL_DOWN"]
    Type input_pin : input#B2 [pull_mode="PULL_DOWN"]
    Type input_pin : input#B3 [pull_mode="PULL_DOWN"]
    Type input_pin : input#B4 [pull_mode="PULL_DOWN"]
    Type input_pin : input#B5 [pull_mode="PULL_DOWN"]
    Type input_pin : input#B6 [pull_mode="PULL_DOWN"]
    Type input_pin : input#B7 [pull_mode="PULL_DOWN"]
}

items

Contact         F2_LivingDining_Light          "Luce Soggiorno"             <myfunnyicon>         (F2_LivingDining, gLight)          ["Lighting"]     {channel="mcp23017:mcp23017:chip24:input#B0"} //, autoupdate="false"}   //C15r18 L29L30L31
Switch          F2_LivingDining_Pulse          "Pulsante Luce Soggiorno"    <wallswitch>         (F2_LivingDining, gPulse)                           {channel="mcp23017:mcp23017:chip24:output#A0"} 

(Rossko57) #8

Okay, so no events in the events.log for your Contact Item. Did ask about this before.

I can see your ‘pulse’ Item going on and off. Is your physical step relay clonking on and off?

Meter at the input pin on your board. Does it change when the step relay is changed?
If it does, you’ll need to look more closely at the binding. I can’t help with that.


(Lorenzo S.) #9

All output are ok. All tested

Just made, 5V arrived to input pin.


(Rossko57) #10

You’ll want it to be 0V sometimes, as well.

MCP23017 binding doc doesn’t mention anything about PULL_DOWN
Does the binding complain in openhab.log?
I don’t think you can just make this stuff up.


(Lorenzo S.) #11

You right!!!
openhab.log

Blockquote 2019-02-12 21:36:40.488 [ERROR] [ome.core.thing.link.ThingLinkManager] - Exception occurred while informing handler: This GPIO pin [GPIO B0] does not support the pull resistance specified [down]
com.pi4j.io.gpio.exception.UnsupportedPinPullResistanceException: This GPIO pin [GPIO B0] does not support the pull resistance specified [down]

I saw too much cartoons when was child :sweat_smile:
Or probably during a sweet dream i have read PULL_DOWN.

ps.: on mcp23017 binding’s page have read OFF or PULL_UP as input. OFF equals to PULL_DOWN?


(Lorenzo S.) #12

I try set input [pull_mode=“OFF”] now input flick , when contact’s relay is open i have 1 V residue.


(Rossko57) #13

Yes. That’s because you don’t have a pull-down to make it properly 0v when the external contact is open, and the wire is just floating…

Googling tells me MCP23017 chip has no pull down feature. So you still can’t make it up.
OFF in the binding means OFF, no pull-up. Absence of pull-up is NOT a pull-down, it means no pull at all.

You can either add a physical pull-down resistor to the circuit, linking the input to 0V.

Or - this is what I would do - rewire the extra contact on the step relay to 0V instead of 5V.
Enable PULL_UP in your binding configuration.

Now when you meter, you should see 5V (from the pull-up) or 0V (from the contact) and the MCP23017 should have a changing input to pass to openHAB.

Next you need to work out if Item OPEN or CLOSED means light on or off, and fix your rules and icons to suit.


(Lorenzo S.) #14

Made!!! Nice!!!

Could i simple invert name of the icons?
Last question for this evening… I promise.

Thank you so much @rossko57


(Rossko57) #15

Of course. Who cares if CLOSED means lit or dark :smiley:

I think if you plan on using rules I’ve suggested before for controlling step relays, there is going to be a problem. You cannot send commands to an openHAB Contact type Item.

I’d try creating a new Switch type Item linked to the same channel as your Contact type. I don’t know if that will work with the MCP23017 binding, let’s find out.


(Lorenzo S.) #16

Solved.
for complete resolution i attach all settings.

Final Schema

file.things

Thing mcp23017:mcp23017:chip20  "MCP23017 chip 20" [address=20,bus=1] { 
    Type output_pin : output#A0 [default_state="HIGH", active_low="y"]
    Type output_pin : output#A1 [default_state="HIGH", active_low="y"]
    Type output_pin : output#A2 [default_state="HIGH", active_low="y"]
    Type output_pin : output#A3 [default_state="HIGH", active_low="y"]
    Type output_pin : output#A4 [default_state="HIGH", active_low="y"]
    Type output_pin : output#A5 [default_state="HIGH", active_low="y"]
    Type output_pin : output#A6 [default_state="HIGH", active_low="y"]
    Type output_pin : output#A7 [default_state="HIGH", active_low="y"]
        
    Type input_pin : input#B0 [pull_mode="PULL_UP"]
    Type input_pin : input#B1 [pull_mode="PULL_UP"]
    Type input_pin : input#B2 [pull_mode="PULL_UP"]
    Type input_pin : input#B3 [pull_mode="PULL_UP"]
    Type input_pin : input#B4 [pull_mode="PULL_UP"]
    Type input_pin : input#B5 [pull_mode="PULL_UP"]
    Type input_pin : input#B6 [pull_mode="PULL_UP"]
    Type input_pin : input#B7 [pull_mode="PULL_UP"]
} 

file.items

Contact         GF_LaundryRoom_Light           "Luce Lavanderia"               <myfunnyicon>         (GF_LaundryRoom, gLight)           ["Lighting"]     {channel="mcp23017:mcp23017:chip20:input#B0"} //, autoupdate="false"} //C5r8 L13
Switch          GF_LaundryRoom_Pulse           "Pulsante Luce Lavanderia"      <wallswitch>         (GF_LaundryRoom, gPulse)                            {channel="mcp23017:mcp23017:chip20:output#A0"}

file.rules (for latching relays)

rule "Init"  //set on pulse to on after a system restart.
when
	System started
then
	//createTimer(now.plusSeconds(60)) 
	gPulse.members.filter[i|i.state==NULL].forEach[j| j.sendCommand(ON)]
	gPulsedim.members.filter[l|l.state==NULL].forEach[k| k.sendCommand(ON)]
end

rule "pulse gPulse group"  // rule for gPulse group to release the button after push
when
    Member of gPulse received command OFF	
then
	var pulseitem_name = triggeringItem
	Thread::sleep(300)
	pulseitem_name.sendCommand(ON)
end

Many Thanks to @rossko57