I’m doing a simple solar tracker and using LDR, I know this is not optimal but fun little experiment. I have 4 automations for left,right and tilt. The problem I have when tilt up/down that I do with linear actuator connected to 2 relays. I tought this automation would work as a very simple closed loop but the relay stay on until its all the way down/up when it should stop when no difference between LDR. Do you have any idea why the relay stay on even if I tell it turn off in the end?
This is the template I use to trigger and as condition:
{{states('binary_sensor.test_platform_2_lower_left') == "off" and states('binary_sensor.test_platform_2_upper_left') == "on" and states('binary_sensor.test_platform_2_upper_right') == "on" and states('binary_sensor.test_platform_2_lower_right') == "off"}}
First of all, You’re in an Esphome channel and neither your question, your automation or your template are Esphome related so you’re in the wrong place. You’ve left out any information about your esphome yaml so we can try to figure out why you are using a binary sensor for an LDR which isn’t a binary sensor at all. Binary means 1 or the other or On/Off and it’s used mainly for digital High/Low signals. An LDR isn’t an On/Off type sensor, It’s a sensor and it’s resistance changes based on light levels and it outputs a numerical value not a High/Low so there’s your main problem. The other issue is it looks like you don’t quite understand the basics of how a solar tracker works. You need at a minimum 2 templates. One for your up/down or North/South axis which would be your seasonal adjustment and the other is your East/West axis that will follow the sun during the day. Each of these sensors should be comparing their opposite LDR, so E and W should be compared against each other then N and S compared and resistance decreases as light intensity increases which tells you which way you need to adjust the panel. Comparing all 4 at the same time isn’t helpful information and none of this is helpful unless you add a minimum maximum difference or a time delay or else your solar tracker is going to act like it has a seizure disorder and never sit still.
Now they do have LDR sensors that come on a pcb with a trim pot and you can set them up as a digital or analog sensor. If that’s what your using, which you didn’t think was important enough to specify in your OP. A binary sensor could work for that, although it wouldn’t be my first choice. Everything else I said still applies with this sensor as well.
I have LDR on PCB indeed, so you would compare just LDR Upper Left and Lower Left, how would your automation look for this application, as I said have very limited experience with HA and automations.
You should have 4 LDR’s I assume? This is a dual tracker? You’re LDR’s should be oriented E/W N/S. You’re E/W are going to be the primary tracking direction because the sun travels E/W and N/S will be for changing the angle with the seasons when the sun is higher or lower. In a simplified explanation, to track the sun you’re going to need to compare E-LDR and W-LDR say every 15min and if the difference is more than let’s say 10 then you move your tracker untill the difference is say, less than 2. You want E and W to be the same ideally. The problem with using LDR’s is you have to deal with bad weather, night time, a random cloud shading the LDR’s and causing false movements.
You just need to break the project down into individual steps and then work on one step at a time. Work on getting E/W readings and how big of a difference do you need before you move the panels. You have to make it manageable so you can work through it.