Use scene or luup to turn off device

I have a current veralite G running a number of devices on a house that i monitor remotely. The system includes an older Vision In-Wall Z-Wave Micro Switch with 2 relays controlling a pond aerator and a pump. It generally works really well however we had a significant thunderstorm last night and in the morning both relay channels were on likely due to a power glitch. I’ve noticed this happening before albeit our thunderstorm season lasts only a month in late summer.
I’d like to prevent this if possible. I currently have a simple scene that turns these devices off on the hour between 10pm-4am. The scene works but is inelegant and the devices are running needlessly for at least an hour.
What i would like to do is toggle these devices off during a set time period. While I can use the device’s on state as a trigger to turn itself off, it’s not apparent that this can be limited to a fixed time period. Can this be done with a scene setup or does it require I learn Luup? Is there a plugin that could help instead?

Reactor will definitely do it with no code.

Code in this particular case is not complex. There a lot of samples in the forum. Just put the code in your scene, and the scene will run only if it’s returning true.
Let’s say you want to run it only at night:

return luup.is_night()

If you want to run only during the day, just invert the condition.

ok, many thanks. I look in to reactor. As to adding luup code to a scene would it look like the following pseudo logic

trigger if device comes on
respond with turn device off with luup check on time. If outside time bounds do nothing.

Will the luup code run before response?

It goes
trigger ( a device or time etc)
lua code ( must return true to continue)
actions

1 Like

ok, i setup a scene that triggers whenever 1 of 3 devices comes on. The response is to turn off all these devices subject to some luup code. The code checks if this event happens between 7am and 10pm. If it does it should terminate the response otherwise continue response. Currently setup to return nil as false generates a error. However, nil doesn’t work correctly either although it executes ok. I’ve set myself up to look at the logs so the logic is ok, just the return handling looks bad?

current_hour = os.date(‘*t’,os.time())[“hour”]
if (current_hour > 7) and (current_hour < 22) then
return nil
else
return true
end

Best when posting code is to put it between backticks, as the forum will replace the quotes, meaning anyone copying your code will have to replace all quotes.
```
code
```

you need to set the variable local, unless you want a global variable.
local current_hour = os_date('*t',os_date())["hour"]

Also best just to return false rather than nil

ok, thanks. “nil” runs on test luup page but “false” does not. However, “false” appears to run fine in actual fact. Don’t know why it’s not getting past the code check on the test page.

Making this change fixed things. However, the scene didn’t appear to handle multiple devices well as the trigger or response. Making multiple copies of the scene works regardless. Now the test will be if the system works in a power surge…

jamal, you should really look at Reactor. It is more reliable than vera scenes, it will survive luup reloads. You can do more complicated logic very easily.

next project. I have reactor installed and found all the help info, just need to fit it in. Lua looks enough like python that i thought it would serve in the short term. Anyway, thanks for all the help.

No need to create different scenes. Triggers are by default OR, so any of them will execute the scene.