Reverse an Iris contact sensor

@anon36505037 Thank you so much for that help!! So I am just reversing those in the device handler code. Amazing, I didn’t think it would be that easy. Thank you all so much!!

@Wtstreetglow - Just to be clear the above code change is only reversing the display of the device, not the value. So if this is being used in a routine for something it will still work as a stock device. Is that the intent?

Well, my plans were to soon set up something that would send myself a text message when the door is opened. The magnet comes closer to the sensor when the door is opened and is why I really would like to have everything work in an inverse fashion.

As I understand, now my visual displays in the app will be correct. But are you saying the routines that rely on the state of the device will still be backwards in my situation?

I think I am following you but not completely sure…

Yes…that code changes the label but the “state” of the device is still the same. So your routines will still work exactly as if you didn’t make a change. What you are asking, I believe, is to reverse the state of the device. So when its “open” the device itself thinks its “closed” and vice versa. Still doable in the device handler but a little more complicated.

I would as others mentioned use a virtual device, when your device opens the virtual gets commanded closed and when it closes the virtual gets commanded open. Then use the virtual in your routines.

With that said can’t you use a custom routine in Smart Home Monitor to do what you want? You can say “When xxxx door opens send a alert”. It works on open or closed.

2 Likes

@vseven Yes, what you are saying is what I am wanting to do. Not just invert the status. I am actually wanting the reverse the state of the device…

Can you all help me with that?

Try this, set the sensor to control a virtual switch, and the switch control a virtual open / close sensor that can reverse the operation.

Before you go through the work to do this what exactly do you want to happen? Get a alert when a door opens? If so you can do that with no modifications to anything. Or am I missing something?

I would just use webCoRE and make the rule accordingly…

If open then this
If close then that

Truthfully, I use webCoRE for most of things now…

If its a simple as “If door open send alert” why would you not use a custom rule in Smart Home Monitor that runs locally? I know SHM custom rules have limitations but for something this simple it makes sense. Unless like I said I’m missing something the OP is trying to do.

1 Like

@vseven I like simple. Is smart home monitor a smartapp? Also, can it handle the fact that even though the sensor is reporting the state closed, the door is actually open and vice versa?

Pretty much in my situation, the magnets get close together when the door is open, so the contact sensor is always reporting the opposite of what it really is.

So when I view the smartthings app, I would like it to display correctly but also I would like it to report state correctly just in case I use it in a routine or something that pulls the devices state to trigger something else.

I’m sorry I am new with all of this so if my explanations are no bueno. :frowning:

Smart Home Monitor is the “built-in” app, there is nothing to install. When you go into the app you sbould see it on your “dashboard” view. Click on it then the gear icon then Custom. You can make a rule to do exactly what you want, notify you when a door opens or closes or anything else in the house happens.

1 Like

@vseven Oh lord, I didn’t even know that was a built in feature. Awesome. So will it always tell me the opposite state though? (The way it is now…)

And if I change just the view attribute in the code as stated by a user above, is that the direction I should go? Or should I go the virtual switch direction?

A lot of this is very new to me.

@vseven I think I see now. Setup the virtual device and then reference the virtual device in the alert routine?

I’m saying I don’t know why you need to setup a virtual device at all. Just setup the alert how you want (open or closed…what its actually reporting) and be done.

@vseven it’s reporting the opposite of what it is actually physically doing though because of the way I have had to put the sensors on the door.

So we’re back to before. You can either modify the device handler and reverse the state within the handler, get a virtual device that you command to be the oppposite, or just set up smart home monitor to be what you want to alert on. If you want to alert when it says open then alert when it says open.

@vseven
1.) So you’re saying reverse the actual state. Not just the label as was described earlier.
2.) Create a virtual device

Then setup Home Monitor for alerting after one of the above has been done.

Is this correct?

1 Like

Yeah that’d work for what you’ve described.

I have a question about battery use though if the contact sensor is setup in this way.

I believe these door/window sensors are all normally open switches. When the magnet moves away, the switch closes and an event is generated. To the user it’s the “opening” of a door.

If you position the sensor and magnet farther away so that the switch is closed most of the time, isn’t it going to drain the battery with constant events?

No, it should only report on state change and occasionally to check in.

And I’m saying if you want to do this “right” then you have to modify the actual open/closed state of the device since:

A) “Open” isn’t actually open, either is "closed"
B) The label will then take care of itself
C) No Virtual device will be required

I can make the change later tonight…should be a 2 minute fix.

Me, personally, I would think of this as two different objects: the door is open when the sensor is closed, and vice versa. Then create either a virtual switch or a virtual sensor to represent the door. And have the state change on the sensor push the change to the virtual device.

@marktheknife , you’re probably thinking of some of the leak sensors that people have tried to use for reporting when a Christmas tree container goes dry. Those can run down the battery because of the way they work. But that won’t happen with the regular open/close sensor as @vseven explained: they just report on the state change. :sunglasses: