How to Create a Daytime Loop Routine on Sonoff? 🌞

Hey fellow Sonoff enthusiasts,

I’m trying to figure out how to set up a loop routine on my Sonoff device that only operates during the daytime or within specific timeframes. Here’s what I’m aiming for:

I want to create a routine where my Sonoff device loops through a sequence of actions, but I want this loop to be active only during daylight hours or between certain defined times. For example, I’d like the routine to run from 8 AM to 6 PM each day.

Has anyone successfully accomplished something like this with their Sonoff device? I’ve been tinkering around, but I’m not quite sure how to implement this specific condition into the loop routine. Any guidance, code snippets, or suggestions would be greatly appreciated!

Looking forward to your insights and experiences.

Not so far as I know with what I see with my limit knowledge of eWeLink stuff. Only use the HA eWelink web integration and the phone app. You can using the HA (calendar, helpers, timers (HA, Node-Red), automations). YMMV

Prepare two switches A and B, switch B set inching setting on for 1 second and then off (for cyclic connection)

Configure the scenario:
If B is off,
Then turn on A - delay 5 minutes - close A - delay 10 minutes - turn on B,
Effective time period Daily - 8 am to 6 pm

The effect of this setup is that between 8 am and 6 pm every day, Device A is turned on for 5 minutes - off for 10 minutes - on for 5 minutes-…

1 Like

If, for example, it is necessary to turn on the pump cyclically for watering the garden during a certain period of time:

  1. for the device “Pump” in the inching settings, set the duration of the operating time
  2. create the manual scenario “Turn on the pump”
  3. create an automatic scenario:
    if: “pump” is turned off
    Then: delay 10 minutes
    Then: execute the manual scenario “Turn on the pump”.

Set effective period for this the automatic scenario from 8 AM to 6 PM each day.

1 Like

You could use two switches, like some of the comments suggest. I do the following to switch on my driveway lights on a movement sensor, but only during the night. I have a separate switch that control some other lights using sunset/sunrise as the triggers, so I set up this scene:

IF movement sensor is on, AND other lights switch is on (it is night-time), THEN switch on driveway lights

I often use the reliable state of a different switch in an “AND” combination like the above… it works well for me. You could also set an effective time on the scene like @songal suggested. I wanted to make sure I follow the sunset / sunrise time without needing to change the time settings for the effective period as the seasons change.

1 Like

So are you using two actual physical switches then? Or using two “logical command” switches. If two actual switches that is a more expensive way.

Yes, but I had the other switch controlling some lights already on sunset/sunrise. So I did not need to install two switches - I just “borrowed” the state from the one already installed. I must add that I have more or less 60 smart switches controlling many things on a big property. Lights, gate/doors, cameras, pumps, water heaters… We also suffer from load shedding (regular grid switch-off) so I use a lot of conditional switching… IF this and that and that, THEN do the following…

1 Like

This idea is nice! I have got switches controlling lights, like you said.

Wow! This is exactly what I needed.

It is necessary to set another routine to turn the pump on at 6am, right?

I found a bug in ewelink.
Such an automatic scenario turns off at the correct time, but does not turn on at startup. In order to “wake up” the scenario, you must set a wake-up time in the device scheduler that is equal to or greater than the scenario’s start time.

1 Like

Maybe it is not a bug, maybe that period just means the time the scenario works not the time the device turn on.

By the way , I adapted your idea for a different application. I’ve set up a device to turn on and off based on weather conditions. When it’s raining, the weather sonoff turns on, and the pump sonofff’s are not to activate. You can manually set the rainy condition or use IFTTT applets for that.

Can you describe in detail the loop scenario you need

Yes, it’s not a bag. This is the principle of operation of ewelink and other programs with IF triggers. The scenario is executed only when the state of one of the IF triggers changes. Ewelink does not respond to constant, static triggers, even if they are TRUE (device is ON or OFF, but not changes). This problem can be solved by settting wake-up time in the device scheduler that is equal to or greater than the scenario’s start time, and setting the “Power on state” setting to ON (it is necessary to continue to execute the scenario after the power failure and recovery, otherwise, the problem with statistical triggers will occur again.)