Hmmm…when I use a simple Python script I took from a tutorial to detect the button being pressed it works.
But mqtt-gpio does nothing when I press the button. Nothing happens in MQTTBox or on the shell…only the initial settings are sent upon startup. So the MQTT connection itself should be allright.
I found out that it is very simple to write a small python program publishing a key press on mqtt. Will give it a try tomorrow as I am stuck with pi-mqtt-gpio.
I installed paho-mqtt and wrote (that means: stole together ) a little script that publishes my buttonpress to mqtt topic doorbell:
import RPi.GPIO as GPIO # Import Raspberry Pi GPIO library
import paho.mqtt.publish as publish
import paho.mqtt.client as mqtt
def button_callback(channel):
publish.single("doorbell/", payload=None, qos=0, retain=False, hostname="<mqtt host>", port=1883, client_id="", keepalive=60, will=None, auth={'username':"<mqttuser>",'password':"<password>"}, tls=None, protocol=mqtt.MQTTv311, t$
print("Button was pushed!")
GPIO.setwarnings(False) # Ignore warning for now
GPIO.setmode(GPIO.BOARD) # Use physical pin numbering
GPIO.setup(10, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # Set pin 10 to be an input pin and set initial value to be pulled low (off)
GPIO.add_event_detect(10,GPIO.RISING,callback=button_callback) # Setup event on pin 10 rising edge
message = input("Press enter to quit\n\n") # Run until someone presses enter
GPIO.cleanup() # Clean up
Home Assistant notices the button press and input_boolean.doorbel is turned on by the automation. On the doorpi card I get the option to accept and reject the call, and when I click Accept that changes to end call.
And where should I put the signalling.js and main.js? Also into /www/doorpi? And should I add them under resources: in the ui-lovelace.yaml? (edit: from checking the doorpi-card.js I assume they just have to reside in the same directory as doorpi-card.js)
And is it ok to remove the configuration for the server on port 8888?
So many questions, sorry
edit:
I FINALLY GOT IT WORKING!!!
So stupid! It was not working as I had no SSL active on my Home Assistant and therefore were not able to allow access to the audio devices. Would be helpful if Chrome or Firefox had told me about blocking the access Quickly created SSL certificates and now it is working.
Have to finetune my buttonpress script now
edit:
Instead of putting more work in my button press mqtt script, I used the one I found here, with slight adjustments:
My version:
(added possibility to enter mqtt credentials and changed journal handler to work with custom systemd installed through “pip3 install systemd”. Changed GPIO mode to BOARD.
#!/usr/bin/python3
import RPi.GPIO as GPIO
import logging
import paho.mqtt.publish as publish
from time import sleep
from systemd import journal
log = logging.getLogger('mqtt_alarm')
log.addHandler(journal.JournaldLogHandler())
log.setLevel(logging.INFO)
MQTT_HOST = "<mqtthost>"
MQTT_TOPIC_PREFIX = "doorbell/input/"
MQTT_USER = "<username>"
MQTT_PASS = "<password>"
MQTT_CLIENT_ID = ""
MQTT_PAYLOADS = {
0: "Off",
1: "On",
}
# Dictionary of GPIO PIN to mqtt topic
PIN_MAP = {
10: "button_1",
}
GPIO.setmode(GPIO.BOARD)
def state_change_hadler(channel):
state = GPIO.input(channel)
if state:
log.info("Rising edge detected on {}".format(channel))
else:
log.info("Falling edge detected on {}".format(channel))
publish_event(channel, state)
def publish_event(pin, state):
topic = MQTT_TOPIC_PREFIX + PIN_MAP[pin]
payload = MQTT_PAYLOADS[state]
publish.single(topic, payload, hostname=MQTT_HOST, auth={'username':MQTT_USER,'password':MQTT_PASS}, retain=True, qos=2)
log.info("Published event, topic={}, payload={}, hostname={}".format(topic, payload, MQTT_HOST))
for pin, name in PIN_MAP.items():
GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.add_event_detect(pin, GPIO.BOTH, callback=state_change_hadler, bouncetime=100)
state = GPIO.input(pin)
log.info("Mapped pin {:0>2d} to {}".format(pin, name))
log.info("... state {}".format(state))
publish_event(pin, state)
try:
while True:
sleep(60)
except KeyboardInterrupt:
log.info("Stopping...")
finally:
GPIO.cleanup()
Now I have to put some power to the door for the Pi but I found an unused power cable there already that I might be able to put back to life
When you use Traefik to make that all available over the Internet, that means you are forwarding a Pi Port through the router , right?
Thats a thing a totally want to avoid - to much stress tracking security for device and software… because IF somebody breaks in that network, he might even be able to open my door (didn’t implement something for that yet and still have to walk there on my own, but that might change, too).
I think I will stay with VPN for that.
Would be great of course if there was a way to make it available through nabu casa somehow… maybe through the ingress feature? Maybe by creating an own small hass.io addon? Will do some research if that might be possible…
I see. Naaa…since my QNAP got infected with a Malware and regarding the extremely poor information politic for that issue from QNAP I will never again expose my NAS to the Internet
Hi Ronald,
I am sorry to trouble you as this a HA issue, but I am trying to build this project and can’t get SSL working for UV4l. I have tried everything I can think of. My config works fine until I try to secure it. I have generated a self certificate, but when I make the following changes I can’t access my site
HTTPS options:
server-option = --use-ssl=yes
server-option = --ssl-private-key-file=/etc/ssl/private/selfsign.key
server-option = --ssl-certificate-file=/etc/ssl/private/selfsign.crt
my key is as below
pi@raspberrypi:/etc/uv4l $ ls
privkey.key selfsign.key uv4l-raspicam.conf.save uv4l-uvc.conf
selfsign.crt uv4l-raspicam.conf uv4l-raspidisp.conf
Hi ,I think this is an amazing project. I have completed step 1 of the instructables and have video and audio working. I am a little lost at step 3. Do I put the 3 files into the library www/doorpi/, being doorpi-card.js, signalling.js and doorpi-camera-view.js?
How do I use the doorpi.yaml? Do I copy it to my Configuration.yaml? Do I need to create a LoveLace card, or does the broswer mode do that. Do I need to change any names in the above files?
Sorry for all the dumb questions, but as you can see I am not very good at this stuff.
Thanks
Mark
If you want to have the doorpi available when you are not home, you will need to make sure that ‘your url’ is available external (so not a 192.169.***) url.
Hi Ronald
Thanks for your hard work on this love it.I have everything up and running on a Pi 2 only issue i have is with certificates eg NET::ERR_CERT_AUTHORITY_INVALID
How did you get around this?. Do you use your Nas to reverse proxy and lets encrypt?
also can you use this from your phone IOS or will it only work through chome on a computer
thanks