jerrod-lankford / garageqtpi Goto Github PK
View Code? Open in Web Editor NEWAn MQTT server for a raspberry pi garage door opener. Most commonly used as a HomeAssistant cover component.
License: MIT License
An MQTT server for a raspberry pi garage door opener. Most commonly used as a HomeAssistant cover component.
License: MIT License
Hi - I've got a weird issue here.
Everything is set up fine, with discovery turned off. HA shows the Cover and if I open and close the garage door the 'state change' event fires and HA shows the appropriate state - so the MQTT comms are working OK.
However, if I click on any of the up/down/stop buttons on HA, nothing appears to be getting sent to the other Pi! For testing I'm running main.py interactively so I'd expect at least to see the 'connection' and 'listening' messages but they aren't coming up either.
Any thoughts about what's going on here? I'm running a fresh install of the latest version of HA on a Raspberry Pi 4, the remote Pi is a B+ running a late-ish version of Raspbian, and I'm using the latest version of your code.
Cheers,
Andy
I am getting an error when performing the "python main.py" command. The error is, "Traceback (most recent call last):
File "main.py", line 3, in
import yaml
ImportError: No module named yaml"
any help would be appreciated.
By default, python seems to buffer output which leads to systemd/journald not receiving the results of the prints to STDOUT in a timely manner. If the service file provided would start the script with python in unbuffered mode
ExecStart=/usr/bin/python -u /home/pi/GarageQTPi/main.py
the logging to journald would come immediately and not in larger junks sometime or never.
When using discovery via MQTT, the garage door is configured as a generic "cover" ie. blinds.
It would be great if the MQTT Cover device_class could be set to "garage"
Something I found is that if your mqtt service(mosquitto) what have you re-connects or restarts, this will cause your garage door to open if closed/close if opened. This is a pretty major issue. Right now I have an automation in homeassistant that will auto-close the doors if they are open for a given amount of time, but it is still pretty scary that if you have a power outage at night my garage doors will open when mosquitto comes back online.
I think it could be fixed by adding a variable that holds the current mqtt value and checks against new values received. If they match then it does not trigger??
I need to investigate if this works with paho 1.3 or not. For now if you hit issues please revert back to 1.2
It would be great if a unique_id could be sent to the Home Assistant discovery as per https://www.home-assistant.io/integrations/cover.mqtt/#unique_id
This would allow the entity ID to be changed within HA and prevent duplicate entities being created.
@bg1000 something for your fork?
It would be awesome if this project supported the break sensors as well to detect when sometime is in the way of the door
Can you set a configurable closing state for the time between the relay trigger and the sensor closing?
This would allow the stop command in home-assistant to be functional, as well as prevent double triggering of cover.close_cover.
I have GarageQTPi installed on a Raspberry Pi B running Raspbian Stretch Lite. I'm also running a Raspberry Pi 3 with Hass.io installed. I'm wanting to control my garage door from within Home Assistant using GarageQTPi over MQTT.
When I run python main.py
from within the GarageQTPi directory, I get the following Traceback:
Traceback (most recent call last): File "main.py", line 61, in <module> door = GarageDoor(doorCfg) File "/home/pi/GarageQTPi/lib/garage.py", line 31, in __init__ GPIO.setup(self.relay_pin, GPIO.OUT) ValueError: Channel must be an integer or list/tuple of integers
My config.yaml file looks like this:
mqtt: host: 192.168.1.136 port: 1883 user: homeassistant password: my_password doors: - id: 'garage_door' relay: '23' state '17' state_topic: "home-assistant/cover/garage_door" command_topic: "home-assistant/cover/garage_door/set" position_topic: "home-assistant/cover/garage_door/set_position" availability_topic: "home-assistant/cover/garage_door/availability"
I'm new to using MQTT, so please let me know if anything is incorrect/incompatible with my config. I've added the position_topic and availability_topic only since they were included in the Home Assistant config and I figured everything should be identical between the two.
Any ideas as to why I'm getting the error? I've been unsuccessful getting anything other than "unavailable" or "unknown" as a status for the garage door in Home Assistant.
Thanks in advance,
jerry
I had two issues:
The wall button woudl stop working and the door opens on reboot/bootup
invert_relay = true seemed to fix that. I wired to NO on the 2 ch relay, and they lights for each relay used to be lit red. Now they dont light at all?
But both HA / wall button open / close the door?
Is that expected?
This did not fix the door open on boot issue?
I've seen the closed thread.
I completely erased my MQTT container and its data.
I turned retain off and commented it out in HA
Dont see how this is a MQTT/Mosquitto issue. I turned off HA and booted the Garage RPi and the door still opened independent of HA
Does persist need to be off in MQTT as well?
Configuration can be changed to:
persist data to /mosquitto/data
log to /mosquitto/log/mosquitto.log
i.e. add the following to mosquitto.conf:persistence true
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log
Hi,
I installed your software on my working raspberrypi with https://github.com/andrewshilliday/garage-door-controller.
Turned the garage-door-controller of and start your version and configured them in home-assistant. Everything works fine and I can open and close my single garage door with home-assistant.
But - Parallel to the relay I have a push button installed who works fine in combination with garage-door-controller, but not with GarageQTPi. I just can trigger my push button once and afterwards he didn't react anymore. If I stop GarageQTPi everything is fine again and if I use garage-door-controller again also. Without changing the wiring.
Any Idea?
Thanks a lot.
It appears this project is no longer actively developed. BG1000 has a more current active fork here
pi@raspberrypi:~/GarageQTPi $ python main.py
Welcome to GarageBerryPi!
Traceback (most recent call last):
File "main.py", line 48, in
port = int(CONFIG['mqtt']['port'])
TypeError: int() argument must be a string or a number, not 'NoneType'
Hi, any chance to get help to have this running ?
Python 2.7.9
Requirement already satisfied: paho-mqtt in /usr/local/lib/python2.7/dist-packages (1.5.1)
Requirement already satisfied: PyYAML in /usr/local/lib/python2.7/dist-packages (5.3.1)
python main.py
Welcome to GarageBerryPi!
main.py:42: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
CONFIG = yaml.load(ymlfile)
Traceback (most recent call last):
File "main.py", line 108, in <module>
client.loop_forever()
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 1779, in loop_forever
rc = self.loop(timeout, max_packets)
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 1181, in loop
rc = self.loop_read(max_packets)
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 1572, in loop_read
rc = self._packet_read()
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 2310, in _packet_read
rc = self._packet_handle()
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 2942, in _packet_handle
return self._handle_connack()
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 3030, in _handle_connack
self, self._userdata, flags_dict, result)
TypeError: on_connect() takes exactly 3 arguments (4 given)
I hope this is still being watched as I just found it ;)
Installed and setup on the pi without an issue (I think) but I am getting this error in HA.
Invalid connection from (client @=192.168.1.137:37667) : [MQTT-3.1.2-1] Incorrect protocol name: "MQIsdp"
1:56 PM util/async_.py (ERROR)
Invalid connection from (client @=192.168.1.137:60523) : [MQTT-3.1.2-1] Incorrect protocol name: "MQIsdp"
1:56 PM util/async_.py (ERROR)
This error continuously happens with different ports.
Currently running HA version 0.86.4 and using the embedded MQTT.
I have this installed on Raspberry Pi Zero, no issues with the installation.
Regardless of my magnetic switch (I have the same ones you documented), it's not registering in GarageQTPi correctly. In other words, if I have the switches in contact, it still thinks the garage is open. If I switch the state_mode
, the state never changes regardless of the state of magnetic switches.
Furthermore, the commands to open and close are registering (as evidenced by the logs), but the signal never makes it to the garage door.
I don't think this is a software issue (at least not with GarageQTPi), it feels more like a GPIO issue. However, this is a brand new board with the headers soldered on professionally at the factory.
Do you have any suggestions on how to troubleshoot connectivity issues?
Can a configuration option be created to use NC magnetic switches? (reverse open and closed?)
I have been using GarageQTPi for a little over a year now however I have a problem after purchasing a new garage door opener.
The old garage door opener had the ability to connect the relay directly to the garage door opener and it was working fine.
The new garage door opener doesn't have this ability to I have had to hack a remote by wiring the relay to the button on an extra remote. This is working fine except for one issue. When the Pi boots up the relay triggers once. This opens the garage after a power failure. Not a good thing.
I don't understand why this wouldn't have caused the same issue when the device was wired directly to the garage door opener. But I can't figure out how to solve it.
I have read the thread on #13
These issues don't apply since I had this system working for over a year and the only change is the relay wiring is now going to a remote instead of to a garage door opener. I don't see how this could caused the device to trigger on boot since it is on the other side of the relay. The relay is triggering but the Raspberry Pi has not changed and it is still wired to same pins I used before when it was working.
Another test I performed was to change SHORT_WAIT from .2 to 2. The reason I did this was it seemed that I was observing that the boot trigger was a little shorter than the actual trigger. This test confirmed my observation. After this change on boot the trigger is still brief like it was when SHORT_WAIT was .2, but the actual trigger was in fact now triggering for 2 seconds. So this means the call causing the trigger is not the __press method.
I suspect the trigger is called during the init call setting up the GPIO but I don't know how to prove that or how to fix it if it is the cause.
The next test I performed was to start with only one door configured. Then I configured a second door and restarted the service. This again caused the trigger. So it seems that after a reboot the first time the GPIO is initialized it triggers briefly. In this test case the GPIO 24 triggered on boot. A stop/start didn't trigger it again. Adding left door on GPIO 23 then caused a trigger again with a simple stop/start. After first trigger subsequent start/stops don't trigger again. I confirmed this test by disabling autostart. Then I enabled the service and started after booting and it does in fact trigger.
So clearly a call in the code is causing the trigger but I don't see any way to fix this.
Sorry for such a long message but I wanted to explain all my testing and findings.
I wonder if there is some way to prevent the relay from actually triggering unless the GPIO is fired for a longer time. Some additional hardware inline either between the GPIO and the relay to prevent the signal from getting through unless it is longer or the same on the relay side which prevents a brief closed relay from triggering the remote an requiring the relay be closed for a longer period.
I suspect this is why my old garage door opener didn't open on boot. I suspect it ignored such a brief close of the circuit. The SHORT_WAIT of .2 seconds was long enough but the slightly quicker closed circuit on boot (guessing .1 or less) was ignored.
The linux kernel has removed support for the old GPIO communication, the new kernel API has to be used for GPIO coms. Read here. I tested in on Bookworm Debian, but it doesn't work because RPi.GPIO isn't updated for the new API. We need to fix this.
Hello,
I am trying to install it and the problems.
Next, I am trying to run: pip install -r requirements.txt, I receive the following error:
Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt'
Storing debug log for failure in /root/.pip/pip.log
Can you help?
Thank you.
Looks to me that it does not work. Can you please take a look at this and let me know?
sudo python main.py
Welcome to GarageBerryPi!
Traceback (most recent call last):
File "main.py", line 37, in
CONFIG = yaml.load(ymlfile)
File "/usr/local/lib/python2.7/dist-packages/yaml/init.py", line 71, in load
return loader.get_single_data()
File "/usr/local/lib/python2.7/dist-packages/yaml/constructor.py", line 37, in get_single_data
node = self.get_single_node()
File "/usr/local/lib/python2.7/dist-packages/yaml/composer.py", line 36, in get_single_node
document = self.compose_document()
File "/usr/local/lib/python2.7/dist-packages/yaml/composer.py", line 55, in compose_document
node = self.compose_node(None, None)
File "/usr/local/lib/python2.7/dist-packages/yaml/composer.py", line 84, in compose_node
node = self.compose_mapping_node(anchor)
File "/usr/local/lib/python2.7/dist-packages/yaml/composer.py", line 133, in compose_mapping_node
item_value = self.compose_node(node, item_key)
File "/usr/local/lib/python2.7/dist-packages/yaml/composer.py", line 84, in compose_node
node = self.compose_mapping_node(anchor)
File "/usr/local/lib/python2.7/dist-packages/yaml/composer.py", line 133, in compose_mapping_node
item_value = self.compose_node(node, item_key)
File "/usr/local/lib/python2.7/dist-packages/yaml/composer.py", line 64, in compose_node
if self.check_event(AliasEvent):
File "/usr/local/lib/python2.7/dist-packages/yaml/parser.py", line 98, in check_event
self.current_event = self.state()
File "/usr/local/lib/python2.7/dist-packages/yaml/parser.py", line 449, in parse_block_mapping_value
if not self.check_token(KeyToken, ValueToken, BlockEndToken):
File "/usr/local/lib/python2.7/dist-packages/yaml/scanner.py", line 116, in check_token
self.fetch_more_tokens()
File "/usr/local/lib/python2.7/dist-packages/yaml/scanner.py", line 224, in fetch_more_tokens
return self.fetch_alias()
File "/usr/local/lib/python2.7/dist-packages/yaml/scanner.py", line 607, in fetch_alias
self.tokens.append(self.scan_anchor(AliasToken))
File "/usr/local/lib/python2.7/dist-packages/yaml/scanner.py", line 926, in scan_anchor
% ch.encode('utf-8'), self.get_mark())
yaml.scanner.ScannerError: while scanning an alias
in "config.yaml", line 3, column 11
expected alphabetic or numeric character, but found '\n'
in "config.yaml", line 3, column 12
pi@Garage-Door:~/GarageQTPi $
I do not have the hardware connected yet. Could this be an issue? Everything is in mail, should be here shortly, but I want to be sure that I am ready. How can I check if it works correctly?
Thank you.
I've installed everything onto my pi.
But when running main.py I get
Welcome to GarageBerryPi!
Traceback (most recent call last):
File "main.py", line 45, in <module>
user = CONFIG['mqtt']['user']
TypeError: string indices must be integers, not str
I seemed to be getting lots of errors with the config.yaml but have been able to resolve those just by changing the spaces..... however this error could be related. I'm installing via ssh from a windows 10 computer.
I have a problem when relay that opens the garage door does not change. I run multiple tests and, as far as I can see, my pin 23 does not change the status when I try to open/close the door. It always has 3.5V. It starts as soon as I start the program.
I see this when I try to open/close door from Home Assistant. I also move sensor to change the status:
This is the entry for this program in configuration.yaml file in Home Assistant:
Can you please help?
Thank you.
Hi!
Thanks for the great work! I've set this up on my Raspberry Pi Zero W and it works great, integrates perfectly with Home Assistant, everything works.
However, when I reboot the Pi (or power is otherwise removed e.g. a power outage), then upon startup the script automatically "cycles" the pins and triggers the relay to open/close the garage door. Due to the stability of the Pi and this application, I only noticed this issue recently even though I have had this running for quite a while ๐
Any suggestions? I'm ok with beginner Python, so my guess is it might have something to do with setting the pull_up_down to PUD_DOWN? Or would that just reverse the situation so that it will still cycle during startup? :)
It almost sounded like someone was having a similar issue but was in the wrong topic:
#3
But I didn't see any resolution to their issue in there either.
Thanks!
-Chad
You don't need to make it python 3 compliant, but specifying that detail would be helpful. Particularly as you're relating it to home-assistant, which is a python3 project.
I wired things up in my garage and then ran a couple of test scripts to verify the wiring and GPIO numbers were as expected.
I followed the installation instructions in README.md.
Running the app from the command line (python main.py) works exactly as expected with no errors. I enabled discovery and was also able to add the garage cover to the HA front end. I can open and close the door and the icon changes as expected.
I ran sudo bash autostart_systemd.sh
which ran without error. On reboot I see the following in syslog:
May 30 19:45:52 raspberrypi python[415]: Traceback (most recent call last): May 30 19:45:52 raspberrypi python[415]: File "/home/pi/GarageQTPi/main.py", line 3, in <module> May 30 19:45:52 raspberrypi python[415]: import yaml May 30 19:45:52 raspberrypi python[415]: ImportError: No module named yaml May 30 19:45:52 raspberrypi systemd[1]: [email protected]: Main process exited, code=exited, status=1/FAILURE May 30 19:45:52 raspberrypi systemd[1]: [email protected]: Unit entered failed state. May 30 19:45:52 raspberrypi systemd[1]: [email protected]: Failed with result 'exit-code'.
This repeats every 3 seconds when the service is restarted. It seems that when running as a service that python can not find the libraries that were installed via pip install -r requirements.txt. I gather this has something to do with how sys.path is set but didn't completely work through that.
After some research I found this post on stack exchange which describes the exact same issue (different library):
https://stackoverflow.com/questions/38527235/running-python-script-via-systemd-fails-to-load-module
The answer in post 8 is to install the libraries via sudo -H pip install -r requirements.txt
Things work as expected now. I am not 100% certain if this is something specific to how my environment is setup or if others might run into the same issue.
Do you think I can use Raspberry Pi Zero? After everything worked for me on Raspberry Pi 3, I decided to try it on RPi Zero and, as far as I can see, everything works.
Can I use it or would you recommend to use RPi 3?
Thank you.
Hi there,
I am quite frustrated atm and don't know what I am doing wrong...
This is what I get when I try python main.py:
Welcome to GarageBerryPi!
Traceback (most recent call last):
File "main.py", line 50, in
client.connect(host, port, 60)
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 768, in connect
return self.reconnect()
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 940, in reconnect
return self._send_connect(self._keepalive, self._clean_session)
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 2125, in _send_connect
keepalive))
struct.error: cannot convert argument to integer
Can you tell me what my problem is?
Thank you!!
Has anyone seen an issue with the Garage door opening by itself? Its only happened a couple times but is concerning. My guess is electrical interference could be triggering the GPIO but that's just a guess.
The graphic from README.md that shows the wiring uses a wrong pin number for the right (blue) sensor wiring. The graphic (and the config.yaml) refer to the pin as GPIO21, but according to https://www.raspberrypi.org/documentation/usage/gpio/ the pin used in the graphic is GPIO27.
Saw that a PiZeroW seems like it should work?
I actually have an older RPi Model B rev 2 that I'd love to repurpose and get use for if it would work?
Hello,
I am trying to install it and the problems.
I installed Raspbian
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python3-dev python3-venv
python3 -m venv env
env/bin/python -m pip install --upgrade pip setuptools
git clone https://github.com/Jerrkawz/GarageQTPi.git
Next, I am trying to run: pip install -r requirements.txt, I receive the following error:
Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt'
Storing debug log for failure in /root/.pip/pip.log
After that, I figured out that I have to go to GarageQTPi directory first and run it from that directly. This is the output and error:
pi@Garage-Door:~$ pip install -r GarageQTPi/requirements.txt
Downloading/unpacking paho-mqtt==1.2 (from -r GarageQTPi/requirements.txt (line 1))
Downloading paho-mqtt-1.2.tar.gz (49kB): 49kB downloaded
Running setup.py (path:/tmp/pip-build-xftl86/paho-mqtt/setup.py) egg_info for package paho-mqtt
Downloading/unpacking PyYAML==3.12 (from -r GarageQTPi/requirements.txt (line 2))
Downloading PyYAML-3.12.tar.gz (253kB): 253kB downloaded
Running setup.py (path:/tmp/pip-build-xftl86/PyYAML/setup.py) egg_info for package PyYAML
Installing collected packages: paho-mqtt, PyYAML
Running setup.py install for paho-mqtt
error: could not create '/usr/local/lib/python2.7/dist-packages/paho': Permission denied
Complete output from command /usr/bin/python -c "import setuptools, tokenize;file='/tmp/pip-build-xftl86/paho-mqtt/setup.py';exec(compile(getattr(tokenize, 'open', open)(file).read().replace('\r\n', '\n'), file, 'exec'))" install --record /tmp/pip-tJzjZ4-record/install-record.txt --single-version-externally-managed --compile:
running install
running build
running build_py
creating build
creating build/lib.linux-armv7l-2.7
creating build/lib.linux-armv7l-2.7/paho
copying src/paho/init.py -> build/lib.linux-armv7l-2.7/paho
creating build/lib.linux-armv7l-2.7/paho/mqtt
copying src/paho/mqtt/client.py -> build/lib.linux-armv7l-2.7/paho/mqtt
copying src/paho/mqtt/subscribe.py -> build/lib.linux-armv7l-2.7/paho/mqtt
copying src/paho/mqtt/init.py -> build/lib.linux-armv7l-2.7/paho/mqtt
copying src/paho/mqtt/publish.py -> build/lib.linux-armv7l-2.7/paho/mqtt
running install_lib
creating /usr/local/lib/python2.7/dist-packages/paho
error: could not create '/usr/local/lib/python2.7/dist-packages/paho': Permission denied
Cleaning up...
Command /usr/bin/python -c "import setuptools, tokenize;file='/tmp/pip-build-xftl86/paho-mqtt/setup.py';exec(compile(getattr(tokenize, 'open', open)(file).read().replace('\r\n', '\n'), file, 'exec'))" install --record /tmp/pip-tJzjZ4-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip-build-xftl86/paho-mqtt
Storing debug log for failure in /home/pi/.pip/pip.log
Can you help?
Thank you.
getting this error when the service is trying to run........
โ [email protected] - GarageQTPi
Loaded: loaded (/etc/systemd/system/[email protected]; enabled; vendor preset: enabled)
Active: activating (auto-restart) (Result: exit-code) since Fri 2018-03-16 07:05:06 UTC; 2s ago
Process: 11297 ExecStart=/usr/bin/python /home/pi/GarageQTPi/main.py (code=exited, status=1/FAILURE)
Main PID: 11297 (code=exited, status=1/FAILURE)
Mar 16 07:05:06 garagepi systemd[1]: [email protected]: Failed with result 'exit-code'.
the bash script has run it has root....is that the problem or is there something in the code?
Hi!
I am wondering if I might have something setup incorrectly, or if it's just how this works currently. If I publish:
mosquitto_pub -h 192.168.1.100 -t home-assistant/cover/set -m "CLOSE"
If the door is open, it closes. However, if the door is closed, it will open. GarageQTPi's main.py appears to correctly identify the garage door as being open or closed (based on the reed sensor / pins). So it seems like it's not respecting the command and is instead acting like:
mosquitto_pub -h 102.168.1.100 -t home-assistant/cover/set -m "TOGGLE"
Do I have something misconfigured, or is this how it is currently setup?
Thank you!
-Chad
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.