Event that acts depending on last status

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

Event that acts depending on last status

Post by royson » Monday 22 October 2018 21:10

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
Posts: 2350
Joined: Friday 12 July 2013 21:24
Target OS: Linux
Domoticz version: V4.10196
Location: The Netherlands
Contact:

Re: Event that acts depending on last status

Post by SweetPants » 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.
Ubuntu 16.04.5 LTS, Intel NUC, MySensors 2.3.0-alpha, Pro Mini 3.3/8M RFM69(HW), ESP8266 (SDK2.2.0), Sonoff, RFLink, RFXcom, MQTT, NodeRed, Domoticz Beta (from source)

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

Re: Event that acts depending on last status

Post by royson » Thursday 25 October 2018 22:09

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
Posts: 2350
Joined: Friday 12 July 2013 21:24
Target OS: Linux
Domoticz version: V4.10196
Location: The Netherlands
Contact:

Re: Event that acts depending on last status

Post by SweetPants » Thursday 25 October 2018 22:18

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)
Ubuntu 16.04.5 LTS, Intel NUC, MySensors 2.3.0-alpha, Pro Mini 3.3/8M RFM69(HW), ESP8266 (SDK2.2.0), Sonoff, RFLink, RFXcom, MQTT, NodeRed, Domoticz Beta (from source)

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

Re: Event that acts depending on last status

Post by royson » Thursday 25 October 2018 22:40

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 21:56
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Event that acts depending on last status

Post by royson » Friday 26 October 2018 18:40

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
Posts: 2350
Joined: Friday 12 July 2013 21:24
Target OS: Linux
Domoticz version: V4.10196
Location: The Netherlands
Contact:

Re: Event that acts depending on last status

Post by SweetPants » Friday 26 October 2018 18:50

Do you have re-notification set? Setup->Settings->Notification->Notification Intervals (sensor) i guess 1 hour?
Ubuntu 16.04.5 LTS, Intel NUC, MySensors 2.3.0-alpha, Pro Mini 3.3/8M RFM69(HW), ESP8266 (SDK2.2.0), Sonoff, RFLink, RFXcom, MQTT, NodeRed, Domoticz Beta (from source)

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

Re: Event that acts depending on last status

Post by royson » 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..

User avatar
waaren
Posts: 1219
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Event that acts depending on last status

Post by waaren » 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

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
}
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

SweetPants
Posts: 2350
Joined: Friday 12 July 2013 21:24
Target OS: Linux
Domoticz version: V4.10196
Location: The Netherlands
Contact:

Re: Event that acts depending on last status

Post by SweetPants » Saturday 27 October 2018 10:36

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
Ubuntu 16.04.5 LTS, Intel NUC, MySensors 2.3.0-alpha, Pro Mini 3.3/8M RFM69(HW), ESP8266 (SDK2.2.0), Sonoff, RFLink, RFXcom, MQTT, NodeRed, Domoticz Beta (from source)

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

Re: Event that acts depending on last status

Post by royson » Saturday 27 October 2018 10:37


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 21:56
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Event that acts depending on last status

Post by royson » Saturday 27 October 2018 10:39

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 21:56
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Event that acts depending on last status

Post by royson » Tuesday 30 October 2018 20:30

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