Sonoff ZB Mini R2 Automation problem

I’m hoping someone can help…

I have a Sonoff XB Mini R2, zigbee switch on an automation running 2 porch lights. When the Unifi camera detects motion the lights come on and go off after a minute.

However, when I want them on, say for Amazon delivering in the dark I switch them on to stay on.

The problem is if the camera detects something it starts the 1 min timer from the automation I set. How do I get around this. I want my manual on to override the 1 min automation. Anyone have any ideas?

There are a couple ways to accomplish that, each method has their own limitations…

One option would be to just add a condition to your existing camera-based automation. Have it check if the light is already on using a State condition in the Conditions (aka “And If”) block.

Another, more complicated but possibly more specific, option is to use the context values to determine what turned the switch on.

I would probably set up a separate automation that triggers off the switch turning on, using context. If it is turned on manually, set an Input boolean. Then, in your original automation, check the state of that boolean to determine if the light should be turned off. Make sure you include some mechanism that resets the boolean at the appropriate time.

Thanks. I kinda get that. Could you say how to do it? I’m not very advanced with HA

I mean how I need to add a condition and what to type

This may be over complicated. But I set a trigger for every 5 minutes and then used {{ ((now() - states.binary_sensor.cam_person_occupancy.last_changed).total_seconds() > 300) and states.binary_sensor.cam_person_occupancy.state == ‘off’ }} as a template condition. Really this setup makes my porch light stay on a minimum of 10 minutes. But it does dynamically reset the timer of how long its on if people come in and out.

As mentioned above, there are different ways to do this, but my recommendation:

  • In this “Then do” block, click the blue “Add action” button, and search of “if-then”
  • Then you can add a logic to check whether the light (the ZBMINIR2) being off
  • If off, then execute your 3-step actions
  • Otherwise, there will be no action at all under else

That way, when the light switch have already been turned on manually, your 3-step automation would be skipped.

Sounds reasonable? Hope this helps.

If you can get the above working, congrats!!
If it is not still working as well as you like it to be, let us know where your concerns are, then the next level improvement could be to come back & improve the automation by tackling the context thing that Didgeridrew mentioned above.