Protection for window cover when window is open

I have several window roller shutters and windows that opens to the outside of the house. So when I control the cover by Home Assistant or it is triggered by some automation, I don't want to let the covers go down when the window is open.

I have Aqara Zigbee window sensors. But they are not reliable for me. I think that every battery controlled sensor is not reliable.

So I have buy some hardware: Arduino Uno + Ethernet shield + RTC module + wired reed sensor.

What the plan was is that every second the Arduino checks the reed sensor and sends the information if the window is open or close by publishing a topic to my MQTT broker. In Home Assistant I have ofcourse a MQTT sensor. Also I wanted to send the real time with the message, so I can see how old the sensor state is.

So with the using of NTP and the RTC module I wanted to setup the time. But the problem is that the Arduino Uno in combination with the ethernet shield and the RTC module is not working correctly. The ethernet shield is using SPI and the RTC module I2C but they don't work together correctly.

So the plan changed.Now I only publish every second the state of the window (open or closed). In Node Red I check when my topic of the window state is received --> I set a flow variable with the current date time. (Unfortunately I can't use some informaton from the sensor of Home Assistant like last_updated because that is only updated when there is real change of the state of the sensor)

In Home Assistant I have a cover template that redirects the close and set cover position to a Node-Red trigger. In this flow I check if the window is open AND if the last received MQTT topic about the window sensor is not older then some seconds. Then it is safe for me to execute the command which lets the roller shutter goes down.

I don't now if my algorithm is to heavy for the load of the systems and the MQTT broker (to send every second a topic).

For this project I wanted to have an ethernet connection instead of a Wifi connection because I think it is better. But maybe a Wemos D1 Mini will work with my RTC DS3231 module so I will try this also when the Wemos is delivered.

I'm also looking at the ESP32-POE-ISO. This board has ethernet built in and much faster processor and more memory. Maybe this is one will work with the RTC module.

Another thing: I have also tried to implement a REST API server on the board. So that in the Node-Red flow in stead of checking how old the lasted received window sensor is, I execute a get to get the ACTUAL state of the sensor. But the rest api server (aRest) was also not working in combination with the mqtt publish construction.

What do you think? Is my approach correct or should you do this totally different?

Have you checked their RSSI to the controller. It is possible you need a repeater, I've seen this with the Zigbee TRV's that the Wiser smart heating system uses. Some of the TRV's regularly drop out and then come back 30s later. I need a repeater but the cheapest one for me would be from Ikea and we are on lockdown at the moment. It isn't much of a problem for the Wiser system as it auto-recovers but it does tend to run the batteries down faster.

Not the way I would go. Why an Uno+shield when you can simply use an ESP8266. I think that even an ESP32 would be better value. Using WiFi of course rather than wired so maybe that is an issue for you?

Also, I don't think you need an RTC module, there are plenty of NTP examples for Arduino, I use it on all of my ESP devices and I've never had an issue. I think it might only be an issue if you expect Internet to be down for considerable periods. Even then, I would set up an NTP repeater service on your home controller (a Pi?) and get the devices to sync to that. Having all devices time-sync'd is more important than having them absolutely correct.

A bunch of msg's at once per second shouldn't trouble anything. Certainly the broker, even on a Pi, can cope with thousands of msgs per second. This is running on a PC but I've previously run similar loads on both a Pi2 and a Pi3:

I can't help thinking that you are over-complicating things?

If you have a microprocessor, you can send whatever MQTT messages you like. So have one that only gets sent when the window changes status. But have a heartbeat msg that is output every 30-60 seconds. On that one, use an LWT so that the broker automatically marks the device as being offline if it doesn't receive another message in the given timescale.

I always use a heartbeat for all of my sensor platforms and for any switches that have the capability.

An RTC seems complete overkill. NTP should be enough in nearly all cases. Just give it a bit of time to start up. Set up an NTP service on your controller if your Internet is unreliable.

For the back-end flow, if a window sensor goes offline, use Telegram or similar to get a warning so that you can go fix it and save the state to a flow variable. In your shutter check, test both for the window being open and for whether the sensor is online.

I think I agree with @TotallyInformation, using the ESP family of products would also be my choice. If you want them all integrated in HA (Home Assistant), check out ESPHome, so simple, so powerful. Myself I jumpstarted with ESP32's, never used the smaller ESP8266. At least with the ESP32, you can connect several window sensors to just one ESP32 if the windows are located close enough. No need for RTC modules, you get the correct time & date via wifi connection, simple power supply, no batteries needed, UPS eventually if you have such requirements

Hi @TotallyInformation

I don't know where I can found the RSSI? In Home Assistant I don't see this attribute and I don't see it in the deCONZ software (the Conbee II stick). I don't think it has something to do with the distance because the sensors were on the same table and same distance and only 2 sensors were not working. You say that at your site they drop off and come back automatically. Here I must press the button to get the sensor a live. So very strange.

The reason of using the Arduino UNO was the option of the ethernet shield. But I have to say that you are right it is the wrong choice to use this board (to little memory, slow speed, etc..) I know the ESP8266. The problem is that it have only WIFI and I prefer ethernet. (But I have ordered some Wemos D1 Mini clones from AliExpress because of the ridiculous price of € 1,48 a piece). For some places in the house I have to say that Wifi could be a serious option. I have also orderd the Olimex ESP32-POE-ISO (WIFI, Ethernet (POE) and bluetooth). It cost some money but it has all options you would have.

The reason for the RTC module was that I could set once the time which I gets from a NTP service and then using the time delivered from the RTC module. So in my loop I have the time directly without waiting on the NTP service (which sometimes fails at my site and in the examples they wait some seconds to retreive the packet which means that the loop of checking inputs is on hold for that period).
But your idea about the NTP repeater service (I think the chrony add-on is usable for this?) is a good idea.

So if I understand you well:

  • you send a topic when the your microcontroller board is starting
  • you send a topic when the state of the sensor is changed
  • you send a topic every 30-60 second to let the system know that the sensor is a live

Maybe I over-complicate things. But I don't want to have my roller shutter crashes against my windows. Yes my roller shutters has obstacle detection but I don't want to happen this. So I wanted realtime check of the sensors.

LWT sounds interesting. I will investigate this how it works...

If so, and to be really safe-guarded, I would never trust a only-software-based blocking solution. The window switches should really be in serial with some control signal wire to the roller engine, blocking movements as long as the window is open