DIY Smart Doorbell with Android notifications

I uploaded my latest config files to the instructable.

Without info from the developer console log in chrome, I can’t do anything. Do note that the 8888 url is only for testing. I now proxy UV4L on port 9090 using traefik which automatically gives me https. In my lovelace config, I thus use the https://myhost:9090 now (proxied via traefik).

A Pi zero W could not handle the load with me (or I don’t have enough patience)

I got u4vl running on buster as described above. As I said when I connect to https://myhost:9090 and click on WebRTC I get two way audio. Video is working, too.

But I have no idea why the DoorPi demo is not working (but you say thats not really important).

How can I get you that log? Maybe I should just go on with the Home Assistant integration from the instructable and see if that works tomorrow.

Are you using traefik only to give you https?

Yes, continue with Home assistant integration.

Traefik is used for https and to have it available outside home network.

1 Like

Ah okay. We can discuss that later, haha :wink: Will first go on with the integration today and report back.

Hi Ronald,

can you give me an example how to integrate the doorpi-card?

I found out that I have to add a camera_entitiy by checking the JS but what about the doorpi config? Is that only the URL (https://myhost:9090)?

edit: got the card runnling (mostly)

Hi,

I have a problem with the input button. Maybe I’m doing it completely wrong…

I configured Pin 18 (GPIO24) as button 1. I exported the pin and set the direction to in. Then I started pi-mqtt-gpio and connected Pin 18 and 1 with a wire. My expectation was that I see the pin triggered in mqtt-gpio, but nothing happens.

Am I missing something?

edit: I used a little Python script to check if my button on Pin 18 is working and it is.

edit2: The button seems to be working, I get an incoming call. However no audio yet and when I click hangup, the log says:

2019-10-07 16:44:42 ERROR (MainThread) [frontend.js.latest.201909191] http://myhost:8123/local/doorpi/doorpi-card.js:165:28 TypeError: this.signalObj.hangup is not a function

edit3: No it was just the initial state of the button triggering the card in Home Assistant because I change the “on” and “off” payload in the config. Still no reaction to the button.

Do you have the doorpi.yaml package added to your packages?

P.s. as I also have another life (work and private), I can’t always reply fast. It might take a couple of days.

Hi Ronald,

Yes I added everything. Will now double check each line. Is it expected that I see something on the console running the mqtt-gpio script when I press the button?

Of course I don’t expect you to answer immediately, I’m thankful for any help you can provide :slight_smile:

Mmm, to be honest, I don’t know if you see something in the console when you press a button. I test it using MQTTBox, a chrome plugin where you can subscribe to MQTT topics (I subscribe to the topic doorbell/#). Then, we you press the doorbell, you should see something in the MQTTBox UI.

1 Like

Perfect, will install that plugin at home, will help me a lot. Then I will know where I have to continue troubleshooting: At the mqtt-gpio area or in Home Assistant already.

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.

Very strange. I have very good experience with pi-mqtt-gpio once I figured out pull_up/pull_down.

Don’t forget to make sure that your program starts automatically after a reboot if you should experience a power failure.

I tried everything in the config with pullup, pulldown and the payloads. No reaction at all.

I will try it like described here:

https://www.raspberrypi.org/forums/viewtopic.php?t=172748

However the next days I will not be able to work on it…either I have success today or I will have a hard time waiting until I can continue :smiley:

Ok my button is connected to Pin10 and 3,3V now.

I installed paho-mqtt and wrote (that means: stole together :smiley:) 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

Script parts taken from here https://raspberrypihq.com/use-a-push-button-with-raspberry-pi-gpio/ and here https://pypi.org/project/paho-mqtt/ and here https://www.raspberrypi.org/forums/viewtopic.php?t=172748

Still have to check on payload etc of course… :slight_smile:

This is how far I got:

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.

However I don’t get sound in any direction.

It is working on https://myhost:9090/stream/webrtc but not in Home Assistant. What URL do you enter in the doorpi card? I entered https://myhost:9090 without any path - is that correct?

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 :smiley:

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 :smiley: Quickly created SSL certificates and now it is working.

Have to finetune my buttonpress script now :slight_smile:

edit:

Instead of putting more work in my button press mqtt script, I used the one I found here, with slight adjustments:

:slight_smile:

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()
2 Likes

Glad you got it working!!! I hope you can enjoy the calling now…

I’ll put an extra warning in the instructable about https…

Cheers,
R

1 Like

Yeah.

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 :slight_smile:

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…

Yes. But it runs on a Docker on my NAS.

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 :wink: