Email when sensor still ON after some time

Discussions about Z-Way software and Z-Wave technology in general
Post Reply
xurg
Posts: 10
Joined: 17 Aug 2020 22:38

Email when sensor still ON after some time

Post by xurg »

Running 3.1.0, email notification seems to be working. But here's my problem: I want to realize a seemingly simple task, and that's watching a door sensor and when it's been open for longer than X seconds, I want to send an email notification. A simple If-Delayed-Then doesn't work, as it will always take the action even if the source sensor has gone back to OFF. I then tried a attaching a dummy sensor to If-Delayed-Then to be able to take it back on Else. But when it triggers the (new notification system) email, the mail is sent repeatedly. It seems my sensors are stuck in ON position and so the engine repeatedly triggers the Email action. How best stop such cycle from happening while the root cause (sensor) is still active?

So I think I'm approaching this wrong, but in what way? Surely a simple task like this must be solvable easy without needing 3 rules and a dummy device!? I'm absolutely willing to read and I tried, but did't find help in the ZWayManual.pdf (which also does not seem to cover the new Automation Tasks screens, btw.)

Any help or pointers greatly appreciated!

User avatar
PoltoS
Posts: 5814
Joined: 26 Jan 2011 19:36

Re: Email when sensor still ON after some time

Post by PoltoS »

I would use EasyScripting with the following script:
## ZWayVDev_zway-XX-YY-CC // (select the sensor from Events menu)

if (vdev("ZWayVDev_zway-XX-YY-CC").value() === "on") {
setTimer("myTimer", function() {
vdev("NotificationSend_xxxxx").on(); // This scene should be created using Notification Send app with corresponding notification channel selected
}, 10)
} else {
stopTimer("myTimer);
}

xurg
Posts: 10
Joined: 17 Aug 2020 22:38

Re: Email when sensor still ON after some time

Post by xurg »

Thanks for the response. I haven't looked at EasyScripting yet - I was somehow hoping to solve this with more traditional means. :-) I understand your E/S code, but out of curiosity, what would be the scene/conditional approach to this? More precisely: what is the best practise to cancel a timer? I always thought stuff like this is the core of all these smarthome things.

User avatar
PoltoS
Posts: 5814
Joined: 26 Jan 2011 19:36

Re: Email when sensor still ON after some time

Post by PoltoS »

Exactly canceling the timer is the corner stone that pushes to write scripts or make own app that implements this logic

xurg
Posts: 10
Joined: 17 Aug 2020 22:38

Re: Email when sensor still ON after some time

Post by xurg »

Ok, fair enough.

FWIW, here is my EasyScript based on your suggestion. I fixed the syntax and changed the looks a bit but it's basically the same. I tied a hardware sensor to a dummy device and monitor that so I can more easily test the setup.

Note: it is critical to place the timeout id in "self" so it lives long enough to reach the clearTimeout called in the release/off trigger event.

Thanks again. I was never a friend of all that scene and IFTTT stuff so regular coding like this really feels like home again.

Any chance to get the UI editor working with Firefox?

Code: Select all

### DummyDevice_11
if (vdev("DummyDevice_11").value() == "on") {
    self.myTimer = setTimeout(fn, 15*60*1000);
    vdev("ZWayVDev_zway_2-0-37").on();
}
else {
    clearTimeout(self.myTimer);
    vdev("ZWayVDev_zway_2-0-37").off();
}

function fn() {
        vdev("NotificationSend_9").on();
}

User avatar
PoltoS
Posts: 5814
Joined: 26 Jan 2011 19:36

Re: Email when sensor still ON after some time

Post by PoltoS »

We have not invested much in checking FF - too much headache and we like Chrome... Actually the code is open, you can dig into ;)

https://github.com/Z-Wave-Me/home-autom ... /htdocs/js
The postRender.js is minimized (beacuse this is the only way this crazy part accepts JS code - in one single string only) and the code is in the other file with compile script. Your pull requests are welcome! If not, we have this in the huge TODO, but with many more prior tasks

xurg
Posts: 10
Joined: 17 Aug 2020 22:38

Re: Email when sensor still ON after some time

Post by xurg »

I used to like Chrome too, but, well, Google.

Anyway - even with storing the timeout ID in self, I still get email notifications so the cancellation does not seem to always work. I had done my testing with short events, but in the real world the on/off events are apart by a couple of minutes, usually. What is the lifetime of the object? Do I need to store the id anywhere else?

Post Reply