My openHab Setup

Some updates.

I’ve finally stabilized my system, and it pretty much runs itself now with little to no interaction required from me.

The first stability/reliability issue I had was that the nature of my house’s currently rather bad wifi (that just stops working randomly, especially on the extenders’ sides. This would cause my Xiaomi Gateways to lose connection, and subsequently all of the sensors connected to them also loses connection. Because most of my sensors are linked to the Gateways, this severely affects the reliability of my system.

Router Wifi Issue
The worst issue with this was often my router (Which is small, and old), that can’t assign static leases to devices, reassigns new IP addresses to the Gateways. This, of course, creates issues because the Gateways binding on OpenHAB uses the IP specifically to connect.
The same happens to my wifi Xiaomi light bulbs, but the Mi Io binding apparently auto-corrects their IP addresses by itself, so no fixes were needed there.

Solution
As for the gateways, I needed a way to fix the IPs automatically. And I found a way!
Its a rather crude rule that runs every 10 minutes.
The rule uses the “ExecuteCommand” command to run a arp on network after a broadcast. Then, in that output I search for the mac addresses of each of my gateways, and then use the nifty REST API of OpenHAB to update the IP’s based on their mac addresses.

This process is surprisingly effective. I’ve not yet even noticed a disconnect issue, because even if the ip’s are reassigned, it fixes it within 10 minutes. If I see this happening I can just increase the frequency.
This, in addition to the new Pi I bought, has pretty much guarenteed me almost 100% uptime for all my systems. Which is great.

OpenHAB Notification Issue
Another issue that I had is with a somewhat recent update of Android, the OpenHAB app notifications seem to have become delayed. Instead of getting instant notifications on my gate or garage opening, or doors being open, the notifications are held until I unlock my phone.
This made the functionality pointless, as I didn’t have real time notifications on any entrances being accessed.
After many hours of searching, I couldn’t find a solution to fixing the OpenHAB notifications.

So, I went a different route.

Fixing Notifications
I switched to using Telegram. If you didn’t know, Telegram is basically a Whatsapp clone app with the added benefit of allowing you to write bots that can interact with you or other users on Telegram, which is the key functionality I needed.
Using the Telegram Action binding for OpenHAB, I was able to create a bot that can send me message notifications, with immediate result.

This works great, I created a group with everyone in my household, as well as the bot, so that I can ‘broadcast’ messages to everyone or just have the bot direct message me if there is technical notifications.

Other stuff I did

  • I started reading off the illumination lux values from my Xiaomi smart motion sensors, and using it to determine whether I should turn on certain lights. Although they only update the lux when they detect movement, it still allows me to turn on lights when its darker outside in the day.
    So instead of having to worry about detecting a specific weather element, I simply check on motion whether the illumination is low (in the event of a thunderstorm for example), and then turn on the lights until such a time as the illumination is higher again.
    It works pretty good in most cases.
  • I fixed my garage door’s open sensor triggering twice all the time, by turning the magnet sensor upside down, lol
  • I now have the mySQL binding that writes all of my sensor data to a database, and also displays in my weather to show the temp graphs for the last 24 hours. I actually put the backup on a USB drive attached to the Pi, to prevent reducing my SD cards lifetime too quickly.
    Previously I just used mapdb to save the states, but now I do both, for saving the states and to save all my data for historic reference purposes.
  • I’ve started playing around with sensors and stuff connected to an Arduino, in preparation of my weather station project that I’ll start soon. I have a temp sensor just running off a breadboard, that gives me the room temp, and sends it via the REST API to my openHAB system. Works great.

Planned Stuff

  • Update my gate-open notifications to display a camera photo of the gate in the notification (because telegram allows sending images, yay!). Having issues reading the Motion stream from my pi in a single image in openHAB rules though, so still no dice.
  • I am planning on building a Pi-zero-powered Weather station, with wind direction, speed, temp, humidity, rainfall detection and rainfall gauge. I will report all of this information to my OpenHAB. I might also make a online single page readout of this information for my community to get the most accurate readings close to their homes.
  • I want to mount a lcd screen on my wall in the hallway, and use it to display a custom HUD I’m writing in html/javascript/css to display various sensors’ information from openHAB (again using the useful REST API to draw data directly from openHAB).
  • Future future plans include: A sensor to detect mail in our mailbox, a camera mounted in cement or maybe high up at our gate to read number plates of cars that stop there and notify me who stopped in front of my gate, and more!

Anyway that’s it for now. I’m kind having some financial woes right now (had to fix our roof for a hefty price), so I can’t do all the stuff I want to right now, but hopefully later in the year I can buy some more sensors and cool stuff and get back to it.

1 Like

Hi .
thanks for the update.
thought you disappeared LOL

I lurk around occasionally haha

I used the same approach a long time ago to keep track of the IP addresses of my Rokus. Since I’ve started assigning static IPs from my router/firewall I haven’t used it, but I can confirm, this technique is a good one.

If you haven’t already, you might consider moving your mapDB files to the thumb drive too. As every time there is a state change or update (depending on your strategy) it generates a write. To do this, move /var/lib/openhab2/persistence/mapdb to the thumb drive and then create a soft link from the new location back.

Though be aware that a thumb drive is also flash so it has the same problem with wearing out. This approach buys you some time and probably ensures that the thumb drive wears out before your OH config does. But you should still set up a good backup strategy for your database. When a flash drive fails, it does so silently.

The file corruption problem when the computer loses power is also still a concern so battery backup for your server would be a good idea.

Of course, if you don’t really care if you lose this historic data, don’t worry about it. I don’t back up my persisted data. If I lose it all, I’ll be back to mostly functional (charts and such) within the hour.

Please post your progress as you go on that. I know a lot of people have interest in building their own too. It would be an interesting thread to read.

Most people I’ve seen address this outside of OH in a python script or something and puts the image in $OH_CONF/html I think. There are several threads on the forum that talk about it.

Sounds like you are making excellent progress. Good luck!

Yeah, my plan is to have a script update the database itself to a more permanent storage solution daily or weekly. I just use a flash drive so that when the drive fails, I can restore the backup onto a new drive without having to reinstall and setup my OpenHAB setup itself (though I suppose I can back that up too).
I actually did not even think of the Mapdb also writing to the sd card, I’ll see if I can move it to the flash drive this weekend.

I will most certainly do so. At the moment I only have a few of the parts, but I’m planning on buying the pieces slowly over the coming months, and then building it in one go. I’ve got a Pi Zero, a temp and humidity sensor and the waterproof container to store them in. I’ll post some details on this project soon!

I’ll take a look. I know I can ask Motion to save a snapshot in an image format, so perhaps I can then move that to the html folder of OH and access it from there. Will look around on the forums for some info. Thanks.

Thanks. I’m having a lot of fun with this.

Here’s a summary of what I have up and running thusfar:

  • 10 Xiaomi Phillips Smart Bulbs
  • 5 Xiaomi/Aqara Door sensors (including one on my gate and one on my garage door)
  • 10 Xiaomi/Aqara Motion sensors
  • 9 Xiaomi Wireless Switches
  • 3 Xiaomi Gateways that all the sensors connect to
  • 2 operating Sonoff switches (both on lights) (I have 2 more I’m going to use soon)
  • A Rasberry Pi 3b, that runs my OpenHAB installation.
  • Another Rasberry Pi (2b) that runs Motion
  • A cheap chinese-knockoff AHD DVR that runs 3 exterior cameras, and streams it to my Motion-Pi
  • An arduino, powered by the Motion Rasberry Pi, that has a temp and humidity sensor connected to it. I also, for the fun of it, have a LCD display connected to the Arduino, indicating the current temperature in the room. I’ll post a picture tonight.
  • My Router, both Pi’s as well as some room lights and my computer is powered by a 400aH UPS (4x100aH) Inverter that makes sure my system never goes off even with the surprisingly frequent power outages in my country.
3 Likes

Could you please give a brief overview of how you’re using these in rules and to detect motion? I tried tracking motion throughout the house with them but it constantly crashes cron. My (unsolved) thread Help understanding quartz crashing - "Worker thread was interrupt()'ed."

Well, in my case its a bit easier, though somewhat less accurate than a more manual system.
The Xiaomi and Aqara Motion sensors report more than just motion to me, so I have more info to work with without calculating it myself.

So whenever they are updated I receive a Motion On/Off, as well as a DateTime for Last motion received.
However, the sensors also have a neat little automatic ‘off’ on them, which I can set a timer for. This trigger turns the motion sensor detection status to off after a set number of seconds. This allows me a bit more control, and I don’t have to ‘recheck’ the status of motion. However, to spare battery life, these sensors only detect motion every 1 minute. So the big drawback is that if I walk into a room and out again, I have a minimum of 1 minute where I don’t know if there’s someone still moving.

But, I digress. How I use my sensors for automatic lights:
Automatic Bathroom Light

  • In my bathroom, I have 2 sensors to cover the whole bathroom.
  • Aqara’s sensors include an illumination sensor, so they report the LUX value to me (sadly, only when they detect motion in most cases).
  • Both sensors are set to turn off at 65 seconds (to cover the minimum delay in checking again).

Operation
Whenever one of the sensors have a change in status (OFF or ON), I check both sensors’ values, and if either one is ON, and the lux is low enough (or it is ‘night’), I turn on the bathroom light.

What makes mine easier with Xiaomi sensors, is that I don’t have to periodically check whether there is still motion. After 1 min, the sensors will check again, and if there is motion, the ‘timeout’ is refreshed, otherwise, it turns off after the elapsed timer expires (which is in the motion sensor logic, not my rules).
So I just check on a change in either of the sensors’ motion detected status, and turn the light off again if both are off.
Rule:

rule "Bathroom Door or Main Sensor Triggered"
	when
		Item Motion_BR changed or
		Item Motion_BR_Door changed
	then	
		if (Motion_BR.state == ON || Motion_BR_Door.state == ON)
		{	
			if (!DayMode && Light_BR.state == OFF)
			{				
				Light_BR.sendCommand("ON")		
			}	
			if (DayMode && Motion_BR_Door_LUX.state < 9 && Light_BR.state == OFF)
			{				
				Light_BR.sendCommand("ON")		
			}			
		}
		else if (Motion_BR.state == OFF && Motion_BR_Door.state == OFF)
		{			
			if (Light_BR.state == ON && !BathroomLightOn)
			{	
				Light_BR.sendCommand("OFF")	
			}
		}
	end

I use this same type of rule for all of my automatic lights.
I can also, if necessary (didn’t have that need yet), use the “Last Motion Detected” date and time to calculate how long ago there was motion, without having to actually manually track it.

I checked your thread, and I’m not 100% sure I understand the purpose of the rules, but I think you want to have items that tells you how many minutes ago there was motion on each motion sensor? I’ll read it more thoroughly, and see if I can give you any advice there, but off the top of my head, perhaps storing the current date and time in an item when motion goes ON, you can use that to calculate when last you had motion on that sensor/the group. That way you don’t have to use a cron at all to track it, you just statically calculate the elapsed time.

I actually use cron for a few things, and have never had an issue where the cron fails like that, its quite strange to me that it would crash.

1 Like

This is quite a nice thread, nice to see there are others from SA on here.

I haven’t really paid much attention to Xiaomi stuff but I see what you mean about being close to Apple.

I have an existing system of about 30 sonoffs scattered throughout the house, some still being re-installed into the new house through Major Tech Bell press switches bridge out to the pushbutton on the sonoff and Google Home helping turn on and off the lights, TV and Amp. I’m going to change those Sonoffs to Tasmota too when I can source a FTDI locally or import one from ebay or Banggood.

Happy modding all, hope to bounce around some ideas with you guys in the coming months

Well, I am strongly considering starting to switch out most of my Xiaomi devices with Sonoff ones. I’m especially interested in the rf connection ones, because I have a lot of issues with Wifi connectivity, and it feels to me like the rf would be more reliable.

All I need now is an alternative switch type thing (with Xiaomi I have a switch that detects single, double and long presses and sends a trigger to my openHab. So I need something that’s local and doesn’t require the Xiaomi gateway, to prevent Wifi-issues stopping me from turning on and off stuff).

Hi Allen. glad one more South African here.
Have a look at this link. i bought my FTDi from them.

https://www.robotics.org.za/index.php?route=product/search&search=FTDI

Hi Sky.
There is ways to have rules setup in Tasmota to detect and do stuff. with multipel button presses.
will have a look and give you some links.

Thank you. Would be much appreciated!

Thanks!

I buy stuff from them fairly regularly, they’re a real friendly helpful bunch of guys.

My only problem is that I stay in Centurion aswell, and it’s R100 shipping for a R70 item that I could pop down the road to get myself. So it’s on the back burner until collections reopen

1 Like

Hi Guys. hope you are keeping safe.

Surviving thus far!

Same here. the new norm, working from home.