Contact vs Switch items?

items
Tags: #<Tag:0x00007f51ea8c44a0>

(Paul Hansen) #1

ELI5 why I would want to use a Contact instead of a Switch?

I understand that the Contact is Open/Close and the Switch is On/Off, but do rules behave differently for one or the other? Or is it a semantics thing, purely to differentiate the two physical approaches?


Integrate Siemens Logo (plclogo) in OpenHAB 2
(Andy Swing) #2

A contact is more or less just a read-only version of a switch.


(Rich Koshak) #3

To elaborate on @andy_swing’s answer, the primary difference is that a Contact represents the state of a binary sensor. One cannot command a sensor, otherwise it wouldn’t be a sensor. A Switch represents the state of an actuator. An actuator is something you send a command to switch between binary states.

So use a Contact to represent a sensor or some state akin to a sensor (i.e. representing a binary state of something) and use a Switch to represent an actuator (i.e. something where it makes sense to send an ON or OFF command to).

Contacts are often used to represent the state of doors and windows, hence the OPEN/CLOSED states.


(Paul Hansen) #4

Thanks @andy_swing and @rlkoshak, makes sense.

I’m just working through updating some presence rules and adding some PIR sensors to my groups so I can be notified of movement if we aren’t home. I had planned to use switches for these, but perhaps Contacts might be a better idea.


(Craig) #5

If I may chime in here with an example of one possible use case for a contact instead of a switch.

To turn on a light at sunset, the Astro Binding sends a sunset_start update of ‘ON’ trigger to the bus, and then immediately switches it to off again. If I want to set a rule based on something to happen only when it is dark then I could create a virtual contact which is set to ‘open’ if it’s dark and ‘closed’ when sunrise receives the '‘on’ trigger. So I could test against that condition based on the state of the contact at any time.

A switch item here would not make sense because if it’s dark it’s dark, there should be no option to change it manually.

To clean it up you could use a mapping (open=‘dark’, closed=‘light’) or something like that.

Now I’m not sure if that is the best way to determine whether it is dark or light, but I hope helps


(Rich Koshak) #6

Just to be clear to future readers, this is the behavior of the 1.9 version Astro Binding. The 2.0 version binding uses Event Trigger Channels to trigger rules.

Conceptually I agree. However, there is unfortunately nothing preventing you from postUpdating to change a Contact or from just checking and simply refraining from sendCommand to the Switch.

As for the best way, I recommend this which can be expanded to any number of time periods over a day and can be expanded to handle changes based on day type (e.g. weekends use different time periods from work days).