Event that acts depending on last status

Moderator: leecollings

Post Reply
royson
Posts: 13
Joined: Friday 10 November 2017 20:56
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Event that acts depending on last status

Post by royson »

Hi!
Im currently running an event that checks the wattage of a wall plug and uses the value to determine if the house is armed or disarmed. I know its an pretty ugly solution but its the easiest way since I cannot get status directly from my security provider =)

Anyway, the event works just fine, the problem is that it runs EVERY hour. Which means I get the same notifications over, and over, and over both when I'm away and at home. Im not sure why but I guess that Domoticz is somehow configured to check all events every hour??

My thought was that I could check the last status of the alarm and that way tell it NOT to send a notification if the status is unchanged. Problem is that Blockly doesnt seem to support that kind of logic. So, does anyone have any suggestions? Im sure I could do this pretty easily with a python script or LUA, but with two small children I haven't had the time to learn any advanced scripting yet.

Any help and suggestions is greatly appriciated!
Best regards,
royson
SweetPants

Re: Event that acts depending on last status

Post by SweetPants »

Take a look at dz_Ventz (https://www.domoticz.com/wiki/DzVents:_ ... _scripting). It has a steep learning curve, but once you master it you will see the advantage over plain LUA and Blockly and the integration with Domoticz. I have converted all my LUA scripts to dz_Ventz and must say it works great.
royson
Posts: 13
Joined: Friday 10 November 2017 20:56
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Event that acts depending on last status

Post by royson »

SweetPants wrote: Tuesday 23 October 2018 20:45 Take a look at dz_Ventz (https://www.domoticz.com/wiki/DzVents:_ ... _scripting). It has a steep learning curve, but once you master it you will see the advantage over plain LUA and Blockly and the integration with Domoticz. I have converted all my LUA scripts to dz_Ventz and must say it works great.
Thanks for the tip, I actually had some thoughts on dzVents and after having another look it seems like a nice way to start.
Im just having some problems getting my logic right as there doesnt seems to be any "last state" command to use.
I would like my event to check if the last state of the switch is the same or not. If it is, it shouldnt do anything. The event should only continue if the state is changed, that way I wouldnt get the notifications every hour.
Maybe I could use another dummy switch that keeps track of my Alarm switches state?
SweetPants

Re: Event that acts depending on last status

Post by SweetPants »

royson wrote: Thursday 25 October 2018 22:09 Im just having some problems getting my logic right as there doesnt seems to be any "last state" command to use.
Take a look at the persistent data part. That can give you state info of a previous script run (https://www.domoticz.com/wiki/DzVents:_ ... stent_data)
royson
Posts: 13
Joined: Friday 10 November 2017 20:56
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Event that acts depending on last status

Post by royson »

SweetPants wrote:
royson wrote: Thursday 25 October 2018 22:09 Im just having some problems getting my logic right as there doesnt seems to be any "last state" command to use.
Take a look at the persistent data part. That can give you state info of a previous script run (https://www.domoticz.com/wiki/DzVents:_ ... stent_data)
Thanks. Im gonna give that a look.

Skickat från min CLT-L29 via Tapatalk

royson
Posts: 13
Joined: Friday 10 November 2017 20:56
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Event that acts depending on last status

Post by royson »

Ok, this is what i've got:

Code: Select all

return {
	on = {
		devices = {
			'vSwitch_till_Larmet'
		}
	},
	execute = function(domoticz, vSwitch_till_Larmet)
	    local Larmet = domoticz.devices('vSwitch_till_Larmet')
	    local HomeAway = domoticz.devices('vLARM_HomeAway')
	    if (Larmet.state == 'On') then
	        HomeAway.switchOff()
	        domoticz.notify('Avlarmat', 'Välkommen hem!', domoticz.PRIORITY_NORMAL)
        elseif (Larmet.state == 'Off') then
            HomeAway.switchOn()
            domoticz.notify('Larmet aktiverat', 'Huset är nu larmat', domoticz.PRIORITY_NORMAL)
        else
            domoticz.notify('Stop', 'Sending me the same shit every hour!!', domoticz.PRIORITY_NORMAL)
		end
	end
}
Last part is mostly frustration...
SweetPants

Re: Event that acts depending on last status

Post by SweetPants »

Do you have re-notification set? Setup->Settings->Notification->Notification Intervals (sensor) i guess 1 hour?
royson
Posts: 13
Joined: Friday 10 November 2017 20:56
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Event that acts depending on last status

Post by royson »

SweetPants wrote: Friday 26 October 2018 18:50 Do you have re-notification set? Setup->Settings->Notification->Notification Intervals (sensor) i guess 1 hour?
I have set that to 12 hours..
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Event that acts depending on last status

Post by waaren »

royson wrote: Saturday 27 October 2018 7:57 ... I would like my event to check if the last state of the switch is the same or not. If it is, it shouldnt do anything. The event should only continue if the state is changed, that way I wouldnt get the notifications every hour....
A possible solution using dzVents persistent data (as suggested by Sweetpants)

Code: Select all

return {
    on      = { devices     = { "vSwitch_till_Larmet" }},

    data    = { lastState   = { initial = "init" }},
    
    execute = function(domoticz, item)                        --  item is vSwitch_till_Larmet (the script trigger)
        local HomeAway = domoticz.devices('vLARM_HomeAway')
        if item.state ~= domoticz.data.lastState then          -- lastState different than current state ?
            domoticz.data.lastState = item.state               -- Store current state in domoticzVents persistent data
            if item.state == 'On' then
                HomeAway.switchOff()
                domoticz.notify('Avlarmat', 'Välkommen hem!', domoticz.PRIORITY_NORMAL)
            else
                HomeAway.switchOn()
                domoticz.notify('Larmet aktiverat', 'Huset är nu larmat', domoticz.PRIORITY_NORMAL)
            end
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
SweetPants

Re: Event that acts depending on last status

Post by SweetPants »

royson wrote: Saturday 27 October 2018 7:57
SweetPants wrote: Friday 26 October 2018 18:50 Do you have re-notification set? Setup->Settings->Notification->Notification Intervals (sensor) i guess 1 hour?
I have set that to 12 hours..
Hmm weird, where is the 1 hour (re)notification coming from then!!!
Waaren already send you a script that uses 'persistent data', maybe you can build from there
royson
Posts: 13
Joined: Friday 10 November 2017 20:56
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Event that acts depending on last status

Post by royson »


SweetPants wrote:
royson wrote: Saturday 27 October 2018 7:57
SweetPants wrote: Friday 26 October 2018 18:50 Do you have re-notification set? Setup->Settings->Notification->Notification Intervals (sensor) i guess 1 hour?
I have set that to 12 hours..
Hmm weird, where is the 1 hour (re)notification coming from then!!!
Waaren already send you a script that uses 'persistent data', maybe you can build from there
Not sure. Maybe Domoticz haven't registered my change to 12h or something.

Yep. Gonna give waaren suggestion a go.

Skickat från min CLT-L29 via Tapatalk

royson
Posts: 13
Joined: Friday 10 November 2017 20:56
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Event that acts depending on last status

Post by royson »

waaren wrote:
royson wrote: Saturday 27 October 2018 7:57 ... I would like my event to check if the last state of the switch is the same or not. If it is, it shouldnt do anything. The event should only continue if the state is changed, that way I wouldnt get the notifications every hour....
A possible solution using dzVents persistent data (as suggested by Sweetpants)

Code: Select all

return {
    on      = { devices     = { "vSwitch_till_Larmet" }},

    data    = { lastState   = { initial = "init" }},
    
    execute = function(domoticz, item)                        --  item is vSwitch_till_Larmet (the script trigger)
        local HomeAway = domoticz.devices('vLARM_HomeAway')
        if item.state ~= domoticz.data.lastState then          -- lastState different than current state ?
            domoticz.data.lastState = item.state               -- Store current state in domoticzVents persistent data
            if item.state == 'On' then
                HomeAway.switchOff()
                domoticz.notify('Avlarmat', 'Välkommen hem!', domoticz.PRIORITY_NORMAL)
            else
                HomeAway.switchOn()
                domoticz.notify('Larmet aktiverat', 'Huset är nu larmat', domoticz.PRIORITY_NORMAL)
            end
        end
    end
}
Thank you. I'm gonna give that a try and read the guide again. With your help I might actually understand how it works :)

Skickat från min CLT-L29 via Tapatalk

royson
Posts: 13
Joined: Friday 10 November 2017 20:56
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Event that acts depending on last status

Post by royson »

waaren wrote: Saturday 27 October 2018 8:35
royson wrote: Saturday 27 October 2018 7:57 ... I would like my event to check if the last state of the switch is the same or not. If it is, it shouldnt do anything. The event should only continue if the state is changed, that way I wouldnt get the notifications every hour....
A possible solution using dzVents persistent data (as suggested by Sweetpants)

Code: Select all

...
Thanks a lot for your help @Sweetpants and @waaren. Its seems to be working great!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest