I can not find a solution how to get the threshold from the hall sensor module.
#!/usr/bin/python
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
Digital_PIN = 22
GPIO.setup(Digital_PIN, GPIO.IN)
print('[CTRL + C, to stop the Script!]')
try:
while True:
if GPIO.input(Digital_PIN):
print('Magnet detected')
else:
print('No magnet')
sleep(1)
except KeyboardInterrupt:
print('\nScript end!')
finally:
GPIO.cleanup()
This is like the sample code from the provider I bought the module.
It works fine with Raspberry Pi, but I´d like to get the threshold, too.
(After that I want to implement the values in Home Assistant, but this will be the next step.)
Would someone please help me how to get the threshold?
Thank you for your answer,
but I don´t have a ESP (and I can´t use it).
The hall sensor is connected with a Raspberry Pi 4.
If anyone is interested, this is the hall sensor:
Given that your code uses a digital pin then you can only get binary results.
First of all, you would probably need to connect it to the analogue pin since I assume based on the code you use the digital pin.
But all that is probably irrelevant since I don’t really see anything how you are going to get the data to HA.
In my opinion you should start there. If you must use a RPI then solve that first.
If you are open for ESP, then everything will be a lot simpler.
Hello Hellis81,
first of all, I am open for ESP, but it is now way in my situation.
This is just a part of my code, only to show. The data will be send from the Raspberry to HA via mqtt.
This is already happening for other sensors and was not part of my question.
But you have given me a good hint → the analogue pin.
Silly me, how could I have overlooked that