Ring Alarm - MQTT Discovery Alarm integration

I am able to get it to run now and it connects. Should it generate that mqtt.yaml file in the same dir? Its not being created if so.

Im running the yamlgenerator

@Darbos Did you get some error messages when you tried to run ./yamlGenerator.sh?

When I run it on my Pi3, it does spit out some warnings about deprecated callbacks but it connects just fine to RIng, and then produces a mqtt.yaml as described in the readme. It also prints the yaml config for each of your Alarm devices to the console so you should be able to at least see the output.

I dont get any errors at all.

Connected to mqtt and subscribed to homeassistant channel
[
  {

and then prints all the base station / home information. However one thing I noticed, when I had the older one going it would print a second large block of json with all of my sensors. This new script is i dont get that, after the first block it just says

DataUpdate: errP=false station=XXXXXX-XXXXXX-X datatype=DeviceInfoDocType

DataUpdate: errP=false station=XXXXXX-XXXXXX-X datatype=DeviceInfoDocType

Connected to mqtt and subscribed to homeassistant channel

Connected to mqtt and subscribed to homeassistant channel

Socket is connected

Socket is connected

Socket is connected

Socket is connected

Also, if I just run the mqttAlarm.sh the sensors arnt poulating automaticlly like before…

@Darbos That’s the output from mqttAlarm.js, not yamlGenerator.js. I removed all the console output for the alarm devices in the newer version of the script because it was extraneous for my purposes. That said, I did find and fix a bug related to the discovery flag so it should work now to govern whether the mqttAlarm script properly does the discovery process or not. I just pushed a new commit to the repo to fix this bug.

If you use the exact yamlGenerator.sh script from my repo and put your Ring credentials and MQTT broker address in that script, it should run yamlGenerator.js and produce the mqtt.yaml file I described. You should also see some output to the console that looks like yaml configs for each of your alarm devices. It’s a stand-alone script that just produces the yaml you need for your configuration.

awesome man, thanks for the quick help! Ill check it out

got it, thanks man!

jimmy@RPI-HUB:~/ring-alarm-HA-plugin $ ./yamlGenerator.sh
fs.js:134
  throw new ERR_INVALID_CALLBACK();
  ^

TypeError [ERR_INVALID_CALLBACK]: Callback must be a function
    at maybeCallback (fs.js:134:9)
    at Object.writeFile (fs.js:1180:14)
    at Object.<anonymous> (/home/jimmy/ring-alarm-HA-plugin/yamlGenerator.js:14:4)
    at Module._compile (internal/modules/cjs/loader.js:736:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:747:10)
    at Module.load (internal/modules/cjs/loader.js:628:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:568:12)
    at Function.Module._load (internal/modules/cjs/loader.js:560:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:801:12)
    at executeUserCode (internal/bootstrap/node.js:526:15)

Tried running yamlGenerator.sh but there seems to be a problem in my case. Some type of error in the code. The mqtt.yaml file never generates. Any ideas?

My best guess is what was just throwing a warning message on my machine is throwing an actual error on yours due to the way Javascript works (guessing you’re running a newer version of Node than me or something to that effect). I just pushed a minor edit to the yamlGenerator.js that fixes the warning messages when I run it so hopefully it will resolve the error you’re seeing. Let me know if it’s still throwing that error message and I’ll take another poke at it.

1 Like

I’ve pushed one additional commit to the repo that will hopefully make sense. Basically, the script will listen for an incoming MQTT message published under “home/alarm/check.” This will just trigger the main function in the script which pulls the current status of each alarm device. The reason I added this in was I noticed that my script somehow got out of sync with the actual alarm mode and was showing armed when the alarm was actually disabled. In this state, it would no longer let me set the mode of the alarm from HA since the alarm panel component is dependent on status updates from your MQTT broker to confirm that the mode has changed on the actual alarm panel. To work around this, I added this additional listener in the script so you can fire an MQTT event from HA that will tell the script to pull all the latest statuses (including the alarm mode) and this will correct any out of sync condition.

You can use this however you see fit. In my setup, I have an automation that triggers a timer every time the alarm mode changes (basically it fires the timer.start service every time HA posts an MQTT message to the home/alarm/command topic). I have a second automation listening for incoming MQTT messages on the home/alarm/state topic which which then calls the timer.cancel service. If the timer ever goes off, that means that the script didn’t get a status update from Ring noting that the alarm mode has changed. I have yet a third automation that fires a message on the home/alarm/check topic every time the timer.finished event is triggered. That way, I don’t have to think about resyncing the mode. It should just automatically get resynced within 30 seconds of me trying to set the alarm mode.

Alternatively, you could just have a switch in your front-end that lets you fire this home/alarm/check message if you ever notice it getting out of sync.

1 Like

Yeah, my Raspberry Pi is using the newest version of NodeJS since that is what was recommended. Tried the updated script and it works now. Thanks for the update!

Alright! I ordered a new Pi and all the trimmings; set it up with Raspian Stretch Lite; installed all required libraries; pointed the script to my MQTT broker in hass.io, and…IT WORKS! I am able to see ALL my Ring Alarm devices (contact sensors, motion sensors, and alarm station). I am able to change their state in HA. HA is update when their state changes manually. And using Node Red, I have created a rather lovely automation to turn on my patio lights based on contact sensor and motion detection (Ring Doorbell Camera). I am loving this, and I cannot express how thankful I am to you, @acolytec3 for taking the time to work this up in its current format.

LET THE AUTOMATING BEGIN!! :laughing:

Has anyone had any success trying to run this in a Docker container? If so I’d love to hear how!

I fooled around trying to run it in a Raspbian Stretch docker container via the Portainer add on (in order to be able to run it on the same Pi as my hass.io install) and I’m getting an error. Note that this is probably because I have basically no idea what I am doing when it comes to Docker or MQTT and I’m probably missing something obvious.

Error: Connection refused: Not authorized
    at MqttClient._handleConnack (/ring-alarm-HA-plugin/node_modules/mqtt/lib/client.js:920:15)
    at MqttClient._handlePacket (/ring-alarm-HA-plugin/node_modules/mqtt/lib/client.js:350:12)
    at work (/ring-alarm-HA-plugin/node_modules/mqtt/lib/client.js:292:12)
    at Writable.writable._write (/ring-alarm-HA-plugin/node_modules/mqtt/lib/client.js:302:5)
    at doWrite (/ring-alarm-HA-plugin/node_modules/mqtt/node_modules/readable-stream/lib/_stream_writable.js:428:64)
    at writeOrBuffer (/ring-alarm-HA-plugin/node_modules/mqtt/node_modules/readable-stream/lib/_stream_writable.js:417:5)
    at Writable.write (/ring-alarm-HA-plugin/node_modules/mqtt/node_modules/readable-stream/lib/_stream_writable.js:334:11)
    at Socket.ondata (_stream_readable.js:639:20)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)

Cool, glad to hear it’s working for you. One thing I will note for folks doing this with Hass.io though I suppose it really applies to everyone, you are opening up your MQTT broker to access to clients outside of the HassIO docker container. This means that notionally, any client can access your MQTT broker and there’s a risk, though very small, that if someone had access to your network, they could just publish the “home/alarm/command” topic with an OFF message and turn your alarm off. I don’t write this to make anyone anxious but just make sure you’re practicing good network security (i.e. don’t leave unsecured ports on your router, etc).

1 Like

I’m assuming it is possible to implement MQTT password authentication to the Ring Alarm script correct? Mosquitto and HomeAssisistant accept passwords as far as I’m aware.

It is possible. I just edited the js file and made an options object containing username and password. I sent that, along with the mqtt url to the mqtt.connect() method.

1 Like

So anyone looking, these are the changes I made inside mqttAlarm.js:

const mqtt = require(‘mqtt’)
const client = mqtt.connect(process.env.MQTT, {
username: ‘username’,
password: ‘password’
});

1 Like

I added these to the script and you should be able to populate them in your mqttAlarm.sh startup script (or in mqttAlarm.js) if so desired. I haven’t tested this yet other than to verify that leaving the mqtt credential fields blank in the script works with my current setup (where my broker doesn’t require authentication).

1 Like

Just setup a virtualized Debian in Proxmox and got this working, Thanks for all your hard work!! Now I just need to figure out how to have it auto start if Debian reboots.

Hi would you be able to share how you made this work in hass.io? Where in the config directory did you copy the mqttAlarm.js file?

Thank you.

Currently, in order to get this to work with hass.io, you are going to need to be able to run the Ring Alarm script separate from your hass.io installation (so, a separate RPi, or other VM, etc.), and point the Ring Alarm script at your MQTT server.

1 Like