Page 1 of 1
doing something when status changes from off to on
Posted: Thursday 31 December 2015 9:19
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"
Re: doing something when status changes from off to on
Posted: Thursday 31 December 2015 9:30
by alfred_j_kwak
Have you tested how it really works?
Re: doing something when status changes from off to on
Posted: Thursday 31 December 2015 9:40
by jannl
You can check the lastupdated time, you can create an additional virtual switch to check the status change.
Re: doing something when status changes from off to on
Posted: Thursday 31 December 2015 9:59
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.
Re: doing something when status changes from off to on
Posted: Thursday 31 December 2015 10:05
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

Re: doing something when status changes from off to on
Posted: Thursday 31 December 2015 10:09
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');
Re: doing something when status changes from off to on
Posted: Thursday 31 December 2015 10:12
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
Re: doing something when status changes from off to on
Posted: Thursday 31 December 2015 12:28
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.
Re: doing something when status changes from off to on
Posted: Thursday 31 December 2015 12:37
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.
Re: doing something when status changes from off to on
Posted: Thursday 31 December 2015 13:37
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.
Re: doing something when status changes from off to on
Posted: Thursday 31 December 2015 13:58
by jannl
Devicechanged is only for the device that triggered the event scripts