Detect Button Press

Measure the voltage between the button terminals. It should go to zero when the button is pressed, assuming it's a normally open (NO) switch.

It does. Just trying to figure out what I can connect to this to detect press. Was expecting the 5V relay coil to do so and it’s not.

A picture or sketch would be incredibly helpful. Assuming you're trying to get the button press data into Hubitat, what device are you using?

A relay, or any electronic equivalent, could be placed in parallel with either the button or the load it switches. I would always prefer an electronic device in parallel with the load but physical access may dictate otherwise.

There are several devices discussed in this community, both Zigbee and Z-wave, that would serve your purpose. I don't use any (yet) so no recommendations. Searching should find those topics.

Here's one just mentioned in a topic, Fibaro FBGS-222

Long story short, I am trying to detect when the circulation button is pressed on my hot water heater controller in our bathroom. Years ago I wired a dry contact relay on either side of the button to virtually "press" the button for say when a shower light was turned on so that hot water would start circulating and my kids or us parents have a warm shower immediately. My wife has now gotten in the habit of just pressing the button on the controller manually lately and that has thrown my HE code in a loop of detecting when the circulation pump is on. So now I am on a quest to figure out how to just detect when this button is pressed physically or virtually through my dry contact relay. This would greatly simplify my app code as an added benefit.

So not sure pictures of the circuit board of this would really help, but here is what I have hooked up now:

  • Hot water controller is mounted on wall in our master bathroom
  • I soldered 2 conductor wire to both sides of the circulation button which leads down into the crawl space to a dry contact relay
  • Using the Qubino Flush 1D dry contact relay to simulate the button press
  • The Qubino also happens to have a contact sensor feature that I would like to leverage though since it is powered with 120V it has to be 120V to detect change, which is why I was attempting to go down the 5V SPDT relay route since the power on the button measures 5.9VDC. Then when the relay coil detects change, NO changes to NC and the 120V can flow through the relay.

Thanks I am trying to use a 5V SPDT relay which works great for other purposes I have hooked up to HE and a contact sensor such as my power circuit outage detector. Basically when this relay detects 5VDC via its internal coil the internal relay switch will actuate.

For whatever reason this 5V SPDT relay is not working so hoping this awesome community has other ideas to figure this out.

Okay, I think I understand. Previously, you were essentially using a relay to 'push the button'. Now, you want to detect the button being pushed.

This is a little tricky as the button is receiving 5.9VDC from the Water Heater Controller Board (WHCB). It is important to not draw too much current from from the WHCB, as we don't know how much current is 'too much'. So, we want to simply detect whether or not the 5.9vdc is present or not, as pressing the button should result in the voltage across the two button terminals going to 0VDC, correct?

The fun comes in the fact that you'll need to tie together the GNDs of the WHCB and whatever device you're using to detect the voltage change. This is so both systems have a 'common' voltage reference. You could then very easily use a simple voltage divider circuit (i.e. two resistors) to adjust the 5.9VDC down to 3.3VDC and then feed that signal into a digital input pin on an ESP8266 based board. The HubDuino sketch would need a tiny parameter adjustment to disable the internal pullup resistor, as your incoming signal would vary between 3.3VDC and 0VDC.

Not sure if the above makes sense or not... Let me know if you'd like to pursue this idea further and we can maybe work up a simple wiring diagram.

I am sure there is probably a way to make the Qubino's contact sensor feature work as well. I just am not familiar with that device at all. Crazy that it wants to see 120VAC on an input... :thinking: Using a relay to switch that 120VAC makes sense. The challenge is how to power the coil side of the relay, and then use the 5.9VDC signal as the trigger for the relay. I would advise against trying to pull the relay's coil power from the WHCB, as we don't want to draw too much current and damage the WHCB.

1 Like

@ogiewon Played around with this a little more this weekend. I had high hopes of using a water sensor on as a quick test mid week using alligator clips seemed to work but then after hooking things up in a more permanent manner it failed to report a state change.

So then I decided to try an Arduino Uno because it is easy to hook up to a computer and modify the sketch.

  • Used a voltage divider to get voltage down to around 4VDC
  • I used the digital pin first connecting the ground wire and to the positive side of the button and it kept fluctuating between high and low with and without button presses so that didn't work.
  • Then I decided to try to read the voltage hooking up the wires to both sides of the button to measure the voltage. See a sample of the serial log output below ... you can see the value fluctuates quite a bit but it does go below 1.0 when the button is pressed and sometimes reports that multiple times depending on how long the button is pressed, especially when my dry contact relay (momentary switch) is activated.

Thoughts on this? From here I can use different resistors to get voltage down to 3.3 (really 3.2 with resistors I have) and use the ESP board. Do you recommend a particular driver for Hubduino for this?

13:38:43.586 -> voltage: 2.91
13:38:43.586 -> voltage: 3.01
13:38:43.621 -> button pressed: 0.51
13:38:43.621 -> voltage: 1.20
13:38:43.655 -> button pressed: 0.94
13:38:43.689 -> voltage: 1.57
13:38:43.689 -> voltage: 1.72
13:38:43.689 -> voltage: 1.64
13:38:43.724 -> voltage: 1.39
13:38:43.724 -> voltage: 1.49
13:38:43.759 -> voltage: 1.06
13:38:43.759 -> voltage: 3.74
13:38:43.795 -> voltage: 3.33
13:38:43.795 -> voltage: 3.05
13:38:43.828 -> voltage: 2.83
13:38:43.828 -> voltage: 3.02
13:38:43.861 -> voltage: 3.28
13:38:43.861 -> voltage: 3.41
13:38:43.861 -> voltage: 3.70
13:38:43.896 -> voltage: 3.92
13:38:43.896 -> voltage: 4.33
13:38:43.930 -> voltage: 4.50
13:38:43.930 -> voltage: 4.67
13:38:43.967 -> voltage: 4.47
13:38:43.967 -> voltage: 4.27
13:38:43.967 -> voltage: 4.14
13:38:44.004 -> voltage: 3.84
13:38:44.004 -> voltage: 3.70
13:38:44.037 -> voltage: 3.19
13:38:44.037 -> voltage: 3.04
13:38:44.072 -> voltage: 2.94
13:38:44.072 -> voltage: 3.16
13:38:44.106 -> voltage: 3.33
13:38:44.106 -> voltage: 3.54
13:38:44.140 -> voltage: 3.73
13:38:44.140 -> voltage: 4.20
13:38:44.140 -> voltage: 4.26
13:38:44.176 -> voltage: 4.54
13:38:44.176 -> voltage: 4.64
13:38:44.211 -> voltage: 4.37
13:38:44.211 -> voltage: 4.26
13:38:44.245 -> voltage: 4.11
13:38:44.245 -> voltage: 3.63
13:38:44.278 -> voltage: 3.56
13:38:44.278 -> voltage: 3.28
13:38:44.311 -> voltage: 3.01
13:38:44.311 -> voltage: 3.00
13:38:44.311 -> voltage: 3.28
13:38:44.345 -> voltage: 3.41
13:38:44.345 -> voltage: 3.59
13:38:44.379 -> voltage: 3.85
13:38:44.379 -> voltage: 4.17
13:38:44.414 -> voltage: 4.12
13:38:44.414 -> voltage: 4.66
13:38:44.448 -> voltage: 4.55
13:38:44.448 -> voltage: 4.34
13:38:44.483 -> voltage: 4.23
13:38:44.483 -> voltage: 4.12
13:38:44.517 -> voltage: 3.57
13:38:44.517 -> voltage: 3.49
13:38:44.517 -> voltage: 3.14
13:38:44.555 -> voltage: 2.94
13:38:44.555 -> voltage: 3.06
13:38:44.588 -> voltage: 3.29
13:38:44.588 -> voltage: 3.43
13:38:44.621 -> voltage: 3.68
13:38:44.621 -> voltage: 3.93
13:38:44.656 -> voltage: 4.37
13:38:44.656 -> voltage: 4.49
13:38:44.656 -> voltage: 4.66
13:38:44.692 -> voltage: 4.50
13:38:44.692 -> voltage: 4.33
13:38:44.731 -> voltage: 4.16
13:38:44.731 -> voltage: 3.75
13:38:44.765 -> voltage: 3.73
13:38:44.765 -> voltage: 3.43
13:38:44.799 -> voltage: 3.05
13:38:44.799 -> voltage: 2.94
13:38:44.799 -> voltage: 3.15
13:38:44.832 -> voltage: 3.32
13:38:44.832 -> voltage: 3.47
13:38:44.866 -> voltage: 3.74
13:38:44.866 -> voltage: 4.03
13:38:44.904 -> voltage: 4.18
13:38:44.904 -> voltage: 4.61
13:38:44.938 -> voltage: 4.66
13:38:44.938 -> voltage: 4.41
13:38:44.975 -> voltage: 4.26
13:38:44.975 -> voltage: 4.13
13:38:44.975 -> voltage: 3.78
13:38:45.009 -> voltage: 3.74
13:38:45.009 -> voltage: 3.27
13:38:45.043 -> voltage: 2.99
13:38:45.043 -> voltage: 3.05
13:38:45.076 -> voltage: 3.24
13:38:45.076 -> voltage: 3.39
13:38:45.110 -> voltage: 3.57
13:38:45.110 -> voltage: 3.85
13:38:45.110 -> voltage: 1.35
13:38:45.144 -> voltage: 1.54
13:38:45.144 -> voltage: 1.78
13:38:45.178 -> voltage: 1.88
13:38:45.178 -> voltage: 1.48
13:38:45.211 -> voltage: 1.36
13:38:45.211 -> voltage: 1.17
13:38:45.245 -> button pressed: 0.87
13:38:45.245 -> voltage: 1.34
13:38:45.278 -> voltage: 1.80
13:38:45.278 -> voltage: 4.22
13:38:45.315 -> voltage: 4.20
13:38:45.315 -> voltage: 4.19
13:38:45.349 -> voltage: 4.06
13:38:45.349 -> voltage: 3.84
13:38:45.349 -> voltage: 3.53
13:38:45.383 -> voltage: 3.25

Hmmm... :thinking: The issue with this type of signal is going to be detecting the button press event from the stream of analog input data. You're going to have to poll very quickly to not miss the momentary button press. Once detected, send data to the Hub. I'd use a "button1 pushed" event. Then, you'll need to ignore excess 'low voltage' readings for some period of time to avoid sending multiple events to the hub.

I am thinking this may need to be a custom sketch, as HubDuino/ST_Anything doesn't really support polling analog inputs super fast...

WAIT! There is a specific board, I believe the ESP8266, where a user wanted 1 more contact sensor (i.e. IS_Contact device) that what the ESP8266 would allow. So, he submitted a pull request to allow the ESP8266 to use its Analog Input as a contact sensor. This may work for your needs, with a little code tweak to the threshold voltage.

Let me find the code and I'll be back in a few...

1 Like

@ritchierich - Here is the section of code that was changed to allow any ST_Anything device that inherits from the InterruptSensor Parent Class (e.g. the IS_Contact, IS_Button, IS_Motion, etc...) to use the ESP8266's A0 analog input as a digital input sensor. Therefore, if you create an IS_Button device, and specify A0 as the input pin, it should just work (with the mods below.)

You may need to tweak this ESP8266 specific section of code to be more behaved. For example, it does not have much in the way of debounce logic, which the normal digital inputs do. But, in general, it should work for your needs. Just be sure to change the '512' counts to the value that corresponds to your 1vdc (which should be about 310 counts, if I've done my math correctly.) You may also need to tweak the '1000' value, which is used to prevent the board from reading the A0 input every time through the loop() routine of the sketch. Instead, it only checks once every 1000 times through the loop(). For a contact sensor, this worked fine. For your momentary button press, you may need to adjust this value to not miss a button pushed event.

//******************************************************************************************
//  File: InterruptSensor.cpp
//  Authors: Dan G Ogorchock & Daniel J Ogorchock (Father and Son)
//
//  Summary:  st::InterruptSensor is a generic class which inherits from st::Sensor.  This is the
//			  parent class for the st::IS_Motion, IS_Contact, and IS_DoorControl classes.
//			  In general, this file should not need to be modified.   
//
//  Change History:
//
//    Date        Who            What
//    ----        ---            ----
//    2015-01-03  Dan & Daniel   Original Creation
//	  2015-03-17  Dan			 Added optional "numReqCounts" constructor argument/capability
//    2019-09-22  Dan Ogorchock  ESP8266 support for using A0 pin as a digital input
//
//
//******************************************************************************************

#include "InterruptSensor.h"

#include "Constants.h"
#include "Everything.h"

namespace st
{
//private

	//Checks to see if the pin has changed state.  If so calls appropriate function.
	void InterruptSensor::checkIfTriggered()
	{
            bool inputState;
#if defined(ARDUINO_ARCH_ESP8266)
            if (m_nInterruptPin == A0) 
			{
				if (m_nLoopCounter == 1000) {				//reading an analog input every pass through loop() is too slow
					inputState = analogRead(A0) > 512 ? HIGH : LOW;
					m_nLoopCounter = 0;
				}
				else {
					m_nLoopCounter++;
					return;
				}
			}
			else {
				inputState = digitalRead(m_nInterruptPin);
			}
#else
            inputState = digitalRead(m_nInterruptPin);
#endif
			if (inputState == m_bInterruptState && !m_bStatus) //new interrupt
			{
				m_nCurrentDownCount = m_nRequiredCounts;
				m_nCurrentUpCount++;
				if (m_nCurrentUpCount >= m_nRequiredCounts)
				{
					m_bStatus = true;
					m_bInitRequired = false;
					runInterrupt();
				}
			}
			else if ((inputState != m_bInterruptState && m_bStatus) || m_bInitRequired) //interrupt has ended OR Init called us
			{
				m_nCurrentUpCount = 0;
				m_nCurrentDownCount--;
				if (m_nCurrentDownCount <= 0)
				{
					m_bStatus = false;
					m_bInitRequired = false;
					runInterruptEnded();
				}
			}
	}
...
2 Likes

I realize this is moot to you at this point but I'm puzzled why this doesn't work. Please post here if you ever discover the reason. Thanks

I am honestly not sure. I had my multimeter connected via alligator clips to the same wires as the Arduino and it was measuring a constant 4 volts yet the Arduino was fluctuating quite a bit.

Dan thank you very much for the code. I will give it a go and report back.

2 Likes

Probably there's not enough current to drive the relay from his 5.9VDC circuit.
One other simple way to do this is to use a DPDT switch. One set of contact for the pump and the other for the notification circuit.

There ya go, that makes sense, and I'm :roll_eyes: that I didn't think of it. D'oh!

Ray thanks, not sure I follow how to use a DPDT. We have a LCD keypad in our master bathroom that allows you to change settings on the tankless hot water heater where there is recirculation button on it that I am trying to detect when pressed so no opportunity to change that since there are only 2 wires coming to the keypad to power it and send settings back to the water heater. One challenge I had testing a relay prior was the coil is a NC connection so that disabled the button entirely from working. Then I tried the "hot" side of the button along with the ground coming to the keypad but as you said there wasn't enough current to drive the relay coil. What I also found too is that I needed at least a 10k resistor when hooked up to these otherwise the button wouldn't work either.

Unfortunately this type of stuff is something I have no experience with and learning as I go. If I am misunderstanding please let me know. Thank you for the suggestion.

I see your dilemma. The other option is to use an opto isolated relay in parallel with your switch. You can do a search on Amazon. Amazon.com : opto isolated relay 5v

With an opto isolated relay. The input needs very little current to trigger and also the resistance is very high which will help eliminate the need for 10k EOL problem.

1 Like

Thanks for the further details. As I was looking at these relays on Amazon these looked familiar and I got a message that "you purchased this on X date" and got excited so went and found them in my "HA Bin" in the garage. Unfortunately this relay didn't work either because when the button is pressed the 5.9VDC goes down to 0 if held so the power to the relay itself was terminated thus it couldn't actuate the relay.

Power to the LCD display is 12VDC so curious if I could get the 12V model, use its power to power the relay and use the low side of the button as "in" to actuate the relay but a little worried because I don't want to supply 12V to this button and fry something. I am going to continue to pursue the ESP/Arduino solution in the mean time.

The more important question is. Does the relay energized when connected to the 5.9VDC? All you care about is the state of the dry contacts of the relay.
Usually this type of board needs external power for the main board/relay. The trigger input uses the switch power for triggering. Otherwise you will have the same issue as not enought current.

This is the relay I used. Yes the green power light turns on. I did have to use a 10k resistor even with this relay so that the button on the LCD controller still works. But when I press the button on LCD the power to the relay is terminated. I even tried using a USB 5V power to power the relay and connected one of the sides of the button to the "In" terminal and nothing unfortunately.