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?