doing something when status changes from off to on

Moderator: leecollings

Post Reply
Evelen
Posts: 234
Joined: Thursday 09 July 2015 12:03
Target OS: Linux
Domoticz version: 2.4538
Location: Norway
Contact:

doing something when status changes from off to on

Post by Evelen »

In blockly it is easy to do somthing when a switch is on, or off, but what if I want somthing to happen if the switch is changed from eg off to on.

why? because if i eg want to receiv a E-Mail when a switch is turned on i will be spammed with emails if i use "if on"
alfred_j_kwak
Posts: 110
Joined: Friday 20 September 2013 18:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.3530
Location: Finland
Contact:

Re: doing something when status changes from off to on

Post by alfred_j_kwak »

Have you tested how it really works?
jannl
Posts: 673
Joined: Thursday 02 October 2014 6:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Geleen
Contact:

Re: doing something when status changes from off to on

Post by jannl »

You can check the lastupdated time, you can create an additional virtual switch to check the status change.
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: doing something when status changes from off to on

Post by Egregius »

In my scripting I 'memorize' when the last message is sent. I then only sent a new one if a certain time has passed. Like when someone presses the doorbell 3 times I only get 1 notification.
I would also suggest looking for another notification system than email. I believe Telegram or Pushover is way more suitable for this.
Evelen
Posts: 234
Joined: Thursday 09 July 2015 12:03
Target OS: Linux
Domoticz version: 2.4538
Location: Norway
Contact:

Re: doing something when status changes from off to on

Post by Evelen »

alfred_j_kwak wrote:Have you tested how it really works?
yepp, tested with smoke-detektor and "email if PANIC".
jannl wrote:You can check the lastupdated time, you can create an additional virtual switch to check the status change.
how can i do this in blockly?
Egregius wrote:In my scripting I 'memorize' when the last message is sent. I then only sent a new one if a certain time has passed. Like when someone presses the doorbell 3 times I only get 1 notification.
I would also suggest looking for another notification system than email. I believe Telegram or Pushover is way more suitable for this.
how do you memorize this using blockly?
this is a good solution in your example with doorbell, but not if i want a notification when a light is tuned on (and it stays on for many hours, for example)

But yes, I will try Telegram or Pushover :)
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: doing something when status changes from off to on

Post by Egregius »

I wrote 'In my scripting' ;)
I don't use blockly, only php.
In php could be as simple as:
if($switch=='On'&&$switchtime>time()-60) telegram('switch X On');
jannl
Posts: 673
Joined: Thursday 02 October 2014 6:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Geleen
Contact:

Re: doing something when status changes from off to on

Post by jannl »

lastupdate is in the forum or in the wiki somehwere.

Create a virtual switch
set it to on when e-mail sent and check if it is on and do not sent in that case
set the virtual switch to off when the concerning switch is set to off
alfred_j_kwak
Posts: 110
Joined: Friday 20 September 2013 18:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.3530
Location: Finland
Contact:

Re: doing something when status changes from off to on

Post by alfred_j_kwak »

Ok. So I don't understand the question. I have belived that all the switch action is event based and event occures only when switch is status changes so notification is send according change not state.
My bad.
jannl
Posts: 673
Joined: Thursday 02 October 2014 6:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Geleen
Contact:

Re: doing something when status changes from off to on

Post by jannl »

I use lua, not blockly.
When an event is fired, all device lua scripts are run. It is up to the script to react or not.
alfred_j_kwak
Posts: 110
Joined: Friday 20 September 2013 18:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.3530
Location: Finland
Contact:

Re: doing something when status changes from off to on

Post by alfred_j_kwak »

Yes. But if in the beginning of your Lua script you check 'if devicechanged...' and so on it does trigger only with edge not from state? I understand that OP get spam emails from solid state and that's what confuses.
jannl
Posts: 673
Joined: Thursday 02 October 2014 6:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Geleen
Contact:

Re: doing something when status changes from off to on

Post by jannl »

Devicechanged is only for the device that triggered the event scripts
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest