What is the best way to create an automation to close covers automatically every day when below some lux or at a maximum time?

I need an automation to close my covers everyday when my lux sensor outside gives a value of <= 5 lux or at the maximum time of 22:30.

I have this automation created in Node-RED:

[{"id":"424560624253eb90","type":"tab","label":"Cover close","disabled":false,"info":"","env":[]},{"id":"7f5beb7ea980fbd6","type":"inject","z":"424560624253eb90","name":"Every day at 22:30","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"30 22 * * *","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":360,"wires":[["f12d5513ead28e53"]]},{"id":"87730bdc16333d21","type":"poll-state","z":"424560624253eb90","name":"'Zijraam' lux <= 5","server":"63f26c18.71f4f4","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"updateinterval":"1","updateIntervalType":"num","updateIntervalUnits":"seconds","outputinitially":false,"outputonchanged":false,"entity_id":"sensor.zijraam_woonkamer_lux","state_type":"num","halt_if":"5","halt_if_type":"num","halt_if_compare":"lte","outputs":2,"x":120,"y":140,"wires":[[],[]]},{"id":"1d5adca0d40aa403","type":"server-state-changed","z":"424560624253eb90","name":"'Zijraam' lux <= 5","server":"63f26c18.71f4f4","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.zijraam_woonkamer_lux","entityidfiltertype":"exact","outputinitially":false,"state_type":"habool","haltifstate":"5","halt_if_type":"num","halt_if_compare":"lte","outputs":2,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":140,"y":300,"wires":[["f12d5513ead28e53"],[]]},{"id":"f12d5513ead28e53","type":"switch","z":"424560624253eb90","name":"Are the covers already closed by this automation?","property":"covers_are_closed","propertyType":"global","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":510,"y":320,"wires":[["af86c1158c42df32"],["d3e80ca09ba18180"]]},{"id":"1164530c3b420d1e","type":"inject","z":"424560624253eb90","name":"Every day at 15:00","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"00 15 * * *","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":540,"wires":[["db3b231efe5e61a6"]]},{"id":"db3b231efe5e61a6","type":"change","z":"424560624253eb90","name":"Reset global variable covers are closed","rules":[{"t":"set","p":"covers_are_closed","pt":"global","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":540,"wires":[[]]},{"id":"7b6f15afe3b93fe8","type":"debug","z":"424560624253eb90","name":"Close covers","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1170,"y":380,"wires":[]},{"id":"af86c1158c42df32","type":"debug","z":"424560624253eb90","name":"Covers are already closed","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":890,"y":280,"wires":[]},{"id":"d3e80ca09ba18180","type":"change","z":"424560624253eb90","name":"Set global variable covers are closed","rules":[{"t":"set","p":"covers_are_closed","pt":"global","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":930,"y":380,"wires":[["7b6f15afe3b93fe8"]]},{"id":"c4d23ee7b48fc029","type":"comment","z":"424560624253eb90","name":"Poll every second","info":"","x":130,"y":100,"wires":[]},{"id":"63f26c18.71f4f4","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]

So I use a global variable which is set when the lux value is <=5 or at 22:30. This global variable is reset on 15:00.

Is this best way to do this? (I don’t fetch the positions of the 10 covers because it is not always up-to-date, because the Somfy cloud integration is not always working perfect and also in combination with controlling the covers with wall remote control units).

If you need it to be safe against restarts, either an input helper or saving your global in storage will do it.

EDIT:

another solution is exposing to home assistant the lux node. That’ll create a switch in HA that you can turn on and off at will. This is safe against restarts too.

I deleted the Throttle suggestion because it even gets crapped with a regular deploy rendering it pretty much useless for long timespans like the one you are proposing.

Okay I was forgotten that. Now it is restored and save from/to file

Why do you have that Poll State node at the top?

The poll node was my first choice, but the events state is better to use. So I have to remove it.

There is one little issue left: there is of course a small chance that the system is just restarting at the time when the variable should be reset, so that the variable will not be reset and that the covers are not closed. So maybe it is good to reset the variable on multiple times and not once at 15:00?

Ok, that makes sense then.

Now the question is why you look at lux to close the blinds.
Usually lux will be used to control the blinds continually, so the light in the room stays the same.
Closing the blinds for the night is usually based on the sun instead, since the sun is not as fluctuating as lux. A single dark shortlived thunder cloud might close the blinds at 10 in the morning.

I use sunset/sunrise for my lights and first I wanted to use it also for closing my covers.

But I don’t like it, because when it is a sunny day (no clouds), it starts to early and when it is a rainy/cloudy day, the trigger is too late.

With the lux value it is always the same condition.

I agree that this could be an issue, but I have to check which lux value it is and maybe I could combine the lux value with the sunset time.

Limiting the time where the flow is active might be a good idea, like the period of sunset ± some chosen time, because you might also experience issue with a clear night sky and a bright moon, especially if its in the winter and it snows in your area.

Besides that you could call the reset when you call the 22.30 closing.
Just make a split in the flow and then maybe set a minute or two delay before resetting the global variable.

That is something that I don’t do that.

My covers are in the morning opened at some fixed times (so no lux and no sunrise). When the variable is reset, that could mean that the covers are closed another time after they are opened at 06:00/07:00.

Can I ask why it is important to check if the covers are already closed by the automation?
Will the covers malfunction if you send a close command to covers that are already closed?

My covers are in the morning opened at some fixed times (so no lux and no sunrise). When the variable is reset, that could mean that the covers are closed another time after they are opened at 06:00/07:00.

Not if you set the automation to only run in the period sunset ± some chosen time. :slight_smile:

The check is to prevent the covers to be closed on times that it shouldn’t be.

I think this is a good solution.